Skip to content

Commit 57ba40c

Browse files
Merge pull request #272 from trevorbox/feature/fix-pull252
Feature/fix 196
2 parents 8e63ae1 + d526291 commit 57ba40c

File tree

60 files changed

+3660
-3002
lines changed

Some content is hidden

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

60 files changed

+3660
-3002
lines changed

.github/workflows/pr.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ jobs:
1313
RUN_UNIT_TESTS: true
1414
RUN_INTEGRATION_TESTS: true
1515
RUN_HELMCHART_TEST: true
16-
GO_VERSION: ~1.21
17-
OPERATOR_SDK_VERSION: v1.25.3
16+
GO_VERSION: ~1.22
17+
OPERATOR_SDK_VERSION: v1.31.0

.github/workflows/push.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ jobs:
2020
RUN_UNIT_TESTS: true
2121
RUN_INTEGRATION_TESTS: true
2222
RUN_HELMCHART_TEST: true
23-
GO_VERSION: ~1.21
24-
OPERATOR_SDK_VERSION: v1.25.3
23+
GO_VERSION: ~1.22
24+
OPERATOR_SDK_VERSION: v1.31.0

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.21 as builder
2+
FROM golang:1.22 AS builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

Makefile

+71-16
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@ CHART_REPO_URL ?= http://example.com
22
HELM_REPO_DEST ?= /tmp/gh-pages
33
OPERATOR_NAME ?=$(shell basename -z `pwd`)
44
HELM_VERSION ?= v3.11.0
5-
KIND_VERSION ?= v0.20.0
6-
KUBECTL_VERSION ?= v1.27.3
7-
K8S_MAJOR_VERSION ?= 1.27
8-
KUSTOMIZE_VERSION ?= v3.10.0
9-
CONTROLLER_TOOLS_VERSION ?= v0.11.1
5+
KIND_VERSION ?= v0.27.0
6+
KUBECTL_VERSION ?= v1.29.0
7+
KUSTOMIZE_VERSION ?= v5.4.3
108
# Note changes to the vault version should also match image tags within the integration/vault-values.yaml and config/local-development/vault-values.yaml files
11-
VAULT_VERSION ?= 1.14.0
9+
VAULT_VERSION ?= 1.19.0
1210
# The vault version should also match the appVersion in the vault helm chart
13-
VAULT_CHART_VERSION ?= 0.25.0
11+
VAULT_CHART_VERSION ?= 0.30.0
1412
# Set the Operator SDK version to use. By default, what is installed on the system is used.
1513
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
1614
OPERATOR_SDK_VERSION ?= v1.31.0
1715
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
18-
ENVTEST_K8S_VERSION ?= 1.26.0
16+
ENVTEST_K8S_VERSION ?= 1.29.0
17+
18+
CONTROLLER_TOOLS_VERSION ?= v0.14.0
19+
ENVTEST_VERSION ?= release-0.17
20+
GOLANGCI_LINT_VERSION ?= v1.59.1
1921

2022
# VERSION defines the project version for the bundle.
2123
# Update this value when you upgrade the version of your project.
@@ -190,6 +192,12 @@ docker-build: test ## Build docker image with the manager.
190192
docker-push: ## Push docker image with the manager.
191193
docker push ${IMG}
192194

195+
.PHONY: build-installer
196+
build-installer: manifests generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
197+
mkdir -p dist
198+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
199+
$(KUSTOMIZE) build config/default > dist/install.yaml
200+
193201
##@ Deployment
194202

195203
ifndef ignore-not-found
@@ -213,28 +221,75 @@ deploy: manifests kustomize kubectl ## Deploy controller to the K8s cluster spec
213221
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.
214222
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
215223

224+
##@ Dependencies
225+
226+
## Location to install dependencies to
216227
LOCALBIN ?= $(shell pwd)/bin
217228
$(LOCALBIN):
218229
mkdir -p $(LOCALBIN)
219230

