Skip to content

Commit b406190

Browse files
committed
Initial commit
0 parents  commit b406190

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2058
-0
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore all files which are not go type
3+
!**/*.go
4+
!**/*.mod
5+
!**/*.sum

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
testbin/*
10+
11+
# Test binary, build with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Kubernetes Generated files - skip generated files, except for vendored files
18+
19+
!vendor/**/zz_generated.*
20+
21+
# editor and IDE paraphernalia
22+
.idea
23+
*.swp
24+
*.swo
25+
*~

Dockerfile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.15 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:nonroot
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
USER 65532:65532
26+
27+
ENTRYPOINT ["/manager"]

Makefile

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
6+
7+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
8+
ifeq (,$(shell go env GOBIN))
9+
GOBIN=$(shell go env GOPATH)/bin
10+
else
11+
GOBIN=$(shell go env GOBIN)
12+
endif
13+
14+
all: build
15+
16+
##@ General
17+
18+
# The help target prints out all targets with their descriptions organized
19+
# beneath their categories. The categories are represented by '##@' and the
20+
# target descriptions by '##'. The awk commands is responsible for reading the
21+
# entire set of makefiles included in this invocation, looking for lines of the
22+
# file as xyz: ## something, and then pretty-format the target and help. Then,
23+
# if there's a line with ##@ something, that gets pretty-printed as a category.
24+
# More info on the usage of ANSI control characters for terminal formatting:
25+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
26+
# More info on the awk command:
27+
# http://linuxcommand.org/lc3_adv_awk.php
28+
29+
help: ## Display this help.
30+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
31+
32+
##@ Development
33+
34+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
35+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
36+
37+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
38+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
39+
40+
fmt: ## Run go fmt against code.
41+
go fmt ./...
42+
43+
vet: ## Run go vet against code.
44+
go vet ./...
45+
46+
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
47+
test: manifests generate fmt vet ## Run tests.
48+
mkdir -p ${ENVTEST_ASSETS_DIR}
49+
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
50+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
51+
52+
##@ Build
53+
54+
build: generate fmt vet ## Build manager binary.
55+
go build -o bin/manager main.go
56+
57+
run: manifests generate fmt vet ## Run a controller from your host.
58+
go run ./main.go
59+
60+
docker-build: test ## Build docker image with the manager.
61+
docker build -t ${IMG} .
62+
63+
docker-push: ## Push docker image with the manager.
64+
docker push ${IMG}
65+
66+
##@ Deployment
67+
68+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
69+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
70+
71+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
72+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
73+
74+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
75+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
76+
$(KUSTOMIZE) build config/default | kubectl apply -f -
77+
78+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
79+
$(KUSTOMIZE) build config/default | kubectl delete -f -
80+
81+
82+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
83+
controller-gen: ## Download controller-gen locally if necessary.
84+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
85+
86+
KUSTOMIZE = $(shell pwd)/bin/kustomize
87+
kustomize: ## Download kustomize locally if necessary.
88+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
89+
90+
# go-get-tool will 'go get' any package $2 and install it to $1.
91+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
92+
define go-get-tool
93+
@[ -f $(1) ] || { \
94+
set -e ;\
95+
TMP_DIR=$$(mktemp -d) ;\
96+
cd $$TMP_DIR ;\
97+
go mod init tmp ;\
98+
echo "Downloading $(2)" ;\
99+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
100+
rm -rf $$TMP_DIR ;\
101+
}
102+
endef

PROJECT

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
componentConfig: true
2+
domain: opsboost.dev
3+
layout:
4+
- go.kubebuilder.io/v3
5+
projectName: infoscreen-dispatch
6+
repo: github.com/OpsBoost/infoscreen-dispatch-operator
7+
resources:
8+
- api:
9+
crdVersion: v1
10+
namespaced: true
11+
controller: true
12+
domain: opsboost.dev
13+
group: client
14+
kind: Client
15+
path: github.com/OpsBoost/infoscreen-dispatch-operator/api/v1
16+
version: v1
17+
- api:
18+
crdVersion: v1
19+
namespaced: true
20+
controller: true
21+
domain: opsboost.dev
22+
group: client
23+
kind: Enrolment
24+
path: github.com/OpsBoost/infoscreen-dispatch-operator/api/v1
25+
version: v1
26+
version: "3"

api/v1/client_types.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2021 OpsBoost Crew <[email protected]>.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// ClientSpec defines the desired state of Client
27+
type ClientSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of Client. Edit client_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// ClientStatus defines the observed state of Client
36+
type ClientStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// Client is the Schema for the clients API
45+
type Client struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec ClientSpec `json:"spec,omitempty"`
50+
Status ClientStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// ClientList contains a list of Client
56+
type ClientList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []Client `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&Client{}, &ClientList{})
64+
}

api/v1/enrolment_types.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright 2021 OpsBoost Crew <[email protected]>.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// EnrolmentSpec defines the desired state of Enrolment
27+
type EnrolmentSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of Enrolment. Edit enrolment_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// EnrolmentStatus defines the observed state of Enrolment
36+
type EnrolmentStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// Enrolment is the Schema for the enrolments API
45+
type Enrolment struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec EnrolmentSpec `json:"spec,omitempty"`
50+
Status EnrolmentStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// EnrolmentList contains a list of Enrolment
56+
type EnrolmentList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []Enrolment `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&Enrolment{}, &EnrolmentList{})
64+
}

api/v1/groupversion_info.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2021 OpsBoost Crew <[email protected]>.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1 contains API Schema definitions for the client v1 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=client.opsboost.dev
20+
package v1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "client.opsboost.dev", Version: "v1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

0 commit comments

Comments
 (0)