Skip to content

Commit

Permalink
feat: added the metrics-operator (#917)
Browse files Browse the repository at this point in the history
Co-authored-by: Florian Bacher <florian.bacher@dynatrace.com>
Co-authored-by: odubajDT <93584209+odubajDT@users.noreply.github.com>
Co-authored-by: Giovanni Liva <giovanni.liva@dynatrace.com>
Co-authored-by: RealAnna <89971034+RealAnna@users.noreply.github.com>
Co-authored-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
6 people committed Mar 1, 2023
1 parent 39a002d commit 91e57ca
Show file tree
Hide file tree
Showing 370 changed files with 18,751 additions and 2,770 deletions.
15 changes: 12 additions & 3 deletions .github/actions/deploy-klt-on-cluster/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ runs:
sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' ~/download/artifacts/klt-cert-manager-manifest-test/release.yaml
kubectl apply -f ~/download/artifacts/klt-cert-manager-manifest-test
kubectl rollout status deployment klt-cert-manager -n keptn-lifecycle-toolkit-system -w
sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' ~/download/artifacts/metrics-operator-manifest-test/release.yaml
kubectl apply -f ~/download/artifacts/metrics-operator-manifest-test
kubectl rollout status deployment metrics-operator-controller -n keptn-lifecycle-toolkit-system -w
sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' ~/download/artifacts/scheduler-manifest-test/release.yaml
kubectl apply -f ~/download/artifacts/scheduler-manifest-test
Expand All @@ -82,6 +86,11 @@ runs:
run: |
echo "Installing KLT using helm"
helm version
kubectl delete crds --all -n keptn-lifecycle-toolkit-system
helm install -n keptn-lifecycle-toolkit-system --create-namespace toolkit ~/download/artifacts/keptn-lifecycle-toolkit.tgz --set deployment.imagePullPolicy=Never --debug --wait --timeout 1m
kubectl get crds keptnappversions.lifecycle.keptn.sh -o yaml
helm install -n keptn-lifecycle-toolkit-system --create-namespace toolkit ~/download/artifacts/keptn-lifecycle-toolkit.tgz \
--set keptnScheduler.keptnScheduler.imagePullPolicy=Never \
--set klcControllerManager.manager.imagePullPolicy=Never \
--set metricsOperatorController.manager.imagePullPolicy=Never \
--set klcControllerManager.manager.env.functionRunnerImage=localhost:5000/keptn/functions-runtime:${{ inputs.functions_runtime_tag }} \
--set kltCertManager.manager.imagePullPolicy=Never \
--set fullnameOverride="" \
--debug --wait --timeout 1m
2 changes: 2 additions & 0 deletions .github/scripts/create-reports-full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ for namespace in $(kubectl get namespaces -o jsonpath='{.items[*].metadata.name}
createResourceReport "$logsDir/$namespace" "$namespace" "KeptnTask" false
createResourceReport "$logsDir/$namespace" "$namespace" "KeptnWorkload" false
createResourceReport "$logsDir/$namespace" "$namespace" "KeptnWorkloadInstance" false
createResourceReport "$logsDir/$namespace" "$namespace" "KeptnMetric" false
createResourceReport "$logsDir/$namespace" "$namespace" "KeptnMetricsProvider" false

done
75 changes: 75 additions & 0 deletions .github/scripts/keptnevaluationprovider_migrator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

getNamespaces() {
out=$(kubectl get ns -o name)
for n in $out
do
nn=${n#"namespace/"}
namespaces+=("$nn")
done
}

getProvidersOfNamespace() {
out=$(kubectl get keptnevaluationproviders -o name -n "$1")
for n in $out
do
nn=${n#"keptnevaluationprovider.lifecycle.keptn.sh/"}
providers+=("$nn -n $1")
done
}

echo -e "------------------------------\n"
echo -e "Migrating manifests.\n"
echo -e "------------------------------\n"

declare -a namespaces
declare -a providers

DATE=$(date +%s)
MANIFESTS_FILE="manifests-$DATE.yaml"

getNamespaces

for n in "${namespaces[@]}"
do
getProvidersOfNamespace "$n"
done

for n in "${providers[@]}"
do
echo "---" >> $MANIFESTS_FILE
kubectl get keptnevaluationproviders $n -oyaml >> $MANIFESTS_FILE
done

sed -i 's#lifecycle\.keptn\.sh/v1alpha2#metrics\.keptn\.sh/v1alpha2#g' $MANIFESTS_FILE
sed -i 's/KeptnEvaluationProvider/KeptnMetricsProvider/g' $MANIFESTS_FILE

echo -e "------------------------------\n"
echo -e "Manifests migrated successfully.\n"
echo -e "To review the newly created manifests, check ./$MANIFESTS_FILE file.\n"
echo -e "------------------------------\n"

read -p "Do you want to apply the newly created KeptnMetricsProvider resources? [y/N]" -n 1 -r
echo -e "\n"
if [[ $REPLY =~ ^[Yy]$ ]]
then
kubectl apply -f $MANIFESTS_FILE
echo -e "\nManifests applied.\n"
else
echo -e "Manifests not applied.\n"
fi

echo -e "------------------------------\n"

read -p "Do you want to delete the old KeptnEvaluationProvider resources? [y/N]" -n 1 -r
echo -e "\n"
if [[ $REPLY =~ ^[Yy]$ ]]
then
for n in "${providers[@]}"
do
kubectl delete keptnevaluationproviders $n
done
echo -e "\nResources deleted.\n"
else
echo -e "Resources not deleted.\n"
fi
10 changes: 8 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "metrics-operator"
folder: "metrics-operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "klt-cert-manager"
Expand Down Expand Up @@ -111,6 +113,8 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "metrics-operator"
folder: "metrics-operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
Expand Down Expand Up @@ -159,7 +163,7 @@ jobs:
path: /tmp/${{ matrix.config.name }}-image.tar

- name: Install controller-gen
if: matrix.config.name == 'keptn-lifecycle-operator'
if: matrix.config.name == 'keptn-lifecycle-operator' || matrix.config.name == 'metrics-operator'
working-directory: ./${{ matrix.config.folder }}
run: make controller-gen

Expand Down Expand Up @@ -224,6 +228,8 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "metrics-operator"
folder: "metrics-operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
Expand Down Expand Up @@ -274,7 +280,7 @@ jobs:
cache-to: type=gha,scope=${{ github.ref_name }}-${{ matrix.config.name }}

- name: Install controller-gen
if: matrix.config.name == 'keptn-lifecycle-operator' || matrix.config.name == 'klt-cert-manager'
if: matrix.config.name == 'keptn-lifecycle-operator' || matrix.config.name == 'klt-cert-manager' || matrix.config.name == 'metrics-operator'
working-directory: ./${{ matrix.config.folder }}
run: make controller-gen

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "metrics-operator"
folder: "metrics-operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "klt-cert-manager"
Expand Down
20 changes: 15 additions & 5 deletions .github/workflows/helm-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "metrics-operator"
folder: "metrics-operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
Expand Down Expand Up @@ -122,26 +124,34 @@ jobs:
runs-on: ubuntu-22.04
env:
RELEASE_REGISTRY: "localhost:5000/keptn"
DATETIME: ${{ needs.prepare_ci_run.outputs.DATETIME }}
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Generate helm charts
run: |
make helm-package RELEASE_REGISTRY=${{ env.RELEASE_REGISTRY }} TAG=dev-${{ needs.prepare_ci_run.outputs.DATETIME }}
sed -i 's/imagePullPolicy: Always/imagePullPolicy: Never/g' ./helm/chart/templates/rendered.yaml
sed -i 's/ghcr.keptn.sh\/keptn\/functions-runtime:.*/localhost:5000\/keptn\/functions-runtime:dev-${{ needs.prepare_ci_run.outputs.DATETIME }}/g' ./helm/chart/templates/rendered.yaml
rm -r ./helm/chart/charts
make helm-package RELEASE_REGISTRY=${{ env.RELEASE_REGISTRY }} TAG=dev-${{ env.DATETIME }}
for file in $(find ./helm/chart/templates -type f -name "*.yaml");
do
sed -i 's/{{ include "chart.fullname" . }}-//g' "$file"
done
- name: Upload KLT helm charts archive
uses: actions/upload-artifact@v3
with:
name: keptn-lifecycle-toolkit.tgz
path: ./helm/chart/*

- name: Upload generated helm yaml
uses: actions/upload-artifact@v3
with:
name: helmchart.yaml
path: ./helmchart.yaml

integration_tests:
name: Integration Tests
needs: [ build_helm_chart ]
needs: [ prepare_ci_run, build_helm_chart ]
with:
functions_runtime_tag: dev-${{ needs.prepare_ci_run.outputs.DATETIME }}
helm-install: true
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ jobs:
config:
- name: "keptn-lifecycle-operator"
folder: "operator/"
- name: "metrics-operator"
folder: "metrics-operator/"
- name: "scheduler"
folder: "scheduler/"
- name: "functions-runtime"
Expand Down Expand Up @@ -162,9 +164,12 @@ jobs:
make controller-gen release-manifests
cd ../klt-cert-manager
make controller-gen release-manifests
cd ../metrics-operator
make controller-gen release-manifests
cd ..
echo "---" >> operator/config/rendered/release.yaml
echo "---" >> scheduler/config/rendered/release.yaml
echo "---" >> klt-cert-manager/config/rendered/release.yaml
cat >> namespace.yaml << EOF
---
apiVersion: v1
Expand All @@ -173,7 +178,7 @@ jobs:
name: keptn-lifecycle-toolkit-system
---
EOF
cat namespace.yaml operator/config/rendered/release.yaml scheduler/config/rendered/release.yaml klt-cert-manager/config/rendered/release.yaml > manifest.yaml
cat operator/config/rendered/release.yaml scheduler/config/rendered/release.yaml klt-cert-manager/config/rendered/release.yaml metrics-operator/config/rendered/release.yaml > manifest.yaml
- name: Attach release assets
uses: softprops/action-gh-release@v1
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/security-scans.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,16 @@ jobs:
cd operator/config/default
sed -i 's/\- ..\/crd//' kustomization.yaml && kustomize build ./ > /tmp/operator-manifest.yaml
cd ../crd && kustomize build ./ > /tmp/crds.yaml
cd ../../../metrics-operator/config/default
sed -i 's/\- ..\/crd//' kustomization.yaml && kustomize build ./ > /tmp/metrics-operator-manifest.yaml
echo "---" >> /tmp/crds.yaml
cd ../crd && kustomize build ./ >> /tmp/crds.yaml
cd ../../../scheduler/manifests/install && kustomize build ./ > /tmp/scheduler-manifest.yaml
curl -s https://raw.githubusercontent.com/yannh/kubeconform/${{ matrix.version }}/scripts/openapi2jsonschema.py > /tmp/openapi2jsonschema.py
mkdir -p /tmp/schema && cd /tmp/schema
python3 ../openapi2jsonschema.py ../crds.yaml
cd .. && echo "---" >> operator-manifest.yaml && cat operator-manifest.yaml scheduler-manifest.yaml > manifest.yaml
cd .. && echo "---" >> operator-manifest.yaml && echo "---" >> scheduler-manifest.yaml && cat operator-manifest.yaml scheduler-manifest.yaml metrics-operator-manifest.yaml > manifest.yaml
kubeconform -schema-location default -schema-location './schema/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json' -schema-location 'https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/cert-manager.io/{{.ResourceKind}}_{{.ResourceAPIVersion}}.json' -summary manifest.yaml
- name: Kubescape Scan
Expand All @@ -176,6 +180,7 @@ jobs:
image:
- "functions-runtime"
- "keptn-lifecycle-operator"
- "metrics-operator"
- "scheduler"
- "klt-cert-manager"
steps:
Expand All @@ -201,6 +206,7 @@ jobs:
matrix:
artifact:
- "operator"
- "metrics-operator"
- "scheduler"
- "klt-cert-manager"

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/validate-semantic-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
scheduler
operator
cert-manager
metrics-operator
functions-runtime
dashboards
# Configure that a scope must always be provided.
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ kubeconfig
manifests/
/scheduler/config/rendered/release.yaml
/operator/config/rendered/release.yaml
/metrics-operator/config/rendered/release.yaml
/klt-cert-manager/config/rendered/release.yaml
# macOS
.DS_Store
Expand All @@ -41,3 +42,6 @@ manifests/

# Helm readme generator project
readme-generator-for-helm/
/out.yaml
/test.yaml
/helmchart.yaml
37 changes: 21 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ $(LOCALBIN):

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
HELMIFY ?= $(LOCALBIN)/helmify

.PHONY: helmify
helmify: $(HELMIFY) ## Download helmify locally if necessary.
$(HELMIFY): $(LOCALBIN)
test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/keptn/helmify/cmd/helmify@b1da2bb756ec4328bac7645da037a6fb4e6f30cf

.PHONY: integration-test #these tests should run on a real cluster!
integration-test:
Expand All @@ -50,33 +55,25 @@ $(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

.PHONY: release-helm-manifests
release-helm-manifests:
release-helm-manifests: helmify
echo "building helm overlay"
kustomize build ./helm/overlay > ./helm/chart/templates/rendered.yaml
kustomize build ./helm/overlay > helmchart.yaml
cat helmchart.yaml | $(HELMIFY) -probes=true -image-pull-secrets=true -vv helm/chart

.PHONY: helm-package
helm-package: clean-helm-charts build-release-manifests release-helm-manifests clean-helm-yaml
cd ./helm && helm package ./chart
cd ./helm && mv keptn-lifecycle-toolkit-*.tgz ./chart/charts
helm-package: build-release-manifests release-helm-manifests

.PHONY: clean-helm-charts
clean-helm-charts:
@if test -f "/helm/chart/charts/keptn-lifecycle-toolkit-*.tgz" ; then \
rm "./helm/chart/charts/keptn-lifecycle-toolkit-*.tgz"; \
fi

.PHONY: clean-helm-yaml
clean-helm-yaml:
sed -i "s/'{{/{{/g" ./helm/chart/templates/rendered.yaml
sed -i "s/}}'/}}/g" ./helm/chart/templates/rendered.yaml

.PHONY: build-release-manifests
build-release-manifests:
$(MAKE) -C operator generate
$(MAKE) -C klt-cert-manager generate
$(MAKE) -C metrics-operator generate

$(MAKE) -C operator release-manifests RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG) ARCH=$(ARCH)
$(MAKE) -C scheduler release-manifests RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG) ARCH=$(ARCH)
$(MAKE) -C klt-cert-manager release-manifests RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG) ARCH=$(ARCH)
$(MAKE) -C metrics-operator release-manifests RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG) ARCH=$(ARCH)

.PHONY: build-deploy-operator
build-deploy-operator:
Expand All @@ -86,6 +83,14 @@ build-deploy-operator:

kubectl apply -f operator/config/rendered/release.yaml

.PHONY: build-deploy-metrics-operator
build-deploy-metrics-operator:
$(MAKE) -C metrics-operator release-local.$(ARCH) RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG)
$(MAKE) -C metrics-operator push-local RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG)
$(MAKE) -C metrics-operator release-manifests RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG) ARCH=$(ARCH)

kubectl apply -f metrics-operator/config/rendered/release.yaml

.PHONY: build-deploy-scheduler
build-deploy-scheduler:
$(MAKE) -C scheduler release-local.$(ARCH) RELEASE_REGISTRY=$(RELEASE_REGISTRY) TAG=$(TAG)
Expand All @@ -103,7 +108,7 @@ build-deploy-certmanager:
kubectl apply -f klt-cert-manager/config/rendered/release.yaml

.PHONY: build-deploy-dev-environment
build-deploy-dev-environment: build-deploy-certmanager build-deploy-operator build-deploy-scheduler
build-deploy-dev-environment: build-deploy-certmanager build-deploy-operator build-deploy-metrics-operator build-deploy-scheduler

markdownlint:
docker run -v $(CURDIR):/workdir --rm ghcr.io/igorshubovych/markdownlint-cli:latest "**/*.md" --config "/workdir/docs/markdownlint-rules.yaml" --ignore "/workdir/CHANGELOG.md"
Expand Down

0 comments on commit 91e57ca

Please sign in to comment.