Skip to content

Commit aa92cf4

Browse files
committed
buildchain: generate nginx-operator bundle
1 parent cd87bbe commit aa92cf4

File tree

246 files changed

+10026
-0
lines changed

Some content is hidden

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

246 files changed

+10026
-0
lines changed

buildchain/buildchain/constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
# Path to the MetalK8s operator source directory
6868
METALK8S_OPERATOR_ROOT: Path = ROOT / "operator"
6969
# Path to the storage-operator source directory.
70+
NGINX_OPERATOR_ROOT: Path = ROOT / "nginx-operator"
71+
# Path to the nginx-operator source directory.
7072
STORAGE_OPERATOR_ROOT: Path = ROOT / "storage-operator"
7173
# Path to the UI build root directory.
7274
UI_BUILD_ROOT: Path = config.BUILD_ROOT / "ui"

buildchain/buildchain/image.py

+10
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ def _local_image(name: str, **kwargs: Any) -> targets.LocalImage:
330330
"VERSION": versions.VERSION,
331331
},
332332
),
333+
_local_image(
334+
name="nginx-operator",
335+
dockerfile=constants.NGINX_OPERATOR_ROOT / "Dockerfile",
336+
build_context=constants.NGINX_OPERATOR_ROOT,
337+
),
338+
_local_image(
339+
name="nginx-operator-bundle",
340+
dockerfile=constants.NGINX_OPERATOR_ROOT / "bundle.Dockerfile",
341+
build_context=constants.NGINX_OPERATOR_ROOT,
342+
),
333343
)
334344
# }}}
335345

buildchain/buildchain/versions.py

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
CALICO_VERSION: str = "3.29.0"
2929
SALT_VERSION: str = "3002.9"
3030
CONTAINERD_VERSION: str = "1.6.36"
31+
NGINX_OPERATOR_VERSION: str = "4.11.3"
3132

