Skip to content

Commit d8a8bf6

Browse files
committed
Initial import
1 parent 22a3381 commit d8a8bf6

Some content is hidden

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

58 files changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Build the manager binary
2+
FROM golang:1.18 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+
# cache deps before building and copying source so that we don't need to re-download as much
9+
# and so that source changes don't invalidate our downloaded layer
10+
RUN go mod download
11+
12+
# Copy the go source
13+
COPY main.go main.go
14+
COPY api/ api/
15+
COPY controllers/ controllers/
16+
17+
# Build
18+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
19+
20+
# Use distroless as minimal base image to package the manager binary
21+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
22+
FROM gcr.io/distroless/static:nonroot
23+
WORKDIR /
24+
COPY --from=builder /workspace/manager .
25+
USER 65532:65532
26+
27+
ENTRYPOINT ["/manager"]

Makefile

+274
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
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+
IMG ?= quay.io/c3os/osbuilder:test
8+
CLUSTER_NAME?="c3os-osbuilder-e2e"
9+
export ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
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+
# c3os-x.io/osbuilder-operator-bundle:$VERSION and c3os-x.io/osbuilder-operator-catalog:$VERSION.
35+
IMAGE_TAG_BASE ?= c3os-x.io/osbuilder-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+
# Image URL to use all building/pushing image targets
53+
IMG ?= controller:latest
54+
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
55+
ENVTEST_K8S_VERSION = 1.24.1
56+
57+
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
58+
ifeq (,$(shell go env GOBIN))
59+
GOBIN=$(shell go env GOPATH)/bin
60+
else
61+
GOBIN=$(shell go env GOBIN)
62+
endif
63+
64+
# Setting SHELL to bash allows bash commands to be executed by recipes.
65+
# This is a requirement for 'setup-envtest.sh' in the test target.
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) -p path)" go test ./... -coverprofile cover.out
111+
112+
##@ Build
113+
114+
.PHONY: build
115+
build: 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+
.PHONY: docker-build-test
123+
docker-build-test: test docker-build
124+
125+
.PHONY: docker-build
126+
docker-build: ## 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+
##@ Deployment
134+
135+
ifndef ignore-not-found
136+
ignore-not-found = false
137+
endif
138+
139+
.PHONY: install
140+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
141+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
142+
143+
.PHONY: uninstall
144+
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.
145+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
146+
147+
.PHONY: deploy
148+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
149+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
150+
$(KUSTOMIZE) build config/default | kubectl apply -f -
151+
152+
153+
.PHONY: deploy-dev
154+
deploy-dev: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
155+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
156+
$(KUSTOMIZE) build config/dev | kubectl apply -f -
157+
158+
.PHONY: undeploy
159+
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.
160+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
161+
162+
.PHONY: undeploy-dev
163+
undeploy-dev: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
164+
$(KUSTOMIZE) build config/dev | kubectl delete --ignore-not-found=$(ignore-not-found) -f - || true
165+
166+
##@ Build Dependencies
167+
168+
## Location to install dependencies to
169+
LOCALBIN ?= $(shell pwd)/bin
170+
$(LOCALBIN):
171+
mkdir -p $(LOCALBIN)
172+
173+
## Tool Binaries
174+
KUSTOMIZE ?= $(LOCALBIN)/kustomize
175+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
176+
ENVTEST ?= $(LOCALBIN)/setup-envtest
177+
178+
## Tool Versions
179+
KUSTOMIZE_VERSION ?= v3.8.7
180+
CONTROLLER_TOOLS_VERSION ?= v0.9.0
181+
182+
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
183+
.PHONY: kustomize
184+
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
185+
$(KUSTOMIZE): $(LOCALBIN)
186+
curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
187+
188+
.PHONY: controller-gen
189+
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
190+
$(CONTROLLER_GEN): $(LOCALBIN)
191+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
192+
193+
.PHONY: envtest
194+
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
195+
$(ENVTEST): $(LOCALBIN)
196+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
197+
198+
.PHONY: bundle
199+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
200+
operator-sdk generate kustomize manifests -q
201+
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
202+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
203+
operator-sdk bundle validate ./bundle
204+
205+
.PHONY: bundle-build
206+
bundle-build: ## Build the bundle image.
207+
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
208+
209+
.PHONY: bundle-push
210+
bundle-push: ## Push the bundle image.
211+
$(MAKE) docker-push IMG=$(BUNDLE_IMG)
212+
213+
.PHONY: opm
214+
OPM = ./bin/opm
215+
opm: ## Download opm locally if necessary.
216+
ifeq (,$(wildcard $(OPM)))
217+
ifeq (,$(shell which opm 2>/dev/null))
218+
@{ \
219+
set -e ;\
220+
mkdir -p $(dir $(OPM)) ;\
221+
OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
222+
curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
223+
chmod +x $(OPM) ;\
224+
}
225+
else
226+
OPM = $(shell which opm)
227+
endif
228+
endif
229+
230+
# 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).
231+
# These images MUST exist in a registry and be pull-able.
232+
BUNDLE_IMGS ?= $(BUNDLE_IMG)
233+
234+
# The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
235+
CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
236+
237+
# Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
238+
ifneq ($(origin CATALOG_BASE_IMG), undefined)
239+
FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
240+
endif
241+
242+
# Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
243+
# This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
244+
# https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
245+
.PHONY: catalog-build
246+
catalog-build: opm ## Build a catalog image.
247+
$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
248+
249+
# Push the catalog image.
250+
.PHONY: catalog-push
251+
catalog-push: ## Push a catalog image.
252+
$(MAKE) docker-push IMG=$(CATALOG_IMG)
253+
254+
255+
kind-setup:
256+
kind create cluster --name ${CLUSTER_NAME} || true
257+
$(MAKE) kind-setup-image
258+
259+
kind-setup-image: docker-build
260+
kind load docker-image --name $(CLUSTER_NAME) ${IMG}
261+
262+
.PHONY: test_deps
263+
test_deps:
264+
go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo
265+
go install github.com/onsi/gomega/...
266+
267+
.PHONY: unit-tests
268+
unit-tests: test_deps
269+
ginkgo -r -v --covermode=atomic --coverprofile=coverage.out -p -r ./pkg/...
270+
271+
e2e-tests:
272+
KUBE_VERSION=${KUBE_VERSION} $(ROOT_DIR)/script/test.sh
273+
274+
kind-e2e-tests: kind-setup install undeploy-dev deploy-dev e2e-tests

PROJECT

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

0 commit comments

Comments
 (0)