Skip to content

Commit 432c50b

Browse files
mendrugoryprometherion
authored andcommitted
feat: releasing kamaji
1 parent 7089412 commit 432c50b

File tree

106 files changed

+12738
-2
lines changed

Some content is hidden

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

106 files changed

+12738
-2
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
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/

.github/workflows/ci.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
pull_request:
7+
branches: [ "*" ]
8+
9+
jobs:
10+
golangci:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Run golangci-lint
16+
uses: golangci/[email protected]
17+
with:
18+
version: v1.45.2
19+
only-new-issues: false
20+
args: --timeout 5m --config .golangci.yml
21+
diff:
22+
name: diff
23+
runs-on: ubuntu-18.04
24+
steps:
25+
- uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0
28+
- uses: actions/setup-go@v2
29+
with:
30+
go-version: '1.17'
31+
- run: make yaml-installation-file
32+
- name: Checking if YAML installer file is not aligned
33+
run: if [[ $(git diff | wc -l) -gt 0 ]]; then echo ">>> Untracked generated files have not been committed" && git --no-pager diff && exit 1; fi
34+
- name: Checking if YAML installer generated untracked files
35+
run: test -z "$(git ls-files --others --exclude-standard 2> /dev/null)"
36+
- name: Checking if source code is not formatted
37+
run: test -z "$(git diff 2> /dev/null)"

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ bin
2727
**/*.kubeconfig
2828
**/*.crt
2929
**/*.key
30+
**/*.pem
31+
**/*.csr
3032
.DS_Store
31-

.golangci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
linters-settings:
2+
gci:
3+
sections:
4+
- standard
5+
- default
6+
- prefix(github.com/clastix/kamaji)
7+
8+
linters:
9+
disable:
10+
- wrapcheck
11+
- gomnd
12+
- scopelint
13+
- golint
14+
- interfacer
15+
- maligned
16+
- varnamelen
17+
- testpackage
18+
- tagliatelle
19+
- paralleltest
20+
- ireturn
21+
- goerr113
22+
- gochecknoglobals
23+
- exhaustivestruct
24+
- wsl
25+
- exhaustive
26+
- lll
27+
- gosec
28+
- gomoddirectives
29+
- godox
30+
- gochecknoinits
31+
- funlen
32+
- dupl
33+
- maintidx
34+
- cyclop
35+
enable-all: true

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Build the manager binary
2+
FROM golang:1.17 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+
COPY internal/ internal/
17+
18+
# Build
19+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -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 /workspace/manager .
26+
COPY ./kamaji.yaml .
27+
USER 65532:65532
28+
29+
ENTRYPOINT ["/manager"]

Makefile

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

PROJECT

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

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ A. Lighter Multi-Tenancy solutions, like Capsule shares the Kubernetes control p
119119

120120
Q. So I need a costly cloud infrastructure to try Kamaji?
121121

122-
A. No, it is possible to try Kamaji on your laptop with [KinD](./deploy/kind/README.md). We're porting it also on Canonical MicroK8s as an add-on, _tbd_.
122+
A. No, it is possible to try Kamaji on your laptop with [KinD](./deploy/kind/README.md). We're porting it also on Canonical MicroK8s as an add-on, _tbd_.

api/v1alpha1/groupversion_info.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2022 Clastix Labs
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// Package v1alpha1 contains API Schema definitions for the kamaji v1alpha1 API group
5+
//+kubebuilder:object:generate=true
6+
//+groupName=kamaji.clastix.io
7+
package v1alpha1
8+
9+
import (
10+
"k8s.io/apimachinery/pkg/runtime/schema"
11+
"sigs.k8s.io/controller-runtime/pkg/scheme"
12+
)
13+
14+
var (
15+
// GroupVersion is group version used to register these objects.
16+
GroupVersion = schema.GroupVersion{Group: "kamaji.clastix.io", Version: "v1alpha1"}
17+
18+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
19+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
20+
21+
// AddToScheme adds the types in this group-version to the given scheme.
22+
AddToScheme = SchemeBuilder.AddToScheme
23+
)

0 commit comments

Comments
 (0)