Skip to content

Commit e6952fa

Browse files
committed
Init dspipelines controller via operator sdk.
Signed-off-by: Humair Khan <[email protected]>
1 parent b087d54 commit e6952fa

Some content is hidden

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

45 files changed

+2472
-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

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

Dockerfile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Build the manager binary
2+
FROM golang:1.19 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+
RUN go mod download
13+
14+
# Copy the go source
15+
COPY main.go main.go
16+
COPY api/ api/
17+
COPY controllers/ controllers/
18+
19+
# Build
20+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
21+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
22+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
23+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go
25+
26+
# Use distroless as minimal base image to package the manager binary
27+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
28+
FROM gcr.io/distroless/static:nonroot
29+
WORKDIR /
30+
COPY --from=builder /workspace/manager .
31+
USER 65532:65532
32+
33+
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 quay.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+
# opendatahub.io/ds-pipelines-controller-bundle:$VERSION and opendatahub.io/ds-pipelines-controller-catalog:$VERSION.
32+
IMAGE_TAG_BASE ?= opendatahub.io/ds-pipelines-controller
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.25.0
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) --bin-dir $(LOCALBIN) -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 podman 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.10.0
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 -Ss $(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: opendatahub.io
2+
layout:
3+
- go.kubebuilder.io/v3
4+
plugins:
5+
manifests.sdk.operatorframework.io/v2: {}
6+
scorecard.sdk.operatorframework.io/v2: {}
7+
projectName: ds-pipelines-controller
8+
repo: github.com/opendatahub-io/ds-pipelines-controller
9+
resources:
10+
- api:
11+
crdVersion: v1
12+
namespaced: true
13+
controller: true
14+
domain: opendatahub.io
15+
group: dspipelines.io
16+
kind: DSPipeline
17+
path: github.com/opendatahub-io/ds-pipelines-controller/api/v1alpha1
18+
version: v1alpha1
19+
version: "3"

api/v1alpha1/dspipeline_types.go

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
24+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
25+
26+
// DSPipelineSpec defines the desired state of DSPipeline
27+
type DSPipelineSpec struct {
28+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
29+
// Important: Run "make" to regenerate code after modifying this file
30+
31+
// Foo is an example field of DSPipeline. Edit dspipeline_types.go to remove/update
32+
Foo string `json:"foo,omitempty"`
33+
}
34+
35+
// DSPipelineStatus defines the observed state of DSPipeline
36+
type DSPipelineStatus struct {
37+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
38+
// Important: Run "make" to regenerate code after modifying this file
39+
}
40+
41+
//+kubebuilder:object:root=true
42+
//+kubebuilder:subresource:status
43+
44+
// DSPipeline is the Schema for the dspipelines API
45+
type DSPipeline struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec DSPipelineSpec `json:"spec,omitempty"`
50+
Status DSPipelineStatus `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// DSPipelineList contains a list of DSPipeline
56+
type DSPipelineList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []DSPipeline `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&DSPipeline{}, &DSPipelineList{})
64+
}

0 commit comments

Comments
 (0)