Skip to content

Commit e6da117

Browse files
committed
Use operator-sdk to generate stub
Signed-off-by: Anish Asthana <[email protected]>
1 parent 768fe67 commit e6da117

Some content is hidden

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

46 files changed

+2557
-0
lines changed

.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
2+
# Ignore build and test binaries.
3+
bin/
4+
testbin/

.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
# Binaries for programs and plugins
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
bin
9+
testbin/*
10+
11+
# Test binary, build with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Kubernetes Generated files - skip generated files, except for vendored files
18+
19+
!vendor/**/zz_generated.*
20+
21+
# editor and IDE paraphernalia
22+
.idea
23+
*.swp
24+
*.swo
25+
*~

Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Build the manager binary
2+
FROM registry.redhat.io/ubi8/go-toolset:1.18.9-8 as builder
3+
4+
WORKDIR /workspace
5+
# Copy the Go Modules manifests
6+
COPY go.mod go.mod
7+
COPY go.sum go.sum
8+
RUN go mod download
9+
10+
# Copy the go source
11+
COPY main.go main.go
12+
COPY api/ api/
13+
COPY controllers/ controllers/
14+
15+
# Build
16+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
17+
18+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7
19+
WORKDIR /
20+
COPY --from=builder /workspace/manager .
21+
USER 65532:65532
22+
23+
ENTRYPOINT ["/manager"]

Makefile

