Skip to content

Commit 6886bc4

Browse files
committed
Initial commit
0 parents  commit 6886bc4

42 files changed

Lines changed: 2536 additions & 0 deletions

Some content is hidden

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

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.gitignore

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.16 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 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

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
# Image URL to use all building/pushing image targets
3+
IMG ?= controller:latest
4+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
5+
ENVTEST_K8S_VERSION = 1.22
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+
# Setting SHELL to bash allows bash commands to be executed by recipes.
15+
# This is a requirement for 'setup-envtest.sh' in the test target.
16+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
17+
SHELL = /usr/bin/env bash -o pipefail
18+
.SHELLFLAGS = -ec
19+
20+
.PHONY: all
21+
all: build
22+
23+
##@ General
24+
25+
# The help target prints out all targets with their descriptions organized
26+
# beneath their categories. The categories are represented by '##@' and the
27+
# target descriptions by '##'. The awk commands is responsible for reading the
28+
# entire set of makefiles included in this invocation, looking for lines of the
29+
# file as xyz: ## something, and then pretty-format the target and help. Then,
30+
# if there's a line with ##@ something, that gets pretty-printed as a category.
31+
# More info on the usage of ANSI control characters for terminal formatting:
32+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
33+
# More info on the awk command:
34+
# http://linuxcommand.org/lc3_adv_awk.php
35+
36+
.PHONY: help
37+
help: ## Display this help.
38+
@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)
39+
40+
##@ Development
41+
42+
.PHONY: manifests
43+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
44+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
45+
46+
.PHONY: generate
47+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
48+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
49+
50+
.PHONY: fmt
51+
fmt: ## Run go fmt against code.
52+
go fmt ./...
53+
54+
.PHONY: vet
55+
vet: ## Run go vet against code.
56+
go vet ./...
57+
58+
.PHONY: test
59+
test: manifests generate fmt vet envtest ## Run tests.
60+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
61+
62+
##@ Build
63+
64+
.PHONY: build
65+
build: generate fmt vet ## Build manager binary.
66+
go build -o bin/manager main.go
67+
68+
.PHONY: run
69+
run: manifests generate fmt vet ## Run a controller from your host.
70+
go run ./main.go
71+
72+
.PHONY: docker-build
73+
docker-build: test ## Build docker image with the manager.
74+
docker build -t ${IMG} .
75+
76+
.PHONY: docker-push
77+
docker-push: ## Push docker image with the manager.
78+
docker push ${IMG}
79+
80+
##@ Deployment
81+
82+
ifndef ignore-not-found
83+
ignore-not-found = false
84+
endif
85+
86+
.PHONY: install
87+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
88+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
89+
90+
.PHONY: uninstall
91+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
92+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
93+
94+
.PHONY: deploy
95+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
96+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
97+
$(KUSTOMIZE) build config/default | kubectl apply -f -
98+
99+
.PHONY: undeploy
100+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
101+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
102+
103+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
104+
.PHONY: controller-gen
105+
controller-gen: ## Download controller-gen locally if necessary.
106+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0)
107+
108+
KUSTOMIZE = $(shell pwd)/bin/kustomize
109+
.PHONY: kustomize
110+
kustomize: ## Download kustomize locally if necessary.
111+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
112+
113+
ENVTEST = $(shell pwd)/bin/setup-envtest
114+
.PHONY: envtest
115+
envtest: ## Download envtest-setup locally if necessary.
116+
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
117+
118+
# go-get-tool will 'go get' any package $2 and install it to $1.
119+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
120+
define go-get-tool
121+
@[ -f $(1) ] || { \
122+
set -e ;\
123+
TMP_DIR=$$(mktemp -d) ;\
124+
cd $$TMP_DIR ;\
125+
go mod init tmp ;\
126+
echo "Downloading $(2)" ;\
127+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
128+
rm -rf $$TMP_DIR ;\
129+
}
130+
endef

PROJECT

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
domain: elx.cloud
2+
layout:
3+
- go.kubebuilder.io/v3
4+
projectName: elx-nodegroup-controller
5+
repo: github.com/elastx/elx-nodegroup-controller
6+
resources:
7+
- api:
8+
crdVersion: v1
9+
controller: true
10+
domain: elx.cloud
11+
group: k8s
12+
kind: NodeGroup
13+
path: github.com/elastx/elx-nodegroup-controller/api/v1alpha1
14+
version: v1alpha1
15+
version: "3"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# elx-nodegroup-controller
2+
3+
A tiny controller for persisting labels and taints on a list of nodes.
4+
5+
## NodeGroup
6+
7+
The NodeGroup schema can be found in `api/v1alpha/nogroup_types.go`.

api/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2022.
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 v1alpha1 contains API Schema definitions for the k8s v1alpha1 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=k8s.elx.cloud
20+
package v1alpha1
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: "k8s.elx.cloud", Version: "v1alpha1"}
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+
)

api/v1alpha1/nodegroup_types.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2022.
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 v1alpha1
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
type NodeGroupSpec struct {
25+
Members []string `json:"members,omitempty"`
26+
//+optional
27+
Labels map[string]string `json:"labels,omitEmpty"`
28+
//+optional
29+
Taints []corev1.Taint `json:"taints,omitEmpty"`
30+
}
31+
32+
type NodeGroupStatus struct {
33+
}
34+
35+
//+kubebuilder:object:root=true
36+
//+kubebuilder:subresource:status
37+
//+kubebuilder:resource:scope=Cluster
38+
39+
// NodeGroup is the Schema for the nodegroups API
40+
type NodeGroup struct {
41+
metav1.TypeMeta `json:",inline"`
42+
metav1.ObjectMeta `json:"metadata,omitempty"`
43+
44+
Spec NodeGroupSpec `json:"spec,omitempty"`
45+
Status NodeGroupStatus `json:"status,omitempty"`
46+
}
47+
48+
//+kubebuilder:object:root=true
49+
50+
// NodeGroupList contains a list of NodeGroup
51+
type NodeGroupList struct {
52+
metav1.TypeMeta `json:",inline"`
53+
metav1.ListMeta `json:"metadata,omitempty"`
54+
Items []NodeGroup `json:"items"`
55+
}
56+
57+
func init() {
58+
SchemeBuilder.Register(&NodeGroup{}, &NodeGroupList{})
59+
}

0 commit comments

Comments
 (0)