From 32700aa327c701ee093caea4e52a8d584d41664c Mon Sep 17 00:00:00 2001 From: FrancescoL96 Date: Tue, 8 Oct 2024 16:58:10 +0200 Subject: [PATCH] feat: first commit --- .github/workflows/release-pullrequest.yaml | 35 ++++++ .github/workflows/release-tag.yaml | 47 ++++++++ .gitignore | 2 + README.md | 11 ++ chart/.helmignore | 23 ++++ chart/Chart.yaml | 21 ++++ ...trees.krateo.io_compositionreferences.yaml | 84 +++++++++++++ chart/templates/_helpers.tpl | 62 ++++++++++ chart/templates/deployment.yaml | 112 ++++++++++++++++++ chart/templates/hpa.yaml | 32 +++++ chart/templates/role.yaml | 41 +++++++ chart/templates/rolebinding.yaml | 17 +++ chart/templates/service.yaml | 20 ++++ chart/templates/serviceaccount.yaml | 11 ++ chart/values.yaml | 98 +++++++++++++++ 15 files changed, 616 insertions(+) create mode 100644 .github/workflows/release-pullrequest.yaml create mode 100644 .github/workflows/release-tag.yaml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 chart/.helmignore create mode 100644 chart/Chart.yaml create mode 100644 chart/crds/resourcetrees.krateo.io_compositionreferences.yaml create mode 100644 chart/templates/_helpers.tpl create mode 100644 chart/templates/deployment.yaml create mode 100644 chart/templates/hpa.yaml create mode 100644 chart/templates/role.yaml create mode 100644 chart/templates/rolebinding.yaml create mode 100644 chart/templates/service.yaml create mode 100644 chart/templates/serviceaccount.yaml create mode 100644 chart/values.yaml diff --git a/.github/workflows/release-pullrequest.yaml b/.github/workflows/release-pullrequest.yaml new file mode 100644 index 0000000..9527481 --- /dev/null +++ b/.github/workflows/release-pullrequest.yaml @@ -0,0 +1,35 @@ +name: release-pullrequest + +on: + pull_request: + branches: + - main + +jobs: + package: + runs-on: ubuntu-latest + + steps: + - name: Extract latest App Version + uses: tdemin/find-latest-tag@v1 + id: app_version + with: + repo: https://${{ secrets.HELM_CHARTS_BOT }}@github.com/krateoplatformops/finops-operator-exporter.git + + - name: Print latest App Version + run: echo ${{ steps.app_version.outputs.tag }} + + - name: Checkout + uses: actions/checkout@v3 + + - name: Replace Version in Chart.yaml + run: sed -i 's/CHART_VERSION/${{ steps.app_version.outputs.tag }}/g' ./chart/Chart.yaml + + - name: Replace App Version in Chart.yaml + run: sed -i 's/APP_VERSION/${{ steps.app_version.outputs.tag }}/g' ./chart/Chart.yaml + + - name: Set up Helm + uses: azure/setup-helm@v4.1.0 + + - name: Helm lint + run: helm lint ./chart diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml new file mode 100644 index 0000000..ef2b79f --- /dev/null +++ b/.github/workflows/release-tag.yaml @@ -0,0 +1,47 @@ +name: release-tag + +on: + push: + tags: ["[0-9]+.[0-9]+.[0-9]+"] + +jobs: + package: + runs-on: ubuntu-latest + + steps: + - name: Extract latest App Version + uses: tdemin/find-latest-tag@v1 + id: app_version + with: + repo: https://${{ secrets.HELM_CHARTS_BOT }}@github.com/krateoplatformops/finops-operator-exporter.git + + - name: Checkout + uses: actions/checkout@v3 + + - name: Extract Version + id: tagger + uses: battila7/get-version-action@v2 + + - name: Print Version + run: | + echo ${{steps.tagger.outputs.version}} + echo ${{steps.tagger.outputs.version-without-v}} + + - name: Replace Version in Chart.yaml + run: sed -i 's/CHART_VERSION/${{ steps.tagger.outputs.version-without-v }}/g' ./chart/Chart.yaml + + - name: Print latest App Version + run: echo ${{ steps.app_version.outputs.tag }} + + - name: Replace App Version in Chart.yaml + run: sed -i 's/APP_VERSION/${{ steps.app_version.outputs.tag }}/g' ./chart/Chart.yaml + + - name: Publish Helm chart + uses: stefanprodan/helm-gh-pages@master + with: + token: ${{ secrets.HELM_CHARTS_BOT }} + charts_dir: ./ + charts_url: https://charts.krateo.io + owner: krateoplatformops + repository: helm-charts + branch: gh-pages diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3f21dff --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +chart/templates/clusterrole.yaml +chart/templates/clusterrolebinding.yaml diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ef111a --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Krateo Composition Watcher Operator + +This is a [Helm Chart](https://helm.sh/docs/topics/charts/) for [Krateo Composition Watcher](https://github.com/krateoplatformops/composition-watcher). + +## How to install + +```sh +$ helm repo add krateo https://charts.krateo.io +$ helm repo update krateo +$ helm install composition-watcher krateo/composition-watcher +``` diff --git a/chart/.helmignore b/chart/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/chart/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/chart/Chart.yaml b/chart/Chart.yaml new file mode 100644 index 0000000..a34bd78 --- /dev/null +++ b/chart/Chart.yaml @@ -0,0 +1,21 @@ +apiVersion: v2 +name: composition-watcher +description: Krateo Composition Watcher +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +type: application +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: CHART_VERSION +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: APP_VERSION diff --git a/chart/crds/resourcetrees.krateo.io_compositionreferences.yaml b/chart/crds/resourcetrees.krateo.io_compositionreferences.yaml new file mode 100644 index 0000000..13a440d --- /dev/null +++ b/chart/crds/resourcetrees.krateo.io_compositionreferences.yaml @@ -0,0 +1,84 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: compositionreferences.resourcetrees.krateo.io +spec: + group: resourcetrees.krateo.io + names: + kind: CompositionReference + listKind: CompositionReferenceList + plural: compositionreferences + singular: compositionreference + scope: Namespaced + versions: + - name: v1 + schema: + openAPIV3Schema: + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + properties: + filters: + properties: + exclude: + items: + properties: + apiVersion: + type: string + name: + type: string + resource: + type: string + required: + - apiVersion + type: object + type: array + required: + - exclude + type: object + reference: + properties: + apiVersion: + type: string + name: + type: string + namespace: + type: string + resource: + type: string + required: + - apiVersion + - name + - namespace + - resource + type: object + required: + - filters + - reference + type: object + status: + type: object + type: object + served: true + storage: true + subresources: + status: {} diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl new file mode 100644 index 0000000..7ba5edc --- /dev/null +++ b/chart/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "chart.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "chart.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "chart.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "chart.labels" -}} +helm.sh/chart: {{ include "chart.chart" . }} +{{ include "chart.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "chart.selectorLabels" -}} +app.kubernetes.io/name: {{ include "chart.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "chart.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "chart.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml new file mode 100644 index 0000000..f5d37c2 --- /dev/null +++ b/chart/templates/deployment.yaml @@ -0,0 +1,112 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "chart.fullname" . }}-controller-manager + labels: + app.kubernetes.io/component: manager + app.kubernetes.io/created-by: composition-watcher + app.kubernetes.io/part-of: composition-watcher + control-plane: controller-manager + {{- include "chart.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.controllerManager.replicas }} + selector: + matchLabels: + control-plane: controller-manager + {{- include "chart.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + control-plane: controller-manager + {{- include "chart.selectorLabels" . | nindent 8 }} + annotations: + kubectl.kubernetes.io/default-container: manager + spec: + containers: + - args: + - --secure-listen-address=0.0.0.0:8443 + - --upstream=http://127.0.0.1:8080/ + - --logtostderr=true + - --v=0 + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: "cluster.local" + image: {{ .Values.proxy.image.repository }}:{{ .Values.proxy.image.tag + | default .Chart.AppVersion }} + name: kube-rbac-proxy + imagePullPolicy: {{ .Values.proxy.imagePullPolicy }} + ports: + - containerPort: 8443 + name: https + protocol: TCP + resources: {{- toYaml .Values.proxy.resources | nindent + 10 }} + {{- with .Values.proxy.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 10 }} + {{- end }} + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + - args: + - --health-probe-bind-address=:8081 + - --metrics-bind-address=127.0.0.1:8080 + - --leader-elect + command: + - /manager + env: + - name: KUBERNETES_CLUSTER_DOMAIN + value: {{ quote .Values.kubernetesClusterDomain }} + - name: RECONCILE_REQUEUE_AFTER + value: {{ quote .Values.requeueAfter }} + image: {{ .Values.controllerManager.image.repository }}:{{ .Values.controllerManager.image.tag + | default .Chart.AppVersion }} + imagePullPolicy: {{ .Values.controllerManager.imagePullPolicy }} + livenessProbe: + httpGet: + path: /healthz + port: 8081 + initialDelaySeconds: 15 + periodSeconds: 20 + name: manager + readinessProbe: + httpGet: + path: /readyz + port: 8081 + initialDelaySeconds: 5 + periodSeconds: 10 + {{- with .Values.controllerManager.volumeMounts }} + volumeMounts: + {{- toYaml . | nindent 10 }} + {{- end }} + resources: {{- toYaml .Values.controllerManager.resources + | nindent 10 }} + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + imagePullSecrets: {{- toYaml .Values.imagePullSecrets + | nindent 6 }} + securityContext: + runAsNonRoot: true + serviceAccountName: {{ include "chart.fullname" . }}-controller-manager + terminationGracePeriodSeconds: 10 + {{- with .Values.volumes }} + volumes: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/chart/templates/hpa.yaml b/chart/templates/hpa.yaml new file mode 100644 index 0000000..65db208 --- /dev/null +++ b/chart/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.controllerManager.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "chart.fullname" . }} + labels: + {{- include "chart.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "chart.fullname" . }} + minReplicas: {{ .Values.controllerManager.autoscaling.minReplicas }} + maxReplicas: {{ .Values.controllerManager.autoscaling.maxReplicas }} + metrics: + {{- if .Values.controllerManager.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.controllerManager.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.controllerManager.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.controllerManager.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/chart/templates/role.yaml b/chart/templates/role.yaml new file mode 100644 index 0000000..4664be2 --- /dev/null +++ b/chart/templates/role.yaml @@ -0,0 +1,41 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: Role +metadata: + name: {{ include "chart.fullname" . }}-leader-election-role + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: composition-watcher + app.kubernetes.io/part-of: composition-watcher + {{- include "chart.labels" . | nindent 4 }} +rules: +- apiGroups: + - "" + resources: + - configmaps + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - coordination.k8s.io + resources: + - leases + verbs: + - get + - list + - watch + - create + - update + - patch + - delete +- apiGroups: + - "" + resources: + - events + verbs: + - create + - patch diff --git a/chart/templates/rolebinding.yaml b/chart/templates/rolebinding.yaml new file mode 100644 index 0000000..d6828ae --- /dev/null +++ b/chart/templates/rolebinding.yaml @@ -0,0 +1,17 @@ +apiVersion: rbac.authorization.k8s.io/v1 +kind: RoleBinding +metadata: + name: {{ include "chart.fullname" . }}-leader-election-rolebinding + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: composition-watcher + app.kubernetes.io/part-of: composition-watcher + {{- include "chart.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: '{{ include "chart.fullname" . }}-leader-election-role' +subjects: +- kind: ServiceAccount + name: '{{ include "chart.fullname" . }}-controller-manager' + namespace: '{{ .Release.Namespace }}' diff --git a/chart/templates/service.yaml b/chart/templates/service.yaml new file mode 100644 index 0000000..5c245c8 --- /dev/null +++ b/chart/templates/service.yaml @@ -0,0 +1,20 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "chart.fullname" . }}-controller-manager-metrics-service + labels: + app.kubernetes.io/component: kube-rbac-proxy + app.kubernetes.io/created-by: composition-watcher + app.kubernetes.io/part-of: composition-watcher + control-plane: controller-manager + {{- include "chart.labels" . | nindent 4 }} +spec: + type: ClusterIP + selector: + control-plane: controller-manager + {{- include "chart.selectorLabels" . | nindent 4 }} + ports: + - name: https + port: 8443 + protocol: TCP + targetPort: https diff --git a/chart/templates/serviceaccount.yaml b/chart/templates/serviceaccount.yaml new file mode 100644 index 0000000..f380362 --- /dev/null +++ b/chart/templates/serviceaccount.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "chart.fullname" . }}-controller-manager + labels: + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: composition-watcher + app.kubernetes.io/part-of: composition-watcher + {{- include "chart.labels" . | nindent 4 }} + annotations: + {{- toYaml .Values.serviceAccount.annotations | nindent 4 }} diff --git a/chart/values.yaml b/chart/values.yaml new file mode 100644 index 0000000..39486df --- /dev/null +++ b/chart/values.yaml @@ -0,0 +1,98 @@ +# Default values for finops-operator-focus. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +controllerManager: + replicaCount: 1 + + image: + repository: ghcr.io/krateoplatformops/composition-watcher + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 10m + memory: 128Mi + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + +proxy: + replicaCount: 1 + + image: + repository: gcr.io/kubebuilder/kube-rbac-proxy + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: v0.15.0 + + resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: + cpu: 500m + memory: 128Mi + requests: + cpu: 5m + memory: 64Mi + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + # Additional volumeMounts on the output Deployment definition. + volumeMounts: [] + # - name: foo + # mountPath: "/etc/foo" + # readOnly: true + + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +serviceAccount: + annotations: {} + +imagePullSecrets: + - name: registry-credentials + +requeueAfter: 300