Skip to content

Commit ce3caa1

Browse files
operator,storage-operator: align the files with the testdata example from the operator-sdk
1 parent 5bd59d3 commit ce3caa1

File tree

68 files changed

+1145
-670
lines changed

Some content is hidden

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

68 files changed

+1145
-670
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ junit/
3232
# Buildchain artifacts
3333
/_build/
3434

35-
vagrant_config.rb
35+
vagrant_config.rb

operator/.dockerignore

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

operator/.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
21
# Binaries for programs and plugins
32
*.exe
43
*.exe~
54
*.dll
65
*.so
76
*.dylib
8-
bin
9-
testbin/*
7+
bin/*
8+
Dockerfile.cross
109

11-
# Test binary, build with `go test -c`
10+
# Test binary, built with `go test -c`
1211
*.test
1312

1413
# Output of the go coverage tool, specifically when used with LiteIDE
1514
*.out
1615

17-
# Kubernetes Generated files - skip generated files, except for vendored files
16+
# Go workspace file
17+
go.work
1818

19+
# Kubernetes Generated files - skip generated files, except for vendored files
1920
!vendor/**/zz_generated.*
2021

2122
# editor and IDE paraphernalia
2223
.idea
24+
.vscode
2325
*.swp
2426
*.swo
2527
*~

