Skip to content

Commit 474eafa

Browse files
authored
Merge pull request #1351 from secureCodeBox/update/update-kubebuilder-version
Upgrade Operator & AutoDiscovery to latest kubebuilder 3.6.0 dependencies
2 parents 166b61b + 8e8710d commit 474eafa

29 files changed

Lines changed: 898 additions & 574 deletions

‎.github/workflows/ci.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ on:
1717
env:
1818
# ---- Language Versions ----
1919

20-
GO_VERSION: "1.17"
20+
GO_VERSION: "1.19"
2121
PYTHON_VERSION: "3.8.10"
2222
NODE_VERSION: "16"
2323
NPM_VERSION: "7"

‎auto-discovery/kubernetes/Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44

55
# Build the manager binary
6-
FROM golang:1.17 as builder
6+
FROM golang:1.19 as builder
77

88
WORKDIR /workspace
99
# Copy the Go Modules manifests

‎auto-discovery/kubernetes/Makefile‎

Lines changed: 64 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ IMG ?= auto-discovery-kubernetes
1010
# Tag used for the image
1111
IMG_TAG ?= sha-$$(git rev-parse --short HEAD)
1212

13-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
14-
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
15-
1613
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
1714
ifeq (,$(shell go env GOBIN))
1815
GOBIN=$(shell go env GOPATH)/bin
@@ -26,6 +23,7 @@ endif
2623
SHELL = /usr/bin/env bash -o pipefail
2724
.SHELLFLAGS = -ec
2825

26+
.PHONY: all
2927
all: build
3028

3129
##@ General
@@ -41,96 +39,131 @@ all: build
4139
# More info on the awk command:
4240
# http://linuxcommand.org/lc3_adv_awk.php
4341

42+
.PHONY: help
4443
help: ## Display this help.
4544
@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)
4645

4746
##@ Development
4847

48+
.PHONY: manifests
4949
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
50-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
50+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
5151

52+
.PHONY: generate
5253
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
5354
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
5455

56+
.PHONY: fmt
5557
fmt: ## Run go fmt against code.
5658
go fmt ./...
5759

60+
.PHONY: vet
5861
vet: ## Run go vet against code.
5962
go vet ./...
6063

6164
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
6265

66+
.PHONY: test-setup
6367
test-setup: manifests generate fmt vet ## Run tests.
6468
mkdir -p ${ENVTEST_ASSETS_DIR}
6569
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
66-
6770

71+
.PHONY: test
6872
test: test-setup
6973
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
74+
75+
.PHONY: ginko
7076
ginkgo:
7177
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); ginkgo test ./... -coverprofile cover.out -v --progress
7278

7379
##@ Build
7480

81+
.PHONY: build
7582
build: generate fmt vet ## Build manager binary.
7683
go build -o bin/manager main.go
7784

85+
.PHONY: run
7886
run: manifests generate fmt vet ## Run a controller from your host.
7987
go run ./main.go --config auto-discovery-config.yaml
8088

89+
.PHONY: docker-build
8190
docker-build: test ## Build docker image with the manager.
8291
@echo ".: ⚙️ Build Container Images"
8392
docker build -t ${IMG_NS}/${IMG}:${IMG_TAG} .
8493

94+
.PHONY: docker-push
8595
docker-push: ## Push docker image with the manager.
8696
docker push ${IMG_NS}/${IMG}:${IMG_TAG}
8797

98+
.PHONY: docker-export
8899
docker-export:
89100
@echo ".: 💾 Export Container Images"
90101
docker save $(IMG_NS)/$(IMG):$(IMG_TAG) > $(IMG).tar
91102

92103
##@ Deployment
93104

105+
.PHONY: kind-import
94106
kind-import:
95107
@echo ".: 💾 Importing the image archive to local kind cluster."
96108
kind load image-archive ./$(IMG).tar
97109

110+
.PHONY: helm-deploy
98111
helm-deploy:
99112
@echo ".: ⚙️ Deploying auto-discovery with the Image tag '$(IMG_TAG)' into kind."
100113
helm upgrade --install auto-discovery ./ --wait \
101-
--set="image.repository=docker.io/$(IMG_NS)/$(IMG)" \
102-
--set="image.tag=$(IMG_TAG)" \
114+
--set="image.repository=docker.io/$(IMG_NS)/$(IMG)" \
115+
--set="image.tag=$(IMG_TAG)" \
103116
--set="image.pullPolicy=IfNotPresent" \
104117

118+
ifndef ignore-not-found
119+
ignore-not-found = false
120+
endif
121+
122+
.PHONY: install
105123
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
106124
$(KUSTOMIZE) build config/crd | kubectl apply -f -
107125

108-
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
109-
$(KUSTOMIZE) build config/crd | kubectl delete -f -
126+
.PHONY: uninstall
127+
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.
128+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
110129

130+
.PHONY: deploy
111131
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
112132
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
113133
$(KUSTOMIZE) build config/default | kubectl apply -f -
114134

