Skip to content
This repository was archived by the owner on May 24, 2023. It is now read-only.

Commit 6cdb09e

Browse files
authored
Update to Operator SDK 1.8.0 (#109)
1 parent 2c44794 commit 6cdb09e

File tree

149 files changed

+3356
-12338
lines changed

Some content is hidden

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

149 files changed

+3356
-12338
lines changed

.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore all files which are not go type
3+
!**/*.go
4+
!**/*.mod
5+
!**/*.sum

.github/workflows/ci.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ jobs:
4141
with:
4242
go-version: ${{ env.GO_VERSION }}
4343
- name: Build Binary
44-
run: make binary
44+
run: make build
4545
- name: Cache Artifacts
4646
uses: actions/[email protected]
4747
with:
48-
path: ${{ github.workspace }}/build/_output/bin/nginx-ingress-operator
48+
path: ${{ github.workspace }}/bin/manager
4949
key: nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }}
5050

5151
unit-tests:
@@ -71,7 +71,7 @@ jobs:
7171
- name: Fetch Cached Artifacts
7272
uses: actions/[email protected]
7373
with:
74-
path: ${{ github.workspace }}/build/_output/bin/nginx-ingress-operator
74+
path: ${{ github.workspace }}/bin/manager
7575
key: nginx-ingress-operator-${{ github.run_id }}-${{ github.run_number }}
7676
- name: Docker Buildx
7777
uses: docker/setup-buildx-action@v1
@@ -87,7 +87,6 @@ jobs:
8787
- name: Build Image
8888
uses: docker/build-push-action@v2
8989
with:
90-
file: build/Dockerfile
9190
context: '.'
9291
cache-from: type=local,src=/tmp/.buildx-cache
9392
cache-to: type=local,dest=/tmp/.buildx-cache

.gitignore

+15-70
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,25 @@
1-
# Temporary Build Files
2-
build/_output
3-
build/_test
4-
bundle.zip
5-
# Created by https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
6-
### Emacs ###
7-
# -*- mode: gitignore; -*-
8-
*~
9-
\#*\#
10-
/.emacs.desktop
11-
/.emacs.desktop.lock
12-
*.elc
13-
auto-save-list
14-
tramp
15-
.\#*
16-
# Org-mode
17-
.org-id-locations
18-
*_archive
19-
# flymake-mode
20-
*_flymake.*
21-
# eshell files
22-
/eshell/history
23-
/eshell/lastdir
24-
# elpa packages
25-
/elpa/
26-
# reftex files
27-
*.rel
28-
# AUCTeX auto folder
29-
/auto/
30-
# cask packages
31-
.cask/
32-
dist/
33-
# Flycheck
34-
flycheck_*.el
35-
# server auth directory
36-
/server/
37-
# projectiles files
38-
.projectile
39-
projectile-bookmarks.eld
40-
# directory configuration
41-
.dir-locals.el
42-
# saveplace
43-
places
44-
# url cache
45-
url/cache/
46-
# cedet
47-
ede-projects.el
48-
# smex
49-
smex-items
50-
# company-statistics
51-
company-statistics-cache.el
52-
# anaconda-mode
53-
anaconda-mode/
54-
### Go ###
1+
552
# Binaries for programs and plugins
563
*.exe
574
*.exe~
585
*.dll
596
*.so
607
*.dylib
61-
# Test binary, build with 'go test -c'
8+
bin
9+
testbin/*
10+
11+
# Test binary, build with `go test -c`
6212
*.test
13+
6314
# Output of the go coverage tool, specifically when used with LiteIDE
6415
*.out
65-
### Vim ###
66-
# swap
67-
.sw[a-p]
68-
.*.sw[a-p]
69-
# session
70-
Session.vim
71-
# temporary
72-
.netrwhist
73-
# auto-generated tag files
74-
tags
75-
### VisualStudioCode ###
76-
.vscode/*
77-
.history
78-
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
79-
.DS_Store
16+
17+
# Kubernetes Generated files - skip generated files, except for vendored files
18+
19+
!vendor/**/zz_generated.*
20+
21+
# editor and IDE paraphernalia
8022
.idea
23+
*.swp
24+
*.swo
25+
*~

Dockerfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build the manager binary
2+
FROM golang:1.16 as builder
3+
ARG VERSION
4+
5+
WORKDIR /workspace
6+
# Copy the Go Modules manifests
7+
COPY go.mod go.mod
8+
COPY go.sum go.sum
9+
# cache deps before building and copying source so that we don't need to re-download as much
10+
# and so that source changes don't invalidate our downloaded layer
11+
RUN go mod download
12+
13+
# Copy the go source
14+
COPY main.go main.go
15+
COPY api/ api/
16+
COPY controllers/ controllers/
17+
18+
# Build
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.version=${VERSION}" -a -o manager main.go
20+
21+
# Use distroless as minimal base image to package the manager binary
22+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
23+
FROM gcr.io/distroless/static:nonroot
24+
WORKDIR /
25+
COPY --from=builder --chown=65532:65532 /workspace/manager .
26+
COPY config/crd/kic ./config/crd/kic
27+
USER 65532:65532
28+
29+
ENTRYPOINT ["/manager"]

Makefile

+190-29
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,200 @@
1-
OLD_TAG = 0.1.0
2-
TAG = 0.2.0
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+
VERSION ?= 0.3.0
37

4-
IMAGE = nginx/nginx-ingress-operator
8+
# CHANNELS define the bundle channels used in the bundle.
9+
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "preview,fast,stable")
10+
# To re-generate a bundle for other specific channels without changing the standard setup, you can:
11+
# - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=preview,fast,stable)
12+
# - use environment variables to overwrite this value (e.g export CHANNELS="preview,fast,stable")
13+
ifneq ($(origin CHANNELS), undefined)
14+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
15+
endif
516

