Skip to content

Commit a9f7c28

Browse files
committed
Initial release
1 parent fe0f30a commit a9f7c28

33 files changed

+2225
-1
lines changed

.editorconfig

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
root = true
2+
3+
[*.{yml,yaml}]
4+
indent_style = space
5+
indent_size = 2
6+
trim_trailing_whitespace = true

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
* text=auto
2+
go.mod text eol=lf
3+
4+
# operator build tools require LF normalization
5+
/scripts/entrypoint text eol=lf
6+
/scripts/user_setup text eol=lf

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sandbox-operator

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM golang:1.13-alpine AS builder
2+
WORKDIR /operator
3+
4+
COPY go.mod .
5+
COPY go.sum .
6+
RUN go mod download
7+
8+
COPY . .
9+
10+
RUN GOOS=linux GOARCH=amd64 go build -o sandbox-operator main.go
11+
12+
FROM alpine:3.11.2
13+
ENV OPERATOR=/usr/local/bin/sandbox-operator \
14+
USER_UID=1001 \
15+
USER_NAME=sandbox-operator
16+
17+
COPY --from=builder /operator/sandbox-operator ${OPERATOR}
18+
COPY scripts/ /usr/local/bin
19+
20+
RUN chmod +x /usr/local/bin/user_setup
21+
RUN chmod +x /usr/local/bin/entrypoint
22+
RUN chmod +x /usr/local/bin/sandbox-operator
23+
24+
RUN /usr/local/bin/user_setup
25+
26+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
27+
28+
USER ${USER_UID}

Makefile

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
KUBERNETES_VERSION=v1.14.10
2+
CLUSTER_NAME=operator-testing-$(KUBERNETES_VERSION)
3+
OPERATOR_IMAGE=sandbox-operator:dev
4+
5+
.PHONY: image
6+
image:
7+
docker build . -t $(OPERATOR_IMAGE)
8+
9+
.PHONY: cluster
10+
cluster:
11+
kind create cluster --name $(CLUSTER_NAME) --image kindest/node:$(KUBERNETES_VERSION)
12+
kubectl wait --for=condition=Ready --timeout=60s node --all
13+
14+
.PHONY: deploy
15+
deploy: image
16+
kind load docker-image $(OPERATOR_IMAGE) --name $(CLUSTER_NAME)
17+
kubectl delete pod --all
18+
kustomize build example | kubectl apply -f -
19+
kubectl wait --for=condition=Ready --timeout=60s pods --all
20+
21+
.PHONY: lint
22+
lint:
23+
kustomize build example | kubeval --ignore-missing-schemas -
24+
25+
.PHONY: test-unit
26+
test-unit:
27+
go test ./controller -v -count=1
28+
29+
.PHONY: test-integration
30+
test-integration: cluster deploy
31+
go test ./controller -v --tags=integration -count=1
32+
33+
.PHONY: destroy
34+
destroy:
35+
kind delete cluster --name $(CLUSTER_NAME)

README.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
# sandbox-operator
2-
A kubernetes operator for creating isolated environments
2+
3+
## Introduction
4+
5+
This is a sandbox operator that creates segregated namespaces and sets up RBAC for authenticated users specified in the CRD.
6+
7+
## Local Testing
8+
9+
Run `make test-unit` to run the operator unit tests
10+
11+
Run `make test-integration` to deploy the operator to a Kind cluster and verify the operator pod enters a running state.
12+
13+
Iterative deployments can be made with `make deploy`. This will rebuild the operator and deploy to it to an existing cluster.
14+
15+
To test with a different version of Kubernetes, pass in `KUBERNETES_VERSION` to the `make` command (e.g. `make test-integration KUBERNETES_VERSION=v1.17.0`)
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package apis
2+
3+
import (
4+
"github.com/plexsystems/sandbox-operator/apis/operators/v1alpha1"
5+
)
6+
7+
func init() {
8+
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
9+
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
10+
}

apis/apis.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package apis
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime"
5+
)
6+
7+
// AddToSchemes may be used to add all resources defined in the project to a Scheme
8+
var AddToSchemes runtime.SchemeBuilder
9+
10+
// AddToScheme adds all Resources to the Scheme
11+
func AddToScheme(s *runtime.Scheme) error {
12+
return AddToSchemes.AddToScheme(s)
13+
}

apis/operators/group.go

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package operators contains operators.plex.dev API versions
2+
package operators

apis/operators/v1alpha1/doc.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Package v1alpha1 contains API Schema definitions for the operators.plex.dev API group
2+
// +k8s:deepcopy-gen=package,register
3+
// +groupName=operators.plex.dev
4+
package v1alpha1

