Skip to content

Commit

Permalink
Merge branch 'release/v0.1.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ppxl authored and cesmarvin committed Aug 24, 2023
2 parents a4bc80e + e72f510 commit 6fa93f2
Show file tree
Hide file tree
Showing 70 changed files with 6,390 additions and 2,780 deletions.
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [v0.1.0] - 2023-08-24
### Added
- [#15] Check if component dependencies are installed and if their version is appropriate
- you can find more information about components in the [operations docs](docs/operations/managing_components_en.md)
- this release adds the ability to requeue CR requests

## [v0.0.3] - 2023-08-21
### Changed
- [#17] Make helmClient more generic to be usable by other components (e.g. "k8s-ces-setup")

## [v0.0.2] - 2023-07-14
### Added
- Add documentation for component operator usage in dev environment
- [#12] Add upgrade of components and self-upgrade of component-operator
- Add documentation for component operator usage in a development environment

### Fixed
- Operator finishes uninstallation steps even if component has been uninstalled already
Expand All @@ -22,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [v0.0.1] - 2023-07-07
### Changed
- [#8] Stabilise the installation process with atomic helm operations and a timeout for the underlying k8s client.

### Added
- [#4] Add Helm chart release process to project
- [#3] Initialize a first version for the `k8s-component-operator`. In contrast to the prior poc status the operator pulls charts from an oci registry.
- [#3] Initialize a first version for the `k8s-component-operator`. In contrast to the prior PoC status the operator pulls charts from an OCI registry.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ RUN make compile-generic
FROM gcr.io/distroless/static:nonroot
LABEL maintainer="hello@cloudogu.com" \
NAME="k8s-component-operator" \
VERSION="0.0.3"
VERSION="0.1.0"

WORKDIR /
COPY --from=builder /workspace/target/k8s-component-operator .
Expand Down
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ node('docker') {

stage('Deploy Manager') {
k3d.kubectl("create secret generic component-operator-helm-registry --from-file=config.json=k8s/emptyHelmRegistry.json --namespace default")
k3d.kubectl("create cm component-operator-helm-repository --from-literal=endpoint=dummy --namespace default")
k3d.kubectl("create cm component-operator-helm-repository --from-literal=endpoint=oci://dummy --namespace default")
k3d.kubectl("apply -f ${sourceDeploymentYaml}")
}

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Set these to the desired values
ARTIFACT_ID=k8s-component-operator
VERSION=0.0.3
VERSION=0.1.0
## Image URL to use all building/pushing image targets
IMAGE_DEV=${K3CES_REGISTRY_URL_PREFIX}/${ARTIFACT_ID}:${VERSION}
IMAGE=cloudogu/${ARTIFACT_ID}:${VERSION}
GOTAG?=1.20.3
MAKEFILES_VERSION=7.10.0
MAKEFILES_VERSION=7.12.0
LINT_VERSION?=v1.52.1
STAGE?=production

Expand Down
2 changes: 1 addition & 1 deletion build/make/k8s-controller.mk
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ K8S_INTEGRATION_TEST_DIR=${TARGET_DIR}/k8s-integration-test
##@ K8s - EcoSystem

.PHONY: build
build: image-import k8s-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem.
build: k8s-helm-apply ## Builds a new version of the dogu and deploys it into the K8s-EcoSystem.

##@ Release

Expand Down
2 changes: 1 addition & 1 deletion build/make/k8s-dogu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Dogu
metadata:
name: NAME
labels:
dogu: NAME
app: ces
spec:
name: NAMESPACE/NAME
version: VERSION
79 changes: 65 additions & 14 deletions build/make/k8s.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ endif

BINARY_YQ = $(UTILITY_BIN_PATH)/yq
BINARY_HELM = $(UTILITY_BIN_PATH)/helm
BINARY_HELM_VERSION?=v3.12.0-dev.1.0.20230817154107-a749b663101d
BINARY_HELM_ADDITIONAL_PUSH_ARGS?=--plain-http
BINARY_HELM_ADDITIONAL_PACK_ARGS?=
BINARY_HELM_ADDITIONAL_UNINST_ARGS?=
BINARY_HELM_ADDITIONAL_UPGR_ARGS?=

# The productive tag of the image
IMAGE ?=
Expand All @@ -22,6 +27,8 @@ K8S_RESOURCE_TEMP_FOLDER ?= $(TARGET_DIR)/make/k8s
K8S_RESOURCE_TEMP_YAML ?= $(K8S_RESOURCE_TEMP_FOLDER)/$(ARTIFACT_ID)_$(VERSION).yaml
K8S_HELM_TARGET ?= $(K8S_RESOURCE_TEMP_FOLDER)/helm
K8S_HELM_RESSOURCES ?= k8s/helm
K8S_HELM_RELEASE_TGZ=${K8S_HELM_TARGET}/${ARTIFACT_ID}-${VERSION}.tgz
K8S_HELM_TARGET_DEP_DIR=charts

##@ K8s - Variables

Expand Down Expand Up @@ -79,9 +86,9 @@ k8s-apply: k8s-generate $(K8S_POST_GENERATE_TARGETS) ## Applies all generated K8
@kubectl apply -f $(K8S_RESOURCE_TEMP_YAML) --namespace=${NAMESPACE}

##@ K8s - Helm general

${K8S_HELM_RESSOURCES}/Chart.yaml: ${BINARY_HELM} ## Creates the Chart.yaml-template if missing
@echo "Create Chart.yaml..."
.PHONY: k8s-helm-init-chart
k8s-helm-init-chart: ${BINARY_HELM} ## Creates a Chart.yaml-template with zero values
@echo "Initialize ${K8S_HELM_RESSOURCES}/Chart.yaml..."
@mkdir -p ${K8S_HELM_RESSOURCES}/tmp/
@${BINARY_HELM} create ${K8S_HELM_RESSOURCES}/tmp/${ARTIFACT_ID}
@cp ${K8S_HELM_RESSOURCES}/tmp/${ARTIFACT_ID}/Chart.yaml ${K8S_HELM_RESSOURCES}/
Expand All @@ -90,17 +97,19 @@ ${K8S_HELM_RESSOURCES}/Chart.yaml: ${BINARY_HELM} ## Creates the Chart.yaml-temp
@sed -i 's/version: .*/version: 0.0.0-replaceme/' ${K8S_HELM_RESSOURCES}/Chart.yaml

.PHONY: k8s-helm-delete
k8s-helm-delete: ${BINARY_HELM} ## Uninstalls the current helm chart.
k8s-helm-delete: ${BINARY_HELM} check-k8s-namespace-env-var ## Uninstalls the current helm chart.
@echo "Uninstall helm chart"
@${BINARY_HELM} uninstall ${ARTIFACT_ID}
@${BINARY_HELM} uninstall ${ARTIFACT_ID} --namespace=${NAMESPACE} ${BINARY_HELM_ADDITIONAL_UNINST_ARGS} || true

.PHONY: k8s-helm-generate-chart
k8s-helm-generate-chart: ${K8S_HELM_RESSOURCES}/Chart.yaml $(K8S_RESOURCE_TEMP_FOLDER) ## Generates the final helm chart.
k8s-helm-generate-chart: ${K8S_HELM_TARGET}/Chart.yaml ## Generates the final helm chart.

${K8S_HELM_TARGET}/Chart.yaml: $(K8S_RESOURCE_TEMP_FOLDER)
@echo "Generate helm chart..."
@rm -drf ${K8S_HELM_TARGET} # delete folder, so Chart.yaml is newly created from template
@rm -drf ${K8S_HELM_TARGET} # delete folder, so the chart is newly created.
@mkdir -p ${K8S_HELM_TARGET}/templates
@cp $(K8S_RESOURCE_TEMP_YAML) ${K8S_HELM_TARGET}/templates
@cp ${K8S_HELM_RESSOURCES}/Chart.yaml ${K8S_HELM_TARGET}
@cp -r ${K8S_HELM_RESSOURCES}/** ${K8S_HELM_TARGET}
@sed -i 's/appVersion: "0.0.0-replaceme"/appVersion: "${VERSION}"/' ${K8S_HELM_TARGET}/Chart.yaml
@sed -i 's/version: 0.0.0-replaceme/version: ${VERSION}/' ${K8S_HELM_TARGET}/Chart.yaml

Expand All @@ -110,23 +119,65 @@ k8s-helm-generate-chart: ${K8S_HELM_RESSOURCES}/Chart.yaml $(K8S_RESOURCE_TEMP_F
k8s-helm-generate: k8s-generate k8s-helm-generate-chart ## Generates the final helm chart with dev-urls.

.PHONY: k8s-helm-apply
k8s-helm-apply: ${BINARY_HELM} image-import k8s-helm-generate $(K8S_POST_GENERATE_TARGETS) ## Generates and installs the helm chart.
k8s-helm-apply: ${BINARY_HELM} check-k8s-namespace-env-var image-import k8s-helm-generate $(K8S_POST_GENERATE_TARGETS) ## Generates and installs the helm chart.
@echo "Apply generated helm chart"
@${BINARY_HELM} upgrade -i ${ARTIFACT_ID} ${K8S_HELM_TARGET}
@${BINARY_HELM} upgrade -i ${ARTIFACT_ID} ${K8S_HELM_TARGET} ${BINARY_HELM_ADDITIONAL_UPGR_ARGS} --namespace ${NAMESPACE}

.PHONY: k8s-helm-reinstall
k8s-helm-reinstall: k8s-helm-delete k8s-helm-apply ## Uninstalls the current helm chart and reinstalls it.

##@ K8s - Helm release targets

.PHONY: k8s-helm-generate-release
k8s-helm-generate-release: $(K8S_PRE_GENERATE_TARGETS) k8s-helm-generate-chart ## Generates the final helm chart with release urls.
k8s-helm-generate-release: ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml ## Generates the final helm chart with release urls.

${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml: $(K8S_PRE_GENERATE_TARGETS) ${K8S_HELM_TARGET}/Chart.yaml
@sed -i "s/'{{ .Namespace }}'/'{{ .Release.Namespace }}'/" ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml

.PHONY: k8s-helm-package-release
k8s-helm-package-release: ${BINARY_HELM} k8s-helm-generate-release $(K8S_POST_GENERATE_TARGETS) ## Generates and packages the helm chart with release urls.
k8s-helm-package-release: ${BINARY_HELM} k8s-helm-delete-existing-tgz ${K8S_HELM_RELEASE_TGZ} k8s-helm-delete-temp-dependencies k8s-helm-remove-dependency-charts ## Generates and packages the helm chart with release urls.

.PHONY: k8s-helm-delete-existing-tgz
k8s-helm-delete-existing-tgz: ## Remove an existing Helm package.
# remove
@rm -f ${K8S_HELM_RELEASE_TGZ}*

${K8S_HELM_RELEASE_TGZ}: ${BINARY_HELM} ${K8S_HELM_TARGET}/templates/$(ARTIFACT_ID)_$(VERSION).yaml k8s-helm-create-temp-dependencies $(K8S_POST_GENERATE_TARGETS) ## Generates and packages the helm chart with release urls.
@echo "Package generated helm chart"
@${BINARY_HELM} package ${K8S_HELM_TARGET} -d ${K8S_HELM_TARGET}
@${BINARY_HELM} package ${K8S_HELM_TARGET} -d ${K8S_HELM_TARGET} ${BINARY_HELM_ADDITIONAL_PACK_ARGS}

.PHONY: k8s-helm-create-temp-dependencies
k8s-helm-create-temp-dependencies: k8s-helm-generate-chart
# we use helm dependencies internally but never use them as "official" dependency because the namespace may differ
# instead we create empty dependencies to satisfy the helm package call and delete the whole directory from the chart.tgz later-on.
@echo "Create helm temp dependencies (if they exist)"
@for dep in `yq -e '.dependencies[].name // ""' ${K8S_HELM_TARGET}/Chart.yaml`; do \
mkdir -p ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}/$${dep} ; \
sed "s|replaceme|$${dep}|g" $(BUILD_DIR)/make/k8s-helm-temp-chart.yaml > ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}/$${dep}/Chart.yaml ; \
done

.PHONY: k8s-helm-delete-temp-dependencies
k8s-helm-delete-temp-dependencies:
@echo "Delete helm temp dependencies (if they exist)"
@rm -rf ${K8S_HELM_TARGET}/${K8S_HELM_TARGET_DEP_DIR}

.PHONY: k8s-helm-remove-dependency-charts
k8s-helm-remove-dependency-charts: ${K8S_HELM_RELEASE_TGZ}
# deleting dirs from a .tgz is hard so un-tar,remove dir,re-tar is a good alternative
# but only if any dependency directory actually exists
@if tar -tf ${K8S_HELM_RELEASE_TGZ} ${ARTIFACT_ID}/${K8S_HELM_TARGET_DEP_DIR} > /dev/null 2>&1; then \
echo "Remove dependency files from ${K8S_HELM_RELEASE_TGZ}" ; \
gzip --to-stdout --decompress ${K8S_HELM_RELEASE_TGZ} | \
tar --to-stdout --delete "${ARTIFACT_ID}/${K8S_HELM_TARGET_DEP_DIR}" -f - | \
gzip > ${K8S_HELM_RELEASE_TGZ}.temp ; \
rm ${K8S_HELM_RELEASE_TGZ} && mv ${K8S_HELM_RELEASE_TGZ}.temp ${K8S_HELM_RELEASE_TGZ} ; \
fi

.PHONY: chart-import
chart-import: check-all-vars check-k8s-artifact-id k8s-helm-generate-chart k8s-helm-package-release image-import ## Imports the currently available image into the cluster-local registry.
@echo "Import ${K8S_HELM_RELEASE_TGZ} into K8s cluster ${K3CES_REGISTRY_URL_PREFIX}..."
@${BINARY_HELM} push ${K8S_HELM_RELEASE_TGZ} oci://${K3CES_REGISTRY_URL_PREFIX}/k8s ${BINARY_HELM_ADDITIONAL_PUSH_ARGS}
@echo "Done."

##@ K8s - Docker

Expand Down Expand Up @@ -172,4 +223,4 @@ ${BINARY_YQ}: $(UTILITY_BIN_PATH) ## Download yq locally if necessary.
$(call go-get-tool,$(BINARY_YQ),github.com/mikefarah/yq/v4@v4.25.1)

${BINARY_HELM}: $(UTILITY_BIN_PATH) ## Download helm locally if necessary.
$(call go-get-tool,$(BINARY_HELM),helm.sh/helm/v3/cmd/helm@latest)
$(call go-get-tool,$(BINARY_HELM),helm.sh/helm/v3/cmd/helm@${BINARY_HELM_VERSION})
6 changes: 6 additions & 0 deletions config/crd/bases/k8s.cloudogu.com_components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.11.3
creationTimestamp: null
labels:
app: ces
app.kubernetes.io/name: k8s-component-operator
Expand Down Expand Up @@ -50,6 +51,11 @@ spec:
status:
description: ComponentStatus defines the observed state of a Component.
properties:
requeueTimeNanos:
description: RequeueTimeNanos contains the time in nanoseconds to
wait until the next requeue.
format: int64
type: integer
status:
description: Status represents the state of the component in the ecosystem.
type: string
Expand Down
2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ kind: Kustomization
images:
- name: controller
newName: cloudogu/k8s-component-operator
newTag: 0.0.3
newTag: 0.1.0
2 changes: 0 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ spec:
port: 8081
initialDelaySeconds: 5
periodSeconds: 10
# TODO(user): Configure the resources accordingly based on the project requirements.
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
resources:
limits:
cpu: 500m
Expand Down
3 changes: 3 additions & 0 deletions config/samples/component-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ apiVersion: k8s.cloudogu.com/v1
kind: Component
metadata:
name: k8s-component-operator
labels:
app: ces
app.kubernetes.io/name: k8s-component-operator
spec:
name: k8s-component-operator
namespace: testing
Expand Down
4 changes: 2 additions & 2 deletions config/samples/dogu-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ metadata:
name: k8s-dogu-operator
spec:
name: k8s-dogu-operator
namespace: testing
version: 0.2.0
namespace: k8s
version: 0.35.0
68 changes: 68 additions & 0 deletions docs/development/developing_the_operator_de.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Komponenten-Operator und Komponenten entwickeln

Dieses Dokument beschreibt sowohl, wie man den Komponenten-Operator entwickelt als auch Komponenten-spezifische Eigenheiten.

## Vorbereitungen

### Helm-Repository konfigurieren

- Die Datei `.env` aus dem Template `.env.template` erstellen
- Wichtig sind die Variablen
- `HELM_REPO_ENDPOINT` (bspw. https://registry.cloudogu.com)
- `HELM_REPO_USERNAME`
- `HELM_REPO_PASSWORD`
- `NAMESPACE`
- Credentials im Cluster ablegen: `make helm-repo-config`

### Den Komponenten-Operator lokal debuggen

1. Befolgen Sie die Installationsanweisungen von k8s-ecosystem
2. Öffnen Sie die Datei `.env.template` und folgen Sie den Anweisungen um eine
Umgebungsvariablendatei mit persönlichen Informationen anzulegen
3. Löschen Sie eventuelle Komponenten-Operator-Deployments im Cluster, um Parallelisierungsfehler auszuschließen
- `kubectl -n ecosystem delete deployment k8s-component-operator`
4. Legen Sie eine neue Debug-Konfiguration (z. B. in IntelliJ) ans, um den Operator lokal auszuführen
- mit diesen Umgebungsvariablen:
- STAGE=production;NAMESPACE=ecosystem;KUBECONFIG=/pfad/zur/kubeconfig/.kube/k3ces.local
5. Breakpoints setzen und ggf. ein Komponenten-CR auf den Cluster anwenden

### Komponenten-Operator installieren

- Operator bauen und im Cluster installieren: `make k8s-helm-apply`

### Komponente für Test vorbereiten

Am Beispiel von `k8s-dogu-operator`

1. Repository der Komponente öffnen
2. Ggf. im Verzeichnis `k8s/helm` ein `Chart.yaml` mit `make k8s-helm-init-chart` anlegen
3. Helm-Package erstellen: `make k8s-helm-package-release`
- generiert ein Paket nach dem Schema KOMPONENTENNAME-VERSION.tgz
4. ggf. alle nötigen Nicht-Test-Komponenten [installieren](../operations/managing_components_de.md#komponenten-installieren-oder-aktualisieren)
`kubectl -n ecosystem apply -f yourComponentCR.yaml`
5. Test-Komponente pushen:
- `make chart-import`
6. die ConfigMap `component-operator-helm-repository` auf die cluster-lokale Registry richten
- `kubectl -n ecosystem patch configmap component-operator-helm-repository -p '{"data": {"endpoint": "oci://k3ces.local:30099","plainHttp": "true"}}'`
7. YAML der Test-Komponente überprüfen und [installieren](../operations/managing_components_de.md#komponenten-installieren-oder-aktualisieren)
`kubectl -n ecosystem apply -f k8s-dogu-operator.yaml`

## Abhängigkeiten in Komponenten darstellen

Komponenten müssen nicht unbedingt für sich alleine stehen, sondern können auch andere Komponenten erfordern. Dies wird als Abhängigkeit im Helm-Chart definiert:

```yaml
apiVersion: v2
name: k8s-dogu-operator
...
dependencies:
- name: k8s/k8s-dogu-operator
version: 3.*.*
condition: false
```
Abhängigkeitsversionen sollten so gestaltet werden, dass sie nicht auf eine einzige Version fixiert werden, sondern unterschiedliche Versionsbereiche abdecken. Dies ermöglicht den Betrieb von Komponenten, selbst wenn Komponentenversionen mit kleineren Änderungen oder Fehlerbehebungen ausgebracht wurden.
Die Bibliothek [Masterminds/semver](https://github.com/Masterminds/semver#checking-version-constraints) beschreibt genauer, welche Versionseinschränkungen möglich sind.
Da wir die Abhängigkeitsdeklaration im Helm-Chart nur nutzen, um Abhängigkeiten für den Komponenten-Operator darzustellen, muss das Feld `.dependencies.[].condition` zwingend auf `false` gesetzt werden. Würde dieses Feld `true` sein, würde Helm die Abhängigkeit automatisch installieren und der Komponenten-Operator würde in seiner eigenen Tätigkeit gestört werden.
Loading

0 comments on commit 6fa93f2

Please sign in to comment.