Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create command for updating auto-generated docs and helm resources for CRD structs #2897

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/scripts/lifecycle-operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Keptn script for endtasks
#
# This script copies the crds from lifecycle-operator(lifecycle-operator/config/crd/bases) to the directory's helm chart(lifecycle-operator/chart/templates)
# It also appends the respective annotations

echo "copying manifests"

dir="lifecycle-operator/config/crd/bases"
helm_dir="lifecycle-operator/chart/templates"

configElements=(keptnapps keptnappcontext keptnappcreationrequest keptnappversion keptnconfig keptnevaluations keptnevaluationdefinition keptntasks keptntaskdefinition keptnworkloads keptnworkloadversion)

n=10
for file in "$dir"/* ; do
# Extract the basename of the file
configCrds=$(basename "$file" .yaml)

# Loop through each element in the pickElement array
for element in "${configElements[@]}"; do

# Check if the element is present in the filename
if echo "$configCrds" | grep -q "$element" && [[ $n > -1 ]] ; then
echo "Match found: $element in $configCrds"

# Loop through files in the helm directory
for crds in "$helm_dir"/* ; do
# Extract the basename of the helm file
helm_filename=$(basename "$crds" .yaml)

# Check if the element is present in the helm filename
if [[ $helm_filename == k* ]] && echo "$helm_filename" | grep -q "$element" && [[ $n > -1 ]] ; then

echo "Match found: $element in $helm_filename"
truncate -s 0 "$crds"
((n=n-1))
# Concatenate the content of the file into the helm file
cat "$file" >> "$crds"
break
fi
done
fi
done
done

for file in "$helm_dir"/*; do
filename=$(basename "$file" .yaml)
if [[ $filename == k* ]] ; then
sed -i '/controller-gen.kubebuilder.io\/version: v0.14.0/a\
{{- with .Values.global.caInjectionAnnotations }}\
{{- toYaml . | nindent 4 }}\
{{- end }}\
{{- include "common.annotations" ( dict "context" . ) }}\
labels:\
app.kubernetes.io/part-of: keptn\
crdGroup: lifecycle.keptn.sh\
keptn.sh/inject-cert: "true"\
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}' "$helm_dir/$filename.yaml"
fi
if [[ "$filename" == "keptnappcontext-crd" ]] ; then
sed -i "s|{{- with .Values.global.caInjectionAnnotations }}|cert-manager.io/inject-ca-from: '{{ .Release.Namespace }}/keptn-certs'|g" "$helm_dir/$filename.yaml"
sed -i "/{{- end }}/d" "$helm_dir/$filename.yaml"
sed -i "/{{- toYaml \. /d" "$helm_dir/$filename.yaml"
fi
if [[ "$filename" == "keptnapps-crd" || "$filename" == "keptnappversion-crd" ]] ; then
sed -i "0,/spec/{/spec/a\\
conversion:\\
strategy: Webhook\\
webhook:\\
clientConfig:\\
service:\\
name: 'lifecycle-webhook-service'\\
namespace: '{{ .Release.Namespace }}'\\
path: \/convert\\
conversionReviewVersions:\\
- v1
}" "$helm_dir/$filename.yaml"
fi
done
77 changes: 77 additions & 0 deletions .github/scripts/metrics-operator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash

# Keptn script for endtasks
#
# This script copies the crds from lifecycle-operator(lifecycle-operator/config/crd/bases) to the directory's helm chart(lifecycle-operator/chart/templates)
# It also appends the respective annotations

echo "copying manifests"

dir="metrics-operator/config/crd/bases"
helm_dir="metrics-operator/chart/templates"

configElements=(analysisdefinition analysisvaluetemplate keptnmetricsprovider)

truncate -s 0 $helm_dir/keptnmetric-crd.yaml
cat $dir/metrics.keptn.sh_keptnmetrics.yaml >> $helm_dir/keptnmetric-crd.yaml

truncate -s 0 $helm_dir/analysis-crd.yaml
cat $dir/metrics.keptn.sh_analyses.yaml >> $helm_dir/analysis-crd.yaml

n=3
# Loop through each file in the directory
for file in "$dir"/* ; do
# Extract the basename of the file
configCrds=$(basename "$file" .yaml)
echo "Processing file: $filename"

# Loop through each element in the pickElement array
for element in "${configElements[@]}"; do
echo "Checking element: $element"

# Check if the element is present in the filename
if echo "$configCrds" | grep -q "$element" && [[ $n > -1 ]] ; then
echo "Match found: $element in $filename"

# Loop through files in the helm directory
for crds in "$helm_dir"/* ; do
# Extract the basename of the helm file
helm_filename=$(basename "$crds" .yaml)

echo "Checking helm file: $helm_filename"

# Check if the element is present in the helm filename
if echo "$helm_filename" | grep -q "$element" && [[ $n > -1 ]] ; then

echo "Match found: $element in $helm_filename"
truncate -s 0 "$crds"
((n=n-1))
# Concatenate the content of the file into the helm file
cat "$file" >> "$crds"
break
fi
done
fi
done
done

for file in "$helm_dir"/*; do
filename=$(basename "$file" .yaml)
if [[ $filename == k* || $filename == a* ]]; then
sed -i '/controller-gen.kubebuilder.io\/version: v0.14.0/a\
{{- with .Values.global.caInjectionAnnotations }}\
{{- toYaml . | nindent 4 }}\
{{- end }}\
{{- include "common.annotations" ( dict "context" . ) }}\
labels:\
app.kubernetes.io/part-of: keptn\
crdGroup: metrics.keptn.sh\
keptn.sh/inject-cert: "true"\
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}' "$helm_dir/$filename.yaml"
fi
if [[ $filename == "analysis-crd" ]] ; then
echo "found"
sed -i "/{{- end }}/a\\
cert-manager.io/inject-ca-from: '{{ .Release.Namespace }}\/keptn-certs'" "$helm_dir/$filename.yaml"
fi
done
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ install-prometheus:
kubectl wait --for=condition=available deployment/kube-state-metrics -n monitoring --timeout=120s
kubectl wait pod/prometheus-k8s-0 --for=condition=ready --timeout=120s -n monitoring

# Run resource for sub-directories
.PHONY: lifecycle-operator-resource
lifecycle-operator-resource:
$(MAKE) -C lifecycle-operator resource

.PHONY: metrics-operator-resource
metrics-operator-resource:
$(MAKE) -C metrics-operator resource

.PHONY: metrics-operator-test
metrics-operator-test:
$(MAKE) -C metrics-operator test
Expand Down
8 changes: 8 additions & 0 deletions lifecycle-operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="{./apis/..., ./controllers/..., ./webhooks/...}"

# Command for end tasks to make generate, make manifests, copy crds from config to helm templates
.PHONY: resource
resource: manifests generate
kustomize build config/crd
./.github/scripts/lifecycle-operator.sh
./.github/scripts/generate-crd-docs/generate-crd-docs.sh
./.github/scripts/generate-helm-docs.sh

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand Down
5 changes: 3 additions & 2 deletions lifecycle-operator/chart/templates/keptnappcontext-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnappcontexts.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
cert-manager.io/inject-ca-from: '{{ .Release.Namespace }}/keptn-certs'
{{- include "common.annotations" ( dict "context" . ) }}
{{- include "common.annotations" ( dict "context" . ) }}
labels:
app.kubernetes.io/part-of: keptn
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnappcontexts.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnappcreationrequests.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
Expand All @@ -13,6 +13,7 @@ metadata:
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnappcreationrequests.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnapps.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
{{- with .Values.global.caInjectionAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "common.annotations" (dict "context" .) }}
{{- include "common.annotations" ( dict "context" . ) }}
labels:
app.kubernetes.io/part-of: keptn
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnapps.lifecycle.keptn.sh
spec:
conversion:
strategy: Webhook
Expand Down
5 changes: 3 additions & 2 deletions lifecycle-operator/chart/templates/keptnappversion-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnappversions.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
{{- with .Values.global.caInjectionAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "common.annotations" ( dict "context" . ) }}
Expand All @@ -13,6 +13,7 @@ metadata:
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnappversions.lifecycle.keptn.sh
spec:
conversion:
strategy: Webhook
Expand Down
3 changes: 2 additions & 1 deletion lifecycle-operator/chart/templates/keptnconfig-crd.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnconfigs.options.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
Expand All @@ -13,6 +13,7 @@ metadata:
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnconfigs.options.keptn.sh
spec:
group: options.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnevaluationdefinitions.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
Expand All @@ -13,6 +13,7 @@ metadata:
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnevaluationdefinitions.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnevaluations.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
Expand All @@ -13,6 +13,7 @@ metadata:
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnevaluations.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptntaskdefinitions.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
{{- with .Values.global.caInjectionAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "common.annotations" ( dict "context" . ) }}
{{- include "common.annotations" ( dict "context" . ) }}
labels:
app.kubernetes.io/part-of: keptn
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptntaskdefinitions.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptntasks.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "common.annotations" ( dict "context" . ) }}
{{- include "common.annotations" ( dict "context" . ) }}
labels:
app.kubernetes.io/part-of: keptn
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptntasks.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: keptnworkloads.lifecycle.keptn.sh
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
{{- with .Values.global.caInjectionAnnotations }}
{{- with .Values.global.caInjectionAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- include "common.annotations" ( dict "context" . ) }}
{{- include "common.annotations" ( dict "context" . ) }}
labels:
app.kubernetes.io/part-of: keptn
crdGroup: lifecycle.keptn.sh
keptn.sh/inject-cert: "true"
{{- include "common.labels.standard" ( dict "context" . ) | nindent 4 }}
name: keptnworkloads.lifecycle.keptn.sh
spec:
group: lifecycle.keptn.sh
names:
Expand Down
Loading
Loading