operator/.golangci.yml

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
version: "2"
2-
2+
run:
3+
allow-parallel-runners: true
34
linters:
4-
disable-all: true
5+
default: none
56
enable:
7+
- copyloopvar
68
- dupl
79
- errcheck
810
- ginkgolinter
911
- goconst
1012
- gocyclo
11-
- gofmt
12-
- goimports
13-
- gosimple
1413
- govet
1514
- ineffassign
1615
- lll
@@ -19,22 +18,35 @@ linters:
1918
- prealloc
2019
- revive
2120
- staticcheck
22-
- typecheck
2321
- unconvert
2422
- unparam
2523
- unused
26-
27-
settings:
28-
revive:
24+
settings:
25+
revive:
26+
rules:
27+
- name: comment-spacings
28+
- name: import-shadowing
29+
exclusions:
30+
generated: lax
2931
rules:
30-
- name: comment-spacings
31-
32-
exclusions:
33-
rules:
34-
- path: "api/*"
35-
linters:
36-
- lll
37-
- path: "internal/*"
38-
linters:
39-
- dupl
40-
- lll
32+
- linters:
33+
- lll
34+
path: api/*
35+
- linters:
36+
- dupl
37+
- lll
38+
path: internal/*
39+
paths:
40+
- third_party$
41+
- builtin$
42+
- examples$
43+
formatters:
44+
enable:
45+
- gofmt
46+
- goimports
47+
exclusions:
48+
generated: lax
49+
paths:
50+
- third_party$
51+
- builtin$
52+
- examples$

operator/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.24 as builder
2+
FROM golang:1.24 AS builder
33
ARG TARGETOS
44
ARG TARGETARCH
55

operator/Makefile

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ OPERATOR_SDK_VERSION ?= v1.42.0
5252

5353
# Image URL to use all building/pushing image targets
5454
IMG ?= controller:latest
55-
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56-
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
57-
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
5855

5956
# Force Go toolchain version to prevent automatic selection issues
6057
# See: https://go.dev/doc/toolchain
@@ -120,18 +117,14 @@ vet: ## Run go vet against code.
120117
test: manifests generate fmt vet setup-envtest ## Run tests.
121118
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./... | grep -v /test/) -coverprofile cover.out
122119

123-
.PHONY: setup-envtest
124-
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
125-
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
126-
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
127-
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
128-
exit 1; \
129-
}
130-
120+
# TODO(user): To use a different vendor for e2e tests, modify the setup under 'tests/e2e'.
121+
# The default setup assumes Kind is pre-installed and builds/loads the Manager Docker image locally.
122+
# CertManager is installed by default; skip with:
123+
# - CERT_MANAGER_INSTALL_SKIP=true
131124
KIND_CLUSTER ?= operator-test-e2e
132125

133126
.PHONY: setup-test-e2e
134-
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist.
127+
setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist
135128
@command -v $(KIND) >/dev/null 2>&1 || { \
136129
echo "Kind is not installed. Please install Kind manually."; \
137130
exit 1; \
@@ -144,15 +137,15 @@ setup-test-e2e: ## Set up a Kind cluster for e2e tests if it does not exist.
144137
$(KIND) create cluster --name $(KIND_CLUSTER) ;; \
145138
esac
146139

147-
.PHONY: cleanup-test-e2e
148-
cleanup-test-e2e: ## Delete the Kind cluster used for e2e tests.
149-
$(KIND) delete cluster --name $(KIND_CLUSTER)
150-
151140
.PHONY: test-e2e
152141
test-e2e: setup-test-e2e manifests generate fmt vet ## Run the e2e tests. Expected an isolated environment using Kind.
153142
KIND_CLUSTER=$(KIND_CLUSTER) go test ./test/e2e/ -v -ginkgo.v
154143
$(MAKE) cleanup-test-e2e
155144

145+
.PHONY: cleanup-test-e2e
146+
cleanup-test-e2e: ## Tear down the Kind cluster used for e2e tests
147+
@$(KIND) delete cluster --name $(KIND_CLUSTER)
148+
156149
.PHONY: lint
157150
lint: golangci-lint ## Run golangci-lint linter & yamllint
158151
$(GOLANGCI_LINT) run
@@ -252,6 +245,8 @@ KUSTOMIZE_VERSION ?= v5.6.0
252245
CONTROLLER_TOOLS_VERSION ?= v0.18.0
253246
#ENVTEST_VERSION is the version of controller-runtime release branch to fetch the envtest setup script (i.e. release-0.20)
254247
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
248+
#ENVTEST_K8S_VERSION is the version of Kubernetes to use for setting up ENVTEST binaries (i.e. 1.31)
249+
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
255250
GOLANGCI_LINT_VERSION ?= v2.8.0
256251

257252
.PHONY: kustomize
@@ -264,16 +259,24 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
264259
$(CONTROLLER_GEN): $(LOCALBIN)
265260
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
266261

262+
.PHONY: setup-envtest
263+
setup-envtest: envtest ## Download the binaries required for ENVTEST in the local bin directory.
264+
@echo "Setting up envtest binaries for Kubernetes version $(ENVTEST_K8S_VERSION)..."
265+
@$(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path || { \
266+
echo "Error: Failed to set up envtest binaries for version $(ENVTEST_K8S_VERSION)."; \
267+
exit 1; \
268+
}
269+
267270
.PHONY: envtest
268271
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
269272
$(ENVTEST): $(LOCALBIN)
270273
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
271-
274+
272275
.PHONY: golangci-lint
273276
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
274277
$(GOLANGCI_LINT): $(LOCALBIN)
275-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
276-
278+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
279+
277280
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
278281
# $1 - target path with name of binary (ideally with version)
279282
# $2 - package url which can be installed
@@ -316,7 +319,7 @@ bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metada
316319

317320
.PHONY: bundle-build
318321
bundle-build: ## Build the bundle image.
319-
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
322+
$(CONTAINER_TOOL) build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
320323

321324
.PHONY: bundle-push
322325
bundle-push: ## Push the bundle image.
@@ -356,7 +359,7 @@ endif
356359
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
357360
.PHONY: catalog-build
358361
catalog-build: opm ## Build a catalog image.
359-
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
362+
$(OPM) index add --container-tool $(CONTAINER_TOOL) --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
360363

361364
# Push the catalog image.
362365
.PHONY: catalog-push

operator/README.md

Lines changed: 72 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,121 @@
55
// TODO(user): An in-depth paragraph about your project and overview of use
66

77
## Getting Started
8-
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
9-
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).
108

11-
### Running on the cluster
12-
1. Install Instances of Custom Resources:
9+
### Prerequisites
10+
- go version v1.24.0+
11+
- docker version 17.03+.
12+
- kubectl version v1.11.3+.
13+
- Access to a Kubernetes v1.11.3+ cluster.
14+
15+
### To Deploy on the cluster
16+
**Build and push your image to the location specified by `IMG`:**
1317

1418
```sh
15-
kubectl apply -f config/samples/
19+
make docker-build docker-push IMG=<some-registry>/operator:tag
1620
```
1721

18-
2. Build and push your image to the location specified by `IMG`:
19-
22+
**NOTE:** This image ought to be published in the personal registry you specified.
23+
And it is required to have access to pull the image from the working environment.
24+
Make sure you have the proper permission to the registry if the above commands don’t work.
25+
26+
**Install the CRDs into the cluster:**
27+
2028
```sh
21-
make docker-build docker-push IMG=<some-registry>/operator:tag
29+
make install
2230
```
23-
24-
3. Deploy the controller to the cluster with the image specified by `IMG`:
31+
32+
**Deploy the Manager to the cluster with the image specified by `IMG`:**
2533

2634
```sh
2735
make deploy IMG=<some-registry>/operator:tag
2836
```
2937

30-
### Uninstall CRDs
31-
To delete the CRDs from the cluster:
38+
> **NOTE**: If you encounter RBAC errors, you may need to grant yourself cluster-admin
39+
privileges or be logged in as admin.
40+
41+
**Create instances of your solution**
42+
You can apply the samples (examples) from the config/sample:
43+
44+
```sh
45+
kubectl apply -k config/samples/
46+
```
47+
48+
>**NOTE**: Ensure that the samples has default values to test it out.
49+
50+
### To Uninstall
51+
**Delete the instances (CRs) from the cluster:**
52+
53+
```sh
54+
kubectl delete -k config/samples/
55+
```
56+
57+
**Delete the APIs(CRDs) from the cluster:**
3258

3359
```sh
3460
make uninstall
3561
```
3662

37-
### Undeploy controller
38-
UnDeploy the controller to the cluster:
63+
**UnDeploy the controller from the cluster:**
3964

4065
```sh
4166
make undeploy
4267
```
4368

44-
## Contributing
45-
// TODO(user): Add detailed information on how you would like others to contribute to this project
69+
## Project Distribution
4670

47-
### How it works
48-
This project aims to follow the Kubernetes [Operator pattern](https://kubernetes.io/docs/concepts/extend-kubernetes/operator/)
71+
Following the options to release and provide this solution to the users.
4972

50-
It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controller/)
51-
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
73+
### By providing a bundle with all YAML files
5274

53-
### Test It Out
54-
1. Install the CRDs into the cluster:
75+
1. Build the installer for the image built and published in the registry:
5576

5677
```sh
57-
make install
78+
make build-installer IMG=<some-registry>/operator:tag
5879
```
5980

60-
2. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
81+
**NOTE:** The makefile target mentioned above generates an 'install.yaml'
82+
file in the dist directory. This file contains all the resources built
83+
with Kustomize, which are necessary to install this project without its
84+
dependencies.
85+
86+
2. Using the installer
87+
88+
Users can just run 'kubectl apply -f <URL for YAML BUNDLE>' to install
89+
the project, i.e.:
6190

6291
```sh
63-
make run
92+
kubectl apply -f https://raw.githubusercontent.com/<org>/operator/<tag or branch>/dist/install.yaml
6493
```
6594

66-
**NOTE:** You can also run this in one step by running: `make install run`
95+
### By providing a Helm Chart
6796

68-
### Modifying the API definitions
69-
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
97+
1. Build the chart using the optional helm plugin
7098

7199
```sh
72-
make manifests
100+
operator-sdk edit --plugins=helm/v1-alpha
73101
```
74102

75-
**NOTE:** Run `make --help` for more information on all potential `make` targets
103+
2. See that a chart was generated under 'dist/chart', and users
104+
can obtain this solution from there.
105+
106+
**NOTE:** If you change the project, you need to update the Helm Chart
107+
using the same command above to sync the latest changes. Furthermore,
108+
if you create webhooks, you need to use the above command with
109+
the '--force' flag and manually ensure that any custom configuration
110+
previously added to 'dist/chart/values.yaml' or 'dist/chart/manager/manager.yaml'
111+
is manually re-applied afterwards.
112+
113+
## Contributing
114+
// TODO(user): Add detailed information on how you would like others to contribute to this project
115+
116+
**NOTE:** Run `make help` for more information on all potential `make` targets
76117

77118
More information can be found via the [Kubebuilder Documentation](https://book.kubebuilder.io/introduction.html)
78119

79120
## License
80121

81-
Copyright 2022.
122+
Copyright 2025.
82123

83124
Licensed under the Apache License, Version 2.0 (the "License");
84125
you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)