220-
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
221-
.PHONY: kustomize
231+
## Tool Binaries
232+
# KUBECTL ?= kubectl
222233
KUSTOMIZE ?= $(LOCALBIN)/kustomize
234+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
235+
ENVTEST ?= $(LOCALBIN)/setup-envtest
236+
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
237+
238+
## Tool Versions
239+
# above
240+
241+
.PHONY: kustomize
223242
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
224243
$(KUSTOMIZE): $(LOCALBIN)
225-
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
244+
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION))
226245

227246
.PHONY: controller-gen
228-
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
229247
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
230248
$(CONTROLLER_GEN): $(LOCALBIN)
231-
test -s $(LOCALBIN)/controller-gen || echo "Downloading controller-gen to ${CONTROLLER_GEN}..." && GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
249+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
232250

233251
.PHONY: envtest
234-
ENVTEST ?= $(LOCALBIN)/setup-envtest
235-
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
252+
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
236253
$(ENVTEST): $(LOCALBIN)
237-
test -s $(LOCALBIN)/setup-envtest || echo "Downloading setup-envtest to ${ENVTEST}..." && GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.16
254+
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
255+
256+
.PHONY: golangci-lint
257+
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
258+
$(GOLANGCI_LINT): $(LOCALBIN)
259+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
260+
261+
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
262+
# $1 - target path with name of binary
263+
# $2 - package url which can be installed
264+
# $3 - specific version of package
265+
define go-install-tool
266+
@[ -f "$(1)-$(3)" ] || { \
267+
set -e; \
268+
package=$(2)@$(3) ;\
269+
echo "Downloading $${package}" ;\
270+
rm -f $(1) || true ;\
271+
GOBIN=$(LOCALBIN) go install $${package} ;\
272+
mv $(1) $(1)-$(3) ;\
273+
} ;\
274+
ln -sf $(1)-$(3) $(1)
275+
endef
276+
277+
.PHONY: operator-sdk
278+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
279+
operator-sdk: ## Download operator-sdk locally if necessary.
280+
ifeq (,$(wildcard $(OPERATOR_SDK)))
281+
ifeq (, $(shell which operator-sdk 2>/dev/null))
282+
@{ \
283+
set -e ;\
284+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
285+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
286+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
287+
chmod +x $(OPERATOR_SDK) ;\
288+
}
289+
else
290+
OPERATOR_SDK = $(shell which operator-sdk)
291+
endif
292+
endif
238293

239294
.PHONY: bundle
240295
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.

Tiltfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ custom_build(
2626
local_resource(
2727
'vault-config-operator-manifests',
2828
'make manifests',
29-
deps=['./bin']
29+
deps=['./api']
3030
)
3131

3232
allow_k8s_contexts(k8s_context())

api/v1alpha1/randomsecret_types.go

+9
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,18 @@ type RandomSecretSpec struct {
8080
// +kubebuilder:validation:Optional
8181
// +kubebuilder:validation:Pattern:=`[a-z0-9]([-a-z0-9]*[a-z0-9])?`
8282
Name string `json:"name,omitempty"`
83+
84+
// The KV secret retain policy to apply when the Kubernetes resource is deleted.
85+
// When unspecified, the KV secret is also deleted.
86+
// +kubebuilder:validation:Optional
87+
// +kubebuilder:validation:Enum:={"Delete","Retain"}
88+
// +kubebuilder:default:="Delete"
89+
KvSecretRetainPolicy string `json:"kvSecretRetainPolicy,omitempty"`
8390
}
8491

8592
const ttlKey string = "ttl"
93+
const RetainKvSecretRetainPolicy = "Retain"
94+
const DeleteKvSecretRetainPolicy = "Delete"
8695

8796
var _ vaultutils.VaultObject = &RandomSecret{}
8897
var _ vaultutils.ConditionsAware = &RandomSecret{}

api/v1alpha1/utils/vaultobject.go

+10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ func (ve *VaultEndpoint) DeleteIfExists(context context.Context) error {
8787
return nil
8888
}
8989

90+
func (ve *VaultEndpoint) Exists(context context.Context) (bool, error) {
91+
log := log.FromContext(context)
92+
_, found, err := read(context, ve.vaultObject.GetPath())
93+
if err != nil {
94+
log.Error(err, "unable to check object existence at", "path", ve.vaultObject.GetPath())
95+
return false, err
96+
}
97+
return found, nil
98+
}
99+
90100
func (ve *VaultEndpoint) Create(context context.Context) error {
91101
return write(context, ve.vaultObject.GetPath(), ve.vaultObject.GetPayload())
92102
}

api/v1alpha1/utils/zz_generated.deepcopy.go

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/webhook_suite_test.go

+34-69
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,31 @@ import (
2222
"fmt"
2323
"net"
2424
"path/filepath"
25+
"runtime"
2526
"testing"
2627
"time"
2728

2829
. "github.com/onsi/ginkgo/v2"
2930
. "github.com/onsi/gomega"
3031

31-
admissionv1beta1 "k8s.io/api/admission/v1"
32+
admissionv1 "k8s.io/api/admission/v1"
33+
"k8s.io/client-go/rest"
3234

33-
//+kubebuilder:scaffold:imports
34-
"k8s.io/apimachinery/pkg/runtime"
35+
// +kubebuilder:scaffold:imports
36+
apimachineryruntime "k8s.io/apimachinery/pkg/runtime"
3537
ctrl "sigs.k8s.io/controller-runtime"
3638
"sigs.k8s.io/controller-runtime/pkg/client"
3739
"sigs.k8s.io/controller-runtime/pkg/envtest"
3840
logf "sigs.k8s.io/controller-runtime/pkg/log"
3941
"sigs.k8s.io/controller-runtime/pkg/log/zap"
42+
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
43+
"sigs.k8s.io/controller-runtime/pkg/webhook"
4044
)
4145

4246
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
4347
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
4448

45-
// var cfg *rest.Config
49+
var cfg *rest.Config
4650
var k8sClient client.Client
4751
var testEnv *envtest.Environment
4852
var ctx context.Context
@@ -63,71 +67,31 @@ var _ = BeforeSuite(func() {
6367
testEnv = &envtest.Environment{
6468
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")},
6569
ErrorIfCRDPathMissing: false,
70+
71+
// The BinaryAssetsDirectory is only required if you want to run the tests directly
72+
// without call the makefile target test. If not informed it will look for the
73+
// default path defined in controller-runtime which is /usr/local/kubebuilder/.
74+
// Note that you must have the required binaries setup under the bin directory to perform
75+
// the tests directly. When we run make test it will be setup and used automatically.
76+
BinaryAssetsDirectory: filepath.Join("..", "..", "bin", "k8s",
77+
fmt.Sprintf("1.31.0-%s-%s", runtime.GOOS, runtime.GOARCH)),
78+
6679
WebhookInstallOptions: envtest.WebhookInstallOptions{
6780
Paths: []string{filepath.Join("..", "..", "config", "webhook")},
6881
},
6982
}
7083

71-
cfg, err := testEnv.Start()
84+
var err error
85+
// cfg is defined in this file globally.
86+
cfg, err = testEnv.Start()
7287
Expect(err).NotTo(HaveOccurred())
7388
Expect(cfg).NotTo(BeNil())
7489

75-
scheme := runtime.NewScheme()
90+
scheme := apimachineryruntime.NewScheme()
7691
err = AddToScheme(scheme)
7792
Expect(err).NotTo(HaveOccurred())
7893

79-
err = admissionv1beta1.AddToScheme(scheme)
80-
Expect(err).NotTo(HaveOccurred())
81-
82-
err = admissionv1beta1.AddToScheme(scheme)
83-
Expect(err).NotTo(HaveOccurred())
84-
85-
err = admissionv1beta1.AddToScheme(scheme)
86-
Expect(err).NotTo(HaveOccurred())
87-
88-
err = admissionv1beta1.AddToScheme(scheme)
89-
Expect(err).NotTo(HaveOccurred())
90-
91-
err = admissionv1beta1.AddToScheme(scheme)
92-
Expect(err).NotTo(HaveOccurred())
93-
94-
err = admissionv1beta1.AddToScheme(scheme)
95-
Expect(err).NotTo(HaveOccurred())
96-
97-
err = admissionv1beta1.AddToScheme(scheme)
98-
Expect(err).NotTo(HaveOccurred())
99-
100-
err = admissionv1beta1.AddToScheme(scheme)
101-
Expect(err).NotTo(HaveOccurred())
102-
103-
err = admissionv1beta1.AddToScheme(scheme)
104-
Expect(err).NotTo(HaveOccurred())
105-
106-
err = admissionv1beta1.AddToScheme(scheme)
107-
Expect(err).NotTo(HaveOccurred())
108-
109-
err = admissionv1beta1.AddToScheme(scheme)
110-
Expect(err).NotTo(HaveOccurred())
111-
112-
err = admissionv1beta1.AddToScheme(scheme)
113-
Expect(err).NotTo(HaveOccurred())
114-
115-
err = admissionv1beta1.AddToScheme(scheme)
116-
Expect(err).NotTo(HaveOccurred())
117-
118-
err = admissionv1beta1.AddToScheme(scheme)
119-
Expect(err).NotTo(HaveOccurred())
120-
121-
err = admissionv1beta1.AddToScheme(scheme)
122-
Expect(err).NotTo(HaveOccurred())
123-
124-
err = admissionv1beta1.AddToScheme(scheme)
125-
Expect(err).NotTo(HaveOccurred())
126-
127-
err = admissionv1beta1.AddToScheme(scheme)
128-
Expect(err).NotTo(HaveOccurred())
129-
130-
err = admissionv1beta1.AddToScheme(scheme)
94+
err = admissionv1.AddToScheme(scheme)
13195
Expect(err).NotTo(HaveOccurred())
13296

13397
//+kubebuilder:scaffold:scheme
@@ -139,12 +103,14 @@ var _ = BeforeSuite(func() {
139103
// start webhook server using Manager
140104
webhookInstallOptions := &testEnv.WebhookInstallOptions
141105
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
142-
Scheme: scheme,
143-
Host: webhookInstallOptions.LocalServingHost,
144-
Port: webhookInstallOptions.LocalServingPort,
145-
CertDir: webhookInstallOptions.LocalServingCertDir,
146-
LeaderElection: false,
147-
MetricsBindAddress: "0",
106+
Scheme: scheme,
107+
WebhookServer: webhook.NewServer(webhook.Options{
108+
Host: webhookInstallOptions.LocalServingHost,
109+
Port: webhookInstallOptions.LocalServingPort,
110+
CertDir: webhookInstallOptions.LocalServingCertDir,
111+
}),
112+
LeaderElection: false,
113+
Metrics: metricsserver.Options{BindAddress: "0"},
148114
})
149115
Expect(err).NotTo(HaveOccurred())
150116

@@ -171,6 +137,7 @@ var _ = BeforeSuite(func() {
171137

172138
err = (&VaultSecret{}).SetupWebhookWithManager(mgr)
173139
Expect(err).NotTo(HaveOccurred())
140+
174141
err = (&PasswordPolicy{}).SetupWebhookWithManager(mgr)
175142
Expect(err).NotTo(HaveOccurred())
176143

@@ -255,10 +222,9 @@ var _ = BeforeSuite(func() {
255222
//+kubebuilder:scaffold:webhook
256223

257224
go func() {
225+
defer GinkgoRecover()
258226
err = mgr.Start(ctx)
259-
if err != nil {
260-
Expect(err).NotTo(HaveOccurred())
261-
}
227+
Expect(err).NotTo(HaveOccurred())
262228
}()
263229

264230
// wait for the webhook server to get ready
@@ -269,8 +235,7 @@ var _ = BeforeSuite(func() {
269235
if err != nil {
270236
return err
271237
}
272-
conn.Close()
273-
return nil
238+
return conn.Close()
274239
}).Should(Succeed())
275240

276241
})

api/v1alpha1/zz_generated.deepcopy.go

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)