115-
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
116-
$(KUSTOMIZE) build config/default | kubectl delete -f -
117-
118-
119-
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
120-
controller-gen: ## Download controller-gen locally if necessary.
121-
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
122-
123-
KUSTOMIZE = $(shell pwd)/bin/kustomize
124-
kustomize: ## Download kustomize locally if necessary.
125-
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)
126-
127-
# go-install-tool will 'go install' any package $2 and install it to $1.
128-
# GOBIN needs to be an absolute path so an additional absolute path project dir variable is used
129-
ABS_PROJECT_DIR=$(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
130-
define go-install-tool
131-
@[ -f $(1) ] || { \
132-
set -e ;\
133-
echo "Downloading $(2)" ;\
134-
GOBIN=$(ABS_PROJECT_DIR)/bin go install $(2) ;\
135-
}
136-
endef
135+
.PHONY: undeploy
136+
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.
137+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
138+
139+
##@ Build Dependencies
140+
141+
## Location to install dependencies to
142+
LOCALBIN ?= $(shell pwd)/bin
143+
$(LOCALBIN):
144+
mkdir -p $(LOCALBIN)
145+
146+
## Tool Binaries
147+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
148+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
149+
ENVTEST ?= $(LOCALBIN)/setup-envtest
150+
151+
## Tool Versions
152+
KUSTOMIZE_VERSION ?= v3.8.7
153+
CONTROLLER_TOOLS_VERSION ?= v0.9.2
154+
155+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
156+
.PHONY: kustomize
157+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
158+
$(KUSTOMIZE): $(LOCALBIN)
159+
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
160+
161+
.PHONY: controller-gen
162+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
163+
$(CONTROLLER_GEN): $(LOCALBIN)
164+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
165+
166+
.PHONY: envtest
167+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
168+
$(ENVTEST): $(LOCALBIN)
169+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

‎auto-discovery/kubernetes/api/v1/autodiscoveryconfig_types.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
cfg "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
1111
)
1212

13-
//+kubebuilder:object:root=true
13+
// +kubebuilder:object:root=true
1414
type AutoDiscoveryConfig struct {
1515
metav1.TypeMeta `json:",inline"`
1616

‎auto-discovery/kubernetes/api/v1/groupversion_info.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0
44

55
// Package v1 contains API Schema definitions for the config v1 API group
6-
//+kubebuilder:object:generate=true
7-
//+groupName=config.securecodebox.io
6+
// +kubebuilder:object:generate=true
7+
// +groupName=config.securecodebox.io
88
package v1
99

1010
import (

‎auto-discovery/kubernetes/controllers/service_scan_controller.go‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,20 @@ func getShaHashesForPod(pod corev1.Pod) map[string]string {
337337

338338
// Takes a list of pods and returns a two tiered map to lookup pod digests per container
339339
// The map returned look like this:
340-
// {
341-
// // container name
342-
// container1: {
343-
// // digest
344-
// ab2dkbsjdha3kshdasjdbalsjdbaljsbd: true
345-
// iuzaksbd2kabsdk4abksdbaksjbdak12a: true
346-
// },
347-
// container2: {
348-
// // digest
349-
// sjdha3kshdasjdbalsjdbaljsbdab2dkb: true
350-
// d2kabsdk4abksdbaksjbdak12aiuzaksb: true
351-
// },
352-
// }
340+
//
341+
// {
342+
// // container name
343+
// container1: {
344+
// // digest
345+
// ab2dkbsjdha3kshdasjdbalsjdbaljsbd: true
346+
// iuzaksbd2kabsdk4abksdbaksjbdak12a: true
347+
// },
348+
// container2: {
349+
// // digest
350+
// sjdha3kshdasjdbalsjdbaljsbdab2dkb: true
351+
// d2kabsdk4abksdbaksjbdak12aiuzaksb: true
352+
// },
353+
// }
353354
func gatherPodDigests(pods *corev1.PodList) map[string]map[string]bool {
354355
podDigests := map[string]map[string]bool{}
355356

‎auto-discovery/kubernetes/go.mod‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
module github.com/secureCodeBox/secureCodeBox/auto-discovery/kubernetes
66

7-
go 1.17
7+
go 1.19
88

99
require (
1010
github.com/Masterminds/sprig v2.22.0+incompatible
1111
github.com/go-logr/logr v1.2.3
1212
github.com/onsi/ginkgo v1.16.5
1313
github.com/onsi/gomega v1.19.0
1414
github.com/secureCodeBox/secureCodeBox/operator v0.0.0-20220516151324-e6d879a9eb4f
15-
k8s.io/api v0.24.0
16-
k8s.io/apimachinery v0.24.0
17-
k8s.io/client-go v0.24.0
18-
sigs.k8s.io/controller-runtime v0.11.0
15+
k8s.io/api v0.24.2
16+
k8s.io/apimachinery v0.24.2
17+
k8s.io/client-go v0.24.2
18+
sigs.k8s.io/controller-runtime v0.12.2
1919
)
2020

2121
require (
@@ -83,8 +83,8 @@ require (
8383
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
8484
gopkg.in/yaml.v2 v2.4.0 // indirect
8585
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
86-
k8s.io/apiextensions-apiserver v0.24.0 // indirect
87-
k8s.io/component-base v0.24.0 // indirect
86+
k8s.io/apiextensions-apiserver v0.24.2 // indirect
87+
k8s.io/component-base v0.24.2 // indirect
8888
k8s.io/klog/v2 v2.60.1 // indirect
8989
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
9090
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect

0 commit comments

Comments
 (0)