6-
test:
7-
GO111MODULE=on go test ./...
17+
# DEFAULT_CHANNEL defines the default channel used in the bundle.
18+
# Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
19+
# To re-generate a bundle for any other default channel without changing the default setup, you can:
20+
# - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
21+
# - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
22+
ifneq ($(origin DEFAULT_CHANNEL), undefined)
23+
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
24+
endif
25+
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
826

9-
binary:
10-
$(eval GOPATH=$(shell go env GOPATH))
11-
CGO_ENABLED=0 GO111MODULE=on GOFLAGS="-gcflags=-trimpath=${GOPATH} -asmflags=-trimpath=${GOPATH}" GOOS=linux go build -trimpath -ldflags "-s -w" -o build/_output/bin/nginx-ingress-operator github.com/nginxinc/nginx-ingress-operator/cmd/manager
27+
# IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
28+
# This variable is used to construct full image tags for bundle and catalog images.
29+
#
30+
# For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
31+
# nginx/nginx-ingress-operator-bundle:$VERSION and nginx/nginx-ingress-operator-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= nginx/nginx-ingress-operator
1233

13-
build: binary
14-
docker build -f build/Dockerfile -t $(IMAGE):$(TAG) .
34+
# BUNDLE_IMG defines the image:tag used for the bundle.
35+
# You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
36+
BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
1537

16-
run-local:
17-
go run github.com/operator-framework/operator-sdk/cmd/operator-sdk run local
38+
# Image URL to use all building/pushing image targets
39+
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
40+
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
41+
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
1842

19-
generate-crds:
20-
go run github.com/operator-framework/operator-sdk/cmd/operator-sdk generate k8s && operator-sdk generate crds --crd-version v1beta1
43+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
44+
ifeq (,$(shell go env GOBIN))
45+
GOBIN=$(shell go env GOPATH)/bin
46+
else
47+
GOBIN=$(shell go env GOBIN)
48+
endif
2149

22-
lint:
23-
go run github.com/golangci/golangci-lint/cmd/golangci-lint run
50+
# Setting SHELL to bash allows bash commands to be executed by recipes.
51+
# This is a requirement for 'setup-envtest.sh' in the test target.
52+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
53+
SHELL = /usr/bin/env bash -o pipefail
54+
.SHELLFLAGS = -ec
2455

25-
generate-metadata: generate-crds
26-
go run github.com/operator-framework/operator-sdk/cmd/operator-sdk generate csv --csv-version=$(TAG) --from-version=$(OLD_TAG) --make-manifests=false
27-
echo "Metadata generated, please make sure you add/update fields in nginx-ingress-operator.v$(TAG).clusterserviceversion.yaml"
56+
all: build
2857

