Skip to content

Commit ad19b9d

Browse files
authored
Merge pull request #1 from ambiknai/operatorbase
Initial commit
2 parents 587677a + 726ee6c commit ad19b9d

Some content is hidden

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

61 files changed

+6654
-685
lines changed

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Build the manager binary
2+
FROM golang:1.20 as builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
6+
WORKDIR /workspace
7+
# Copy the Go Modules manifests
8+
#COPY go.mod go.mod
9+
#COPY go.sum go.sum
10+
# cache deps before building and copying source so that we don't need to re-download as much
11+
# and so that source changes don't invalidate our downloaded layer
12+
13+
14+
COPY . .
15+
#RUN go mod download
16+
17+
# Copy the go source
18+
#COPY main.go main.go
19+
#COPY api/ api/
20+
#COPY controllers/ controllers/
21+
22+
# Build
23+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
24+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
25+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
26+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
27+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ibm-object-csi-operator main.go
28+
29+
30+
31+
32+
# Use distroless as minimal base image to package the manager binary
33+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
34+
FROM gcr.io/distroless/static:nonroot
35+
36+
ENV OPERATOR=/usr/local/bin/ibm-object-csi-operator \
37+
USER_UID=1001 \
38+
USER_NAME=ibm-object-csi-operator \
39+
IBMObjectCSI_CR_YAML=/usr/local/etc/csi_v1alpha1_ibmobjectcsi.yaml
40+
41+
COPY --from=builder /workspace/config/samples/csi_v1alpha1_ibmobjectcsi.yaml ${IBMObjectCSI_CR_YAML}
42+
#RUN chmod 0444 ${IBMObjectCSI_CR_YAML}
43+
44+
45+
WORKDIR /
46+
COPY --from=builder /workspace/ibm-object-csi-operator .
47+
USER 65532:65532
48+
49+
ENTRYPOINT ["/ibm-object-csi-operator"]

