-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade according to https://sdk.operatorframework.io/docs/building-operators/golang/project_migration_guide/ Outstanding issues that were solved Effectively it is completely new project structure and engine, the logic was cherry-picked and migrated step by step in multiple places DepResolver introduced some dependency hell, we included env.go from kuberentes utils right in the codebase Invalid memory nil pointer access was solved by adopting of depresolver to new style of GslbReconciler initialization Adapt to new reconciliation related method signatures Adapt to new logging style Upstream/k8gb Makefile merge Unit test fixes - controller runtime fake client changed its behaviour in treating object versions Terratest fixes Github actions changes Resolves #166 All tests are passing.
- Loading branch information
Showing
89 changed files
with
2,239 additions
and
1,430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Build the manager binary | ||
FROM golang:1.13 as builder | ||
|
||
WORKDIR /workspace | ||
# Copy the Go Modules manifests | ||
COPY go.mod go.mod | ||
COPY go.sum go.sum | ||
# cache deps before building and copying source so that we don't need to re-download as much | ||
# and so that source changes don't invalidate our downloaded layer | ||
RUN go mod download | ||
|
||
# Copy the go source | ||
COPY main.go main.go | ||
COPY api/ api/ | ||
COPY controllers/ controllers/ | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go | ||
|
||
# Use distroless as minimal base image to package the manager binary | ||
# Refer to https://github.com/GoogleContainerTools/distroless for more details | ||
FROM gcr.io/distroless/static:nonroot | ||
WORKDIR / | ||
COPY --from=builder /workspace/manager . | ||
USER nonroot:nonroot | ||
|
||
ENTRYPOINT ["/manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,128 @@ | ||
REPO ?= absaoss/k8gb | ||
# Current Operator version | ||
VERSION ?= $$(helm show chart chart/k8gb/|awk '/appVersion:/ {print $$2}') | ||
K8GB_IMAGE_TAG ?= v$(VERSION) | ||
# Default bundle image tag | ||
BUNDLE_IMG ?= controller-bundle:$(VERSION) | ||
# Options for 'bundle-build' | ||
ifneq ($(origin CHANNELS), undefined) | ||
BUNDLE_CHANNELS := --channels=$(CHANNELS) | ||
endif | ||
ifneq ($(origin DEFAULT_CHANNEL), undefined) | ||
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | ||
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= $(REPO):$(K8GB_IMAGE_TAG) | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
all: manager | ||
|
||
# Run tests | ||
test: generate fmt vet manifests | ||
go test ./... -coverprofile cover.out | ||
|
||
# Build manager binary | ||
manager: generate fmt vet | ||
go build -o bin/manager main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: generate fmt vet manifests | ||
go run ./main.go | ||
|
||
# Install CRDs into a cluster | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Run go fmt against code | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
vet: | ||
go vet ./... | ||
|
||
# Generate code | ||
generate: controller-gen | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
# Build the docker image | ||
docker-build: test | ||
docker build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
controller-gen: | ||
ifeq (, $(shell which controller-gen)) | ||
@{ \ | ||
set -e ;\ | ||
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$CONTROLLER_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\ | ||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
} | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif | ||
|
||
kustomize: | ||
ifeq (, $(shell which kustomize)) | ||
@{ \ | ||
set -e ;\ | ||
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\ | ||
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
} | ||
KUSTOMIZE=$(GOBIN)/kustomize | ||
else | ||
KUSTOMIZE=$(shell which kustomize) | ||
endif | ||
|
||
# Generate bundle manifests and metadata, then validate generated files. | ||
.PHONY: bundle | ||
bundle: manifests | ||
operator-sdk generate kustomize manifests -q | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
operator-sdk bundle validate ./bundle | ||
|
||
# Build the bundle image. | ||
.PHONY: bundle-build | ||
bundle-build: | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . | ||
|
||
## Special k8gb make part | ||
|
||
VALUES_YAML ?= chart/k8gb/values.yaml | ||
HELM_ARGS ?= | ||
ETCD_DEBUG_IMAGE ?= quay.io/coreos/etcd:v3.2.25 | ||
|
@@ -11,12 +134,6 @@ K8GB_IMAGE_TAG ?= v$(VERSION) | |
K8GB_COREDNS_IP ?= kubectl get svc k8gb-coredns -n k8gb -o custom-columns='IP:spec.clusterIP' --no-headers | ||
PODINFO_IMAGE_REPO ?= stefanprodan/podinfo | ||
|
||
.PHONY: up-local | ||
up-local: create-test-ns | ||
kubectl apply -f ./deploy/crds/k8gb.absa.oss_gslbs_crd.yaml | ||
kubectl apply -f ./deploy/crds/k8gb.absa.oss_v1beta1_gslb_cr.yaml | ||
operator-sdk run --local --namespace=test-gslb | ||
|
||
.PHONY: debug-local | ||
debug-local: create-test-ns | ||
kubectl apply -f ./deploy/crds/k8gb.absa.oss_gslbs_crd.yaml | ||
|
@@ -25,22 +142,14 @@ debug-local: create-test-ns | |
|
||
.PHONY: lint | ||
lint: | ||
staticcheck ./pkg/... ./cmd/... | ||
errcheck ./pkg/... ./cmd/... | ||
golint '-set_exit_status=1' pkg/controller/... cmd/manager/... | ||
|
||
.PHONY: test | ||
test: | ||
go test -v ./... | ||
staticcheck ./... | ||
errcheck ./... | ||
golint '-set_exit_status=1' ./... | ||
|
||
.PHONY: terratest | ||
terratest: | ||
cd terratest/test/ && go mod download && go test -v | ||
|
||
.PHONY: e2e-test | ||
e2e-test: deploy-gslb-operator | ||
operator-sdk test local ./pkg/test --no-setup --namespace k8gb | ||
|
||
.PHONY: dns-tools | ||
dns-tools: | ||
kubectl -n k8gb get svc k8gb-coredns | ||
|
@@ -101,7 +210,7 @@ create-test-ns: | |
|
||
.PHONY: deploy-local-ingress | ||
deploy-local-ingress: create-k8gb-ns | ||
helm repo add stable https://kubernetes-charts.storage.googleapis.com | ||
helm repo add --force-update stable https://kubernetes-charts.storage.googleapis.com | ||
helm repo update | ||
helm -n k8gb upgrade -i nginx-ingress stable/nginx-ingress --version 1.41.1 -f deploy/ingress/nginx-ingress-values.yaml | ||
|
||
|
@@ -141,14 +250,6 @@ clean-test-apps: | |
helm -n test-gslb uninstall backend | ||
helm -n test-gslb uninstall frontend | ||
|
||
.PHONY: build | ||
build: | ||
operator-sdk build $(K8GB_IMAGE_REPO):$(K8GB_IMAGE_TAG) | ||
|
||
.PHONY: push | ||
push: | ||
docker push $(K8GB_IMAGE_REPO):$(K8GB_IMAGE_TAG) | ||
|
||
.PHONY: debug-test-etcd | ||
debug-test-etcd: | ||
kubectl run --rm -i --tty --env="ETCDCTL_API=3" --env="ETCDCTL_ENDPOINTS=http://etcd-cluster-client:2379" --namespace k8gb etcd-test --image "$(ETCD_DEBUG_IMAGE)" --restart=Never -- /bin/sh | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
domain: absa.oss | ||
layout: go.kubebuilder.io/v2 | ||
projectName: k8gb | ||
repo: github.com/AbsaOSS/k8gb | ||
resources: | ||
- group: k8gb | ||
kind: Gslb | ||
version: v1beta1 | ||
version: 3-alpha | ||
plugins: | ||
go.sdk.operatorframework.io/v2-alpha: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1beta1 contains API Schema definitions for the k8gb v1beta1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=k8gb.absa.oss | ||
package v1beta1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "k8gb.absa.oss", Version: "v1beta1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.