3233
CONTAINERD_RELEASE: str = "1"
3334
SOSREPORT_RELEASE: str = "2"
@@ -283,6 +284,16 @@ def _version_prefix(version: str, prefix: str = "v") -> str:
283284
version=VERSION,
284285
digest=None,
285286
),
287+
Image(
288+
name="nginx-operator",
289+
version=NGINX_OPERATOR_VERSION,
290+
digest=None,
291+
),
292+
Image(
293+
name="nginx-operator-bundle",
294+
version=NGINX_OPERATOR_VERSION,
295+
digest=None,
296+
),
286297
Image(
287298
name="loki",
288299
version="3.2.0",

nginx-operator/.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
10+
# editor and IDE paraphernalia
11+
.idea
12+
*.swp
13+
*.swo
14+
*~

nginx-operator/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Build the manager binary
2+
FROM quay.io/operator-framework/helm-operator:v1.38.0
3+
4+
ENV HOME=/opt/helm
5+
COPY watches.yaml ${HOME}/watches.yaml
6+
COPY helm-charts ${HOME}/helm-charts
7+
WORKDIR ${HOME}

nginx-operator/Makefile

+230
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
# VERSION defines the project version for the bundle.
2+
# Update this value when you upgrade the version of your project.
3+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
4+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
5+
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
6+
#
7+
# We keep this aligned with the chart version
8+
# Will also be set in versions.py
9+
VERSION ?= 4.11.3
10+
11+
# CHANNELS define the bundle channels used in the bundle.
12+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
13+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
14+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
15+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
16+
ifneq ($(origin CHANNELS), undefined)
17+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
18+
endif
19+
20+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
21+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
22+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
23+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
24+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
25+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
26+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
27+
endif
28+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
29+
30+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
31+
# This variable is used to construct full image tags for bundle and catalog images.
32+
#
33+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
34+
# scality.com/nginx-operator-bundle:$VERSION and scality.com/nginx-operator-catalog:$VERSION.
35+
IMAGE_TAG_BASE ?= scality.com/nginx-operator
36+
37+
# BUNDLE_IMG defines the image:tag used for the bundle.
38+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
39+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
40+
41+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
42+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
43+
44+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
45+
# You can enable this value if you would like to use SHA Based Digests
46+
# To enable set flag to true
47+
USE_IMAGE_DIGESTS ?= false
48+
ifeq ($(USE_IMAGE_DIGESTS), true)
49+
BUNDLE_GEN_FLAGS += --use-image-digests
50+
endif
51+
52+
# Set the Operator SDK version to use. By default, what is installed on the system is used.
53+
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
54+
OPERATOR_SDK_VERSION ?= v1.38.0
55+
56+
# Image URL to use all building/pushing image targets
57+
IMG ?= registry.metalk8s.lan/nginx-operator:v$(VERSION)
58+
59+
.PHONY: all
60+
all: docker-build
61+
62+
##@ General
63+
64+
# The help target prints out all targets with their descriptions organized
65+
# beneath their categories. The categories are represented by '##@' and the
66+
# target descriptions by '##'. The awk commands is responsible for reading the
67+
# entire set of makefiles included in this invocation, looking for lines of the
68+
# file as xyz: ## something, and then pretty-format the target and help. Then,
69+
# if there's a line with ##@ something, that gets pretty-printed as a category.
70+
# More info on the usage of ANSI control characters for terminal formatting:
71+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
72+
# More info on the awk command:
73+
# http://linuxcommand.org/lc3_adv_awk.php
74+
75+
.PHONY: help
76+
help: ## Display this help.
77+
@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)
78+
79+
##@ Build
80+
81+
.PHONY: run
82+
run: helm-operator ## Run against the configured Kubernetes cluster in ~/.kube/config
83+
$(HELM_OPERATOR) run
84+
85+
.PHONY: docker-build
86+
docker-build: ## Build docker image with the manager.
87+
docker build -t ${IMG} .
88+
89+
.PHONY: docker-push
90+
docker-push: ## Push docker image with the manager.
91+
docker push ${IMG}
92+
93+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
94+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
95+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
96+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
97+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> than the export will fail)
98+
# To properly provided solutions that supports more than one platform you should use this option.
99+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
100+
.PHONY: docker-buildx
101+
docker-buildx: ## Build and push docker image for the manager for cross-platform support
102+
- docker buildx create --name project-v3-builder
103+
docker buildx use project-v3-builder
104+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile .
105+
- docker buildx rm project-v3-builder
106+
107+
##@ Deployment
108+
109+
.PHONY: install
110+
install: kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
111+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
112+
113+
.PHONY: uninstall
114+
uninstall: kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
115+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
116+
117+
.PHONY: deploy
118+
deploy: kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
119+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
120+
$(KUSTOMIZE) build config/default | kubectl apply -f -
121+
122+
.PHONY: undeploy
123+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
124+
$(KUSTOMIZE) build config/default | kubectl delete -f -
125+
126+
OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
127+
ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
128+
129+
.PHONY: kustomize
130+
KUSTOMIZE = $(shell pwd)/bin/kustomize
131+
kustomize: ## Download kustomize locally if necessary.
132+
ifeq (,$(wildcard $(KUSTOMIZE)))
133+
ifeq (,$(shell which kustomize 2>/dev/null))
134+
@{ \
135+
set -e ;\
136+
mkdir -p $(dir $(KUSTOMIZE)) ;\
137+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v5.4.2/kustomize_v5.4.2_$(OS)_$(ARCH).tar.gz | \
138+
tar xzf - -C bin/ ;\
139+
}
140+
else
141+
KUSTOMIZE = $(shell which kustomize)
142+
endif
143+
endif
144+
145+
.PHONY: helm-operator
146+
HELM_OPERATOR = $(shell pwd)/bin/helm-operator
147+
helm-operator: ## Download helm-operator locally if necessary, preferring the $(pwd)/bin path over global if both exist.
148+
ifeq (,$(wildcard $(HELM_OPERATOR)))
149+
ifeq (,$(shell which helm-operator 2>/dev/null))
150+
@{ \
151+
set -e ;\
152+
mkdir -p $(dir $(HELM_OPERATOR)) ;\
153+
curl -sSLo $(HELM_OPERATOR) https://github.com/operator-framework/operator-sdk/releases/download/v1.38.0/helm-operator_$(OS)_$(ARCH) ;\
154+
chmod +x $(HELM_OPERATOR) ;\
155+
}
156+
else
157+
HELM_OPERATOR = $(shell which helm-operator)
158+
endif
159+
endif
160+
161+
.PHONY: operator-sdk
162+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
163+
operator-sdk: ## Download operator-sdk locally if necessary.
164+
ifeq (,$(wildcard $(OPERATOR_SDK)))
165+
ifeq (, $(shell which operator-sdk 2>/dev/null))
166+
@{ \
167+
set -e ;\
168+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
169+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$(OS)_$(ARCH) ;\
170+
chmod +x $(OPERATOR_SDK) ;\
171+
}
172+
else
173+
OPERATOR_SDK = $(shell which operator-sdk)
174+
endif
175+
endif
176+
177+
.PHONY: bundle
178+
bundle: kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
179+
$(OPERATOR_SDK) generate kustomize manifests -q
180+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
181+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
182+
$(OPERATOR_SDK) bundle validate ./bundle
183+
184+
.PHONY: bundle-build
185+
bundle-build: ## Build the bundle image.
186+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
187+
188+
.PHONY: bundle-push
189+
bundle-push: ## Push the bundle image.
190+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
191+
192+
.PHONY: opm
193+
OPM = $(LOCALBIN)/opm
194+
opm: ## Download opm locally if necessary.
195+
ifeq (,$(wildcard $(OPM)))
196+
ifeq (,$(shell which opm 2>/dev/null))
197+
@{ \
198+
set -e ;\
199+
mkdir -p $(dir $(OPM)) ;\
200+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$(OS)-$(ARCH)-opm ;\
201+
chmod +x $(OPM) ;\
202+
}
203+
else
204+
OPM = $(shell which opm)
205+
endif
206+
endif
207+
208+
# A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0).
209+
# These images MUST exist in a registry and be pull-able.
210+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
211+
212+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
213+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
214+
215+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
216+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
217+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
218+
endif
219+
220+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
221+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
222+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
223+
.PHONY: catalog-build
224+
catalog-build: opm ## Build a catalog image.
225+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
226+
227+
# Push the catalog image.
228+
.PHONY: catalog-push
229+
catalog-push: ## Push a catalog image.
230+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