apis/operators/v1alpha1/register.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// NOTE: Boilerplate only. Ignore this file.
2+
3+
// Package v1alpha1 contains API Schema definitions for the operators.plex.dev API group
4+
// +k8s:deepcopy-gen=package,register
5+
// +groupName=operators.plex.dev
6+
package v1alpha1
7+
8+
import (
9+
"k8s.io/apimachinery/pkg/runtime/schema"
10+
"sigs.k8s.io/controller-runtime/pkg/runtime/scheme"
11+
)
12+
13+
var (
14+
// SchemeGroupVersion is group version used to register these objects
15+
SchemeGroupVersion = schema.GroupVersion{Group: "operators.plex.dev", Version: "v1alpha1"}
16+
17+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
18+
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
19+
)
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// SandboxSpec defines the desired state of Sandbox
8+
// +k8s:openapi-gen=true
9+
type SandboxSpec struct {
10+
Owners []string `json:"owners"`
11+
}
12+
13+
// SandboxStatus defines the observed state of Sandbox
14+
// +k8s:openapi-gen=true
15+
type SandboxStatus struct{}
16+
17+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
18+
19+
// Sandbox is the Schema for the sandboxes API
20+
// +k8s:openapi-gen=true
21+
// +kubebuilder:subresource:status
22+
type Sandbox struct {
23+
metav1.TypeMeta `json:",inline"`
24+
metav1.ObjectMeta `json:"metadata,omitempty"`
25+
26+
Spec SandboxSpec `json:"spec,omitempty"`
27+
Status SandboxStatus `json:"status,omitempty"`
28+
}
29+
30+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
31+
32+
// SandboxList contains a list of Sandbox
33+
type SandboxList struct {
34+
metav1.TypeMeta `json:",inline"`
35+
metav1.ListMeta `json:"metadata,omitempty"`
36+
Items []Sandbox `json:"items"`
37+
}
38+
39+
func init() {
40+
SchemeBuilder.Register(&Sandbox{}, &SandboxList{})
41+
}

apis/operators/v1alpha1/zz_generated.deepcopy.go

+107
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// +build !ignore_autogenerated
2+
3+
// This file was autogenerated by openapi-gen. Do not edit it manually!
4+
5+
package v1alpha1
6+
7+
import (
8+
spec "github.com/go-openapi/spec"
9+
common "k8s.io/kube-openapi/pkg/common"
10+
)
11+
12+
func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenAPIDefinition {
13+
return map[string]common.OpenAPIDefinition{
14+
"./pkg/apis/operators/v1alpha1.Sandbox": schema_pkg_apis_operators_v1alpha1_Sandbox(ref),
15+
"./pkg/apis/operators/v1alpha1.SandboxSpec": schema_pkg_apis_operators_v1alpha1_SandboxSpec(ref),
16+
"./pkg/apis/operators/v1alpha1.SandboxStatus": schema_pkg_apis_operators_v1alpha1_SandboxStatus(ref),
17+
}
18+
}
19+
20+
func schema_pkg_apis_operators_v1alpha1_Sandbox(ref common.ReferenceCallback) common.OpenAPIDefinition {
21+
return common.OpenAPIDefinition{
22+
Schema: spec.Schema{
23+
SchemaProps: spec.SchemaProps{
24+
Description: "Sandbox is the Schema for the sandboxes API",
25+
Properties: map[string]spec.Schema{
26+
"kind": {
27+
SchemaProps: spec.SchemaProps{
28+
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds",
29+
Type: []string{"string"},
30+
Format: "",
31+
},
32+
},
33+
"apiVersion": {
34+
SchemaProps: spec.SchemaProps{
35+
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources",
36+
Type: []string{"string"},
37+
Format: "",
38+
},
39+
},
40+
"metadata": {
41+
SchemaProps: spec.SchemaProps{
42+
Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"),
43+
},
44+
},
45+
"spec": {
46+
SchemaProps: spec.SchemaProps{
47+
Ref: ref("./pkg/apis/operators/v1alpha1.SandboxSpec"),
48+
},
49+
},
50+
"status": {
51+
SchemaProps: spec.SchemaProps{
52+
Ref: ref("./pkg/apis/operators/v1alpha1.SandboxStatus"),
53+
},
54+
},
55+
},
56+
},
57+
},
58+
Dependencies: []string{
59+
"./pkg/apis/operators/v1alpha1.SandboxSpec", "./pkg/apis/operators/v1alpha1.SandboxStatus", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"},
60+
}
61+
}
62+
63+
func schema_pkg_apis_operators_v1alpha1_SandboxSpec(ref common.ReferenceCallback) common.OpenAPIDefinition {
64+
return common.OpenAPIDefinition{
65+
Schema: spec.Schema{
66+
SchemaProps: spec.SchemaProps{
67+
Description: "SandboxSpec defines the desired state of Sandbox",
68+
Properties: map[string]spec.Schema{},
69+
},
70+
},
71+
Dependencies: []string{},
72+
}
73+
}
74+
75+
func schema_pkg_apis_operators_v1alpha1_SandboxStatus(ref common.ReferenceCallback) common.OpenAPIDefinition {
76+
return common.OpenAPIDefinition{
77+
Schema: spec.Schema{
78+
SchemaProps: spec.SchemaProps{
79+
Description: "SandboxStatus defines the observed state of Sandbox",
80+
Properties: map[string]spec.Schema{},
81+
},
82+
},
83+
Dependencies: []string{},
84+
}
85+
}

0 commit comments

Comments
 (0)