Skip to content

Commit a9f7c28

Browse files
committed
Initial release
1 parent fe0f30a commit a9f7c28

33 files changed

+2225
-1
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sandbox-operator

Dockerfile

Lines changed: 28 additions & 0 deletions
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

Lines changed: 35 additions & 0 deletions
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

Lines changed: 14 additions & 1 deletion
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`)
Lines changed: 10 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

0 commit comments

Comments
 (0)