Makefile

Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
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.0.1
7+
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 = "candidate,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=candidate,fast,stable)
12+
# - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
13+
ifneq ($(origin CHANNELS), undefined)
14+
BUNDLE_CHANNELS := --channels=$(CHANNELS)
15+
endif
16+
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)
26+
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+
# ibm.com/ibm-object-csi-driver-operator-bundle:$VERSION and ibm.com/ibm-object-csi-driver-operator-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= ibm.com/ibm-object-csi-driver-operator
33+
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)
37+
38+
# BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
39+
BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
40+
41+
# USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
42+
# You can enable this value if you would like to use SHA Based Digests
43+
# To enable set flag to true
44+
USE_IMAGE_DIGESTS ?= false
45+
ifeq ($(USE_IMAGE_DIGESTS), true)
46+
BUNDLE_GEN_FLAGS += --use-image-digests
47+
endif
48+
49+
# Set the Operator SDK version to use. By default, what is installed on the system is used.
50+
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
51+
OPERATOR_SDK_VERSION ?= v1.32.0
52+
53+
# Image URL to use all building/pushing image targets
54+
IMG ?= controller:latest
55+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
56+
ENVTEST_K8S_VERSION = 1.26.0
57+
58+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
59+
ifeq (,$(shell go env GOBIN))
60+
GOBIN=$(shell go env GOPATH)/bin
61+
else
62+
GOBIN=$(shell go env GOBIN)
63+
endif
64+
65+
# Setting SHELL to bash allows bash commands to be executed by recipes.
66+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
67+
SHELL = /usr/bin/env bash -o pipefail
68+
.SHELLFLAGS = -ec
69+
70+
.PHONY: all
71+
all: build
72+
73+
##@ General
74+
75+
# The help target prints out all targets with their descriptions organized
76+
# beneath their categories. The categories are represented by '##@' and the
77+
# target descriptions by '##'. The awk commands is responsible for reading the
78+
# entire set of makefiles included in this invocation, looking for lines of the
79+
# file as xyz: ## something, and then pretty-format the target and help. Then,
80+
# if there's a line with ##@ something, that gets pretty-printed as a category.
81+
# More info on the usage of ANSI control characters for terminal formatting:
82+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
83+
# More info on the awk command:
84+
# http://linuxcommand.org/lc3_adv_awk.php
85+
86+
.PHONY: help
87+
help: ## Display this help.
88+
@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)
89+
90+
##@ Development
91+
92+
.PHONY: manifests
93+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
94+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
95+
96+
.PHONY: generate
97+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
98+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
99+
100+
.PHONY: fmt
101+
fmt: ## Run go fmt against code.
102+
go fmt ./...
103+
104+
.PHONY: vet
105+
vet: ## Run go vet against code.
106+
go vet ./...
107+
108+
.PHONY: test
109+
test: manifests generate fmt vet envtest ## Run tests.
110+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
111+
112+
##@ Build
113+
114+
.PHONY: build
115+
build: manifests generate fmt vet ## Build manager binary.
116+
go build -o bin/manager main.go
117+
118+
.PHONY: run
119+
run: manifests generate fmt vet ## Run a controller from your host.
120+
go run ./main.go
121+
122+
# If you wish built the manager image targeting other platforms you can use the --platform flag.
123+
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
124+
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
125+
.PHONY: docker-build
126+
docker-build: test ## Build docker image with the manager.
127+
docker build -t ${IMG} .
128+
129+
.PHONY: docker-push
130+
docker-push: ## Push docker image with the manager.
131+
docker push ${IMG}
132+
133+
# PLATFORMS defines the target platforms for the manager image be build to provide support to multiple
134+
# architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
135+
# - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
136+
# - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
137+
# - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
138+
# To properly provided solutions that supports more than one platform you should use this option.
139+
PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
140+
.PHONY: docker-buildx
141+
docker-buildx: test ## Build and push docker image for the manager for cross-platform support
142+
# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
143+
sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
144+
- docker buildx create --name project-v3-builder
145+
docker buildx use project-v3-builder
146+
- docker buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
147+
- docker buildx rm project-v3-builder
148+
rm Dockerfile.cross
149+
150+
##@ Deployment
151+
152+
ifndef ignore-not-found
153+
ignore-not-found = false
154+
endif
155+
156+
.PHONY: install
157+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
158+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
159+
160+
.PHONY: uninstall
161+
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.
162+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
163+
164+
.PHONY: deploy
165+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
166+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
167+
$(KUSTOMIZE) build config/default | kubectl apply -f -
168+
169+
.PHONY: undeploy
170+
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.
171+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
172+
173+
##@ Build Dependencies
174+
175+
## Location to install dependencies to
176+
LOCALBIN ?= $(shell pwd)/bin
177+
$(LOCALBIN):
178+
mkdir -p $(LOCALBIN)
179+
180+
## Tool Binaries
181+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
182+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
183+
ENVTEST ?= $(LOCALBIN)/setup-envtest
184+
185+
## Tool Versions
186+
KUSTOMIZE_VERSION ?= v3.8.7
187+
CONTROLLER_TOOLS_VERSION ?= v0.11.1
188+
189+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
190+
.PHONY: kustomize
191+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
192+
$(KUSTOMIZE): $(LOCALBIN)
193+
@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
194+
echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
195+
rm -rf $(LOCALBIN)/kustomize; \
196+
fi
197+
test -s $(LOCALBIN)/kustomize || { curl -Ss $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
198+
199+
.PHONY: controller-gen
200+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
201+
$(CONTROLLER_GEN): $(LOCALBIN)
202+
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
203+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
204+
205+
.PHONY: envtest
206+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
207+
$(ENVTEST): $(LOCALBIN)
208+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
209+
210+
.PHONY: operator-sdk
211+
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
212+
operator-sdk: ## Download operator-sdk locally if necessary.
213+
ifeq (,$(wildcard $(OPERATOR_SDK)))
214+
ifeq (, $(shell which operator-sdk 2>/dev/null))
215+
@{ \
216+
set -e ;\
217+
mkdir -p $(dir $(OPERATOR_SDK)) ;\
218+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
219+
curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
220+
chmod +x $(OPERATOR_SDK) ;\
221+
}
222+
else
223+
OPERATOR_SDK = $(shell which operator-sdk)
224+
endif
225+
endif
226+
227+
.PHONY: bundle
228+
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
229+
$(OPERATOR_SDK) generate kustomize manifests -q
230+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
231+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
232+
$(OPERATOR_SDK) bundle validate ./bundle
233+
234+
.PHONY: bundle-build
235+
bundle-build: ## Build the bundle image.
236+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
237+
238+
.PHONY: bundle-push
239+
bundle-push: ## Push the bundle image.
240+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
241+
242+
.PHONY: opm
243+
OPM = ./bin/opm
244+
opm: ## Download opm locally if necessary.
245+
ifeq (,$(wildcard $(OPM)))
246+
ifeq (,$(shell which opm 2>/dev/null))
247+
@{ \
248+
set -e ;\
249+
mkdir -p $(dir $(OPM)) ;\
250+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
251+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
252+
chmod +x $(OPM) ;\
253+
}
254+
else
255+
OPM = $(shell which opm)
256+
endif
257+
endif
258+
259+
# 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).
260+
# These images MUST exist in a registry and be pull-able.
261+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
262+
263+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
264+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
265+
266+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
267+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
268+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
269+
endif
270+
271+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
272+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
273+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
274+
.PHONY: catalog-build
275+
catalog-build: opm ## Build a catalog image.
276+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
277+
278+
# Push the catalog image.
279+
.PHONY: catalog-push
280+
catalog-push: ## Push a catalog image.
281+
$(MAKE) docker-push IMG=$(CATALOG_IMG)

PROJECT

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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: ibm.com
6+
layout:
7+
- go.kubebuilder.io/v3
8+
plugins:
9+
manifests.sdk.operatorframework.io/v2: {}
10+
scorecard.sdk.operatorframework.io/v2: {}
11+
projectName: ibm-object-csi-driver-operator
12+
repo: github.ibm.com/alchemy-containers/ibm-object-csi-driver-operator
13+
resources:
14+
- api:
15+
crdVersion: v1
16+
namespaced: true
17+
controller: true
18+
domain: ibm.com
19+
group: csi
20+
kind: IBMObjectCSI
21+
path: github.ibm.com/alchemy-containers/ibm-object-csi-driver-operator/api/v1alpha1
22+
version: v1alpha1
23+
version: "3"

0 commit comments

Comments
 (0)