+235
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
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+
# codeflare.dev/codeflare-operator-bundle:$VERSION and codeflare.dev/codeflare-operator-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= quay.io/project-codeflare/codeflare-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+
# Image URL to use all building/pushing image targets
50+
IMG ?= controller:latest
51+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
52+
ENVTEST_K8S_VERSION = 1.24.2
53+
54+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
55+
ifeq (,$(shell go env GOBIN))
56+
GOBIN=$(shell go env GOPATH)/bin
57+
else
58+
GOBIN=$(shell go env GOBIN)
59+
endif
60+
61+
# Setting SHELL to bash allows bash commands to be executed by recipes.
62+
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
63+
SHELL = /usr/bin/env bash -o pipefail
64+
.SHELLFLAGS = -ec
65+
66+
.PHONY: all
67+
all: build
68+
69+
##@ General
70+
71+
# The help target prints out all targets with their descriptions organized
72+
# beneath their categories. The categories are represented by '##@' and the
73+
# target descriptions by '##'. The awk commands is responsible for reading the
74+
# entire set of makefiles included in this invocation, looking for lines of the
75+
# file as xyz: ## something, and then pretty-format the target and help. Then,
76+
# if there's a line with ##@ something, that gets pretty-printed as a category.
77+
# More info on the usage of ANSI control characters for terminal formatting:
78+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
79+
# More info on the awk command:
80+
# http://linuxcommand.org/lc3_adv_awk.php
81+
82+
.PHONY: help
83+
help: ## Display this help.
84+
@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)
85+
86+
##@ Development
87+
88+
.PHONY: manifests
89+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
90+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
91+
92+
.PHONY: generate
93+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
94+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
95+
96+
.PHONY: fmt
97+
fmt: ## Run go fmt against code.
98+
go fmt ./...
99+
100+
.PHONY: vet
101+
vet: ## Run go vet against code.
102+
go vet ./...
103+
104+
.PHONY: test
105+
test: manifests generate fmt vet envtest ## Run tests.
106+
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
107+
108+
##@ Build
109+
110+
.PHONY: build
111+
build: generate fmt vet ## Build manager binary.
112+
go build -o bin/manager main.go
113+
114+
.PHONY: run
115+
run: manifests generate fmt vet ## Run a controller from your host.
116+
go run ./main.go
117+
118+
.PHONY: podman-build
119+
podman-build: test ## Build container image with the manager.
120+
podman build -t ${IMG} .
121+
122+
.PHONY: podman-push
123+
podman-push: ## Push podman image with the manager.
124+
podman push ${IMG}
125+
126+
##@ Deployment
127+
128+
ifndef ignore-not-found
129+
ignore-not-found = false
130+
endif
131+
132+
.PHONY: install
133+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
134+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
135+
136+
.PHONY: uninstall
137+
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.
138+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
139+
140+
.PHONY: deploy
141+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
142+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
143+
$(KUSTOMIZE) build config/default | kubectl apply -f -
144+
145+
.PHONY: undeploy
146+
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.
147+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
148+
149+
##@ Build Dependencies
150+
151+
## Location to install dependencies to
152+
LOCALBIN ?= $(shell pwd)/bin
153+
$(LOCALBIN):
154+
mkdir -p $(LOCALBIN)
155+
156+
## Tool Binaries
157+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
158+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
159+
ENVTEST ?= $(LOCALBIN)/setup-envtest
160+
161+
## Tool Versions
162+
KUSTOMIZE_VERSION ?= v3.8.7
163+
CONTROLLER_TOOLS_VERSION ?= v0.9.2
164+
165+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
166+
.PHONY: kustomize
167+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
168+
$(KUSTOMIZE): $(LOCALBIN)
169+
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }
170+
171+
.PHONY: controller-gen
172+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
173+
$(CONTROLLER_GEN): $(LOCALBIN)
174+
test -s $(LOCALBIN)/controller-gen || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
175+
176+
.PHONY: envtest
177+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
178+
$(ENVTEST): $(LOCALBIN)
179+
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
180+
181+
.PHONY: bundle
182+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
183+
operator-sdk generate kustomize manifests -q
184+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
185+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
186+
operator-sdk bundle validate ./bundle
187+
188+
.PHONY: bundle-build
189+
bundle-build: ## Build the bundle image.
190+
podman build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
191+
192+
.PHONY: bundle-push
193+
bundle-push: ## Push the bundle image.
194+
$(MAKE) podman-push IMG=$(BUNDLE_IMG)
195+
196+
.PHONY: opm
197+
OPM = ./bin/opm
198+
opm: ## Download opm locally if necessary.
199+
ifeq (,$(wildcard $(OPM)))
200+
ifeq (,$(shell which opm 2>/dev/null))
201+
@{ \
202+
set -e ;\
203+
mkdir -p $(dir $(OPM)) ;\
204+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
205+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
206+
chmod +x $(OPM) ;\
207+
}
208+
else
209+
OPM = $(shell which opm)
210+
endif
211+
endif
212+
213+
# 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).
214+
# These images MUST exist in a registry and be pull-able.
215+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
216+
217+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
218+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
219+
220+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
221+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
222+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
223+
endif
224+
225+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
226+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
227+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
228+
.PHONY: catalog-build
229+
catalog-build: opm ## Build a catalog image.
230+
$(OPM) index add --container-tool podman --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
231+
232+
# Push the catalog image.
233+
.PHONY: catalog-push
234+
catalog-push: ## Push a catalog image.
235+
$(MAKE) podman-push IMG=$(CATALOG_IMG)

PROJECT

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
domain: codeflare.dev
2+
layout:
3+
- go.kubebuilder.io/v3
4+
plugins:
5+
manifests.sdk.operatorframework.io/v2: {}
6+
scorecard.sdk.operatorframework.io/v2: {}
7+
projectName: codeflare-operator
8+
repo: github.com/project-codeflare/codeflare-operator
9+
resources:
10+
- api:
11+
crdVersion: v1
12+
namespaced: true
13+
controller: true
14+
domain: codeflare.dev
15+
group: codeflare
16+
kind: MCAD
17+
path: github.com/project-codeflare/codeflare-operator/api/v1alpha1
18+
version: v1alpha1
19+
version: "3"

api/v1alpha1/groupversion_info.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1alpha1 contains API Schema definitions for the codeflare v1alpha1 API group
18+
//+kubebuilder:object:generate=true
19+
//+groupName=codeflare.codeflare.dev
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects
29+
GroupVersion = schema.GroupVersion{Group: "codeflare.codeflare.dev", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

0 commit comments

Comments
 (0)