29-
generate-bundle:
30-
@mkdir bundle/$(TAG)
31-
@cp deploy/crds/* bundle/$(TAG)
32-
@cp deploy/olm-catalog/nginx-ingress-operator/nginx-ingress-operator.package.yaml bundle/
33-
@cp -R deploy/olm-catalog/nginx-ingress-operator/$(TAG)/ bundle/$(TAG)/
34-
cd bundle && opm alpha bundle generate -d ./$(TAG)/ -u ./$(TAG)/
35-
@mv bundle/bundle.Dockerfile bundle/bundle-$(TAG).Dockerfile
36-
@echo '\nLABEL com.redhat.openshift.versions="v4.5,v4.6"\nLABEL com.redhat.delivery.operator.bundle=true\nLABEL com.redhat.delivery.backport=true' >> bundle/bundle-$(TAG).Dockerfile
37-
docker build -t bundle:$(TAG) -f bundle/bundle-$(TAG).Dockerfile ./bundle
58+
##@ General
3859

39-
.PHONY: build
60+
# The help target prints out all targets with their descriptions organized
61+
# beneath their categories. The categories are represented by '##@' and the
62+
# target descriptions by '##'. The awk commands is responsible for reading the
63+
# entire set of makefiles included in this invocation, looking for lines of the
64+
# file as xyz: ## something, and then pretty-format the target and help. Then,
65+
# if there's a line with ##@ something, that gets pretty-printed as a category.
66+
# More info on the usage of ANSI control characters for terminal formatting:
67+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
68+
# More info on the awk command:
69+
# http://linuxcommand.org/lc3_adv_awk.php
70+
71+
help: ## Display this help.
72+
@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)
73+
74+
##@ Development
75+
76+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
77+
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
78+
79+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
80+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
81+
82+
fmt: ## Run go fmt against code.
83+
go fmt ./...
84+
85+
vet: ## Run go vet against code.
86+
go vet ./...
87+
88+
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
89+
test: manifests generate fmt vet ## Run tests.
90+
mkdir -p ${ENVTEST_ASSETS_DIR}
91+
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.8.3/hack/setup-envtest.sh
92+
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./... -coverprofile cover.out
93+
94+
##@ Build
95+
96+
build: generate fmt vet ## Build manager binary.
97+
go build -ldflags "-X main.version=${VERSION}" -o bin/manager main.go
98+
99+
run: manifests generate fmt vet ## Run a controller from your host.
100+
go run -ldflags "-X main.version=${VERSION}" ./main.go $(ARGS)
101+
102+
docker-build: test ## Build docker image with the manager.
103+
docker build -t ${IMG} . --build-arg VERSION=${VERSION}
104+
105+
docker-push: ## Push docker image with the manager.
106+
docker push ${IMG}
107+
108+
##@ Deployment
109+
110+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
111+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
112+
113+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
114+
$(KUSTOMIZE) build config/crd | kubectl delete -f -
115+
116+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
117+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
118+
$(KUSTOMIZE) build config/default | kubectl apply -f -
119+
120+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
121+
$(KUSTOMIZE) build config/default | kubectl delete -f -
122+
123+
124+
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
125+
controller-gen: ## Download controller-gen locally if necessary.
126+
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
127+
128+
KUSTOMIZE = $(shell pwd)/bin/kustomize
129+
kustomize: ## Download kustomize locally if necessary.
130+
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])
131+
132+
# go-get-tool will 'go get' any package $2 and install it to $1.
133+
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
134+
define go-get-tool
135+
@[ -f $(1) ] || { \
136+
set -e ;\
137+
TMP_DIR=$$(mktemp -d) ;\
138+
cd $$TMP_DIR ;\
139+
go mod init tmp ;\
140+
echo "Downloading $(2)" ;\
141+
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
142+
rm -rf $$TMP_DIR ;\
143+
}
144+
endef
145+
146+
.PHONY: bundle
147+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
148+
operator-sdk generate kustomize manifests -q
149+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
150+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
151+
operator-sdk bundle validate ./bundle
152+
153+
.PHONY: bundle-build
154+
bundle-build: ## Build the bundle image.
155+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
156+
157+
.PHONY: bundle-push
158+
bundle-push: ## Push the bundle image.
159+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
160+
161+
.PHONY: opm
162+
OPM = ./bin/opm
163+
opm: ## Download opm locally if necessary.
164+
ifeq (,$(wildcard $(OPM)))
165+
ifeq (,$(shell which opm 2>/dev/null))
166+
@{ \
167+
set -e ;\
168+
mkdir -p $(dir $(OPM)) ;\
169+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
170+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.17.2/$${OS}-$${ARCH}-opm ;\
171+
chmod +x $(OPM) ;\
172+
}
173+
else
174+
OPM = $(shell which opm)
175+
endif
176+
endif
177+
178+
# 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).
179+
# These images MUST exist in a registry and be pull-able.
180+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
181+
182+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
183+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
184+
185+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
186+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
187+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
188+
endif
189+
190+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
191+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
192+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
193+
.PHONY: catalog-build
194+
catalog-build: opm ## Build a catalog image.
195+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
196+
197+
# Push the catalog image.
198+
.PHONY: catalog-push
199+
catalog-push: ## Push a catalog image.
200+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

0 commit comments

Comments
 (0)