nginx-operator/PROJECT

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
domain: scality.com
6+
layout:
7+
- helm.sdk.operatorframework.io/v1
8+
plugins:
9+
manifests.sdk.operatorframework.io/v2: {}
10+
scorecard.sdk.operatorframework.io/v2: {}
11+
projectName: nginx-operator
12+
resources:
13+
- api:
14+
crdVersion: v1
15+
namespaced: true
16+
domain: scality.com
17+
group: metalk8s
18+
kind: IngressNginx
19+
version: v1alpha1
20+
version: "3"

nginx-operator/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# NGINX-operator
2+
3+
This operator manages IngressNginx CRs and uses them as a values file for the [ingress-nginx](https://github.com/kubernetes/ingress-nginx) helm chart.
4+
5+
## instructions
6+
7+
### Update helm chart
8+
9+
from within this directory:
10+
11+
```
12+
VERSION=<...>
13+
rm -rf helm-charts/ingress-nginx
14+
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
15+
helm repo update
16+
helm fetch -d helm-charts --untar https://kubernetes.github.io/ingress-nginx/ingress-nginx --version $VERSION
17+
sed -i "s/^VERSION.*/VERSION ?= $VERSION/" Makefile
18+
make bundle
19+
```
20+
21+
also change `NGINX_OPERATOR_VERSION` in `buildchain/buildchain/versions.py`.

nginx-operator/bundle.Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM scratch
2+
3+
# Core bundle labels.
4+
LABEL operators.operatorframework.io.bundle.mediatype.v1=registry+v1
5+
LABEL operators.operatorframework.io.bundle.manifests.v1=manifests/
6+
LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
7+
LABEL operators.operatorframework.io.bundle.package.v1=nginx-operator
8+
LABEL operators.operatorframework.io.bundle.channels.v1=alpha
9+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.38.0
10+
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
11+
LABEL operators.operatorframework.io.metrics.project_layout=helm.sdk.operatorframework.io/v1
12+
13+
# Labels for testing.
14+
LABEL operators.operatorframework.io.test.mediatype.v1=scorecard+v1
15+
LABEL operators.operatorframework.io.test.config.v1=tests/scorecard/
16+
17+
# Copy files to locations specified by labels.
18+
COPY bundle/manifests /manifests/
19+
COPY bundle/metadata /metadata/
20+
COPY bundle/tests/scorecard /tests/scorecard/

0 commit comments

Comments
 (0)