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

Reconcile the pyrra generated prometheusrule crs with azure prometheusrulegroups resources #1110

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c87a612
scaffold the project
monteiro-renato Nov 13, 2024
63151d5
generate the dist folder
monteiro-renato Nov 13, 2024
7728238
create the controller
monteiro-renato Nov 13, 2024
28396c7
update the rbac permissions
monteiro-renato Nov 13, 2024
10e8438
update Dockerfile to include the Azure tool
monteiro-renato Nov 13, 2024
f3f6f2d
update the README
monteiro-renato Nov 13, 2024
a1d5ee2
examples of input and output of the conversion tool
monteiro-renato Nov 13, 2024
13fea12
add npm and az-prom-rules-converter as dependencies
monteiro-renato Nov 13, 2024
fa10f01
include the PrometheusRule CRD
monteiro-renato Nov 13, 2024
afd7fd8
add an example .env file
monteiro-renato Nov 13, 2024
48db0e5
setup the controller dependencies
monteiro-renato Nov 13, 2024
e0cf42a
only resources in the monitoring namespace
monteiro-renato Nov 13, 2024
50b824f
include the PrometheusRule CRD in the test suite
monteiro-renato Nov 13, 2024
f138a09
add a file with test utils
monteiro-renato Nov 13, 2024
04aac84
first implementation
monteiro-renato Nov 13, 2024
da40ae5
k8s deployment configs
monteiro-renato Nov 13, 2024
bd48b3b
add a prefix to the rule names to make them unique in the centralized…
monteiro-renato Nov 18, 2024
0e3a647
kubebuilder edit --plugins=go/v4,helm/v1-alpha
monteiro-renato Nov 26, 2024
1a2baa2
helm template
monteiro-renato Nov 26, 2024
730858b
add .env to gitignore
monteiro-renato Nov 26, 2024
ff46f57
update values.yaml
monteiro-renato Nov 26, 2024
a1377b7
Remove Dockerfile.bak
monteiro-renato Nov 28, 2024
c0066c9
return error as nil when RequeueAfter is configured
monteiro-renato Nov 28, 2024
3227610
simplify if condition
monteiro-renato Nov 28, 2024
6a25df2
log errors as errors and not as info
monteiro-renato Nov 28, 2024
c325b96
simplify if else block
monteiro-renato Nov 28, 2024
257877f
rename variable to logger to avoid confusion with the package name
monteiro-renato Nov 28, 2024
fd2b33c
try to delete the rest of the resources even if one deletion fails
monteiro-renato Nov 28, 2024
ad2cf3c
return false as soon as the first missing annotation is seen
monteiro-renato Nov 28, 2024
d164a3b
point to Azure repo now that the PRs have been merged
monteiro-renato Dec 9, 2024
b83adad
add new line at the end of the file
monteiro-renato Dec 10, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Test Chart

on:
push:
pull_request:

jobs:
test-e2e:
name: Run on Ubuntu
runs-on: ubuntu-latest
steps:
- name: Clone the code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: Install the latest version of kind
run: |
curl -Lo ./kind https://kind.sigs.k8s.io/dl/latest/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

- name: Verify kind installation
run: kind version

- name: Create kind cluster
run: kind create cluster

- name: Prepare dis-promrulegroups-operator
run: |
go mod tidy
make docker-build IMG=dis-promrulegroups-operator:v0.1.0
kind load docker-image dis-promrulegroups-operator:v0.1.0

- name: Install Helm
run: |
curl https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

- name: Verify Helm installation
run: helm version

- name: Lint Helm Chart
run: |
helm lint ./dist/chart

# TODO: Uncomment if cert-manager is enabled
# - name: Install cert-manager via Helm
# run: |
# helm repo add jetstack https://charts.jetstack.io
# helm repo update
# helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set installCRDs=true
#
# - name: Wait for cert-manager to be ready
# run: |
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-cainjector
# kubectl wait --namespace cert-manager --for=condition=available --timeout=300s deployment/cert-manager-webhook

# TODO: Uncomment if Prometheus is enabled
# - name: Install Prometheus Operator CRDs
# run: |
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
# helm repo update
# helm install prometheus-crds prometheus-community/prometheus-operator-crds
#
# - name: Install Prometheus via Helm
# run: |
# helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
# helm repo update
# helm install prometheus prometheus-community/prometheus --namespace monitoring --create-namespace
#
# - name: Wait for Prometheus to be ready
# run: |
# kubectl wait --namespace monitoring --for=condition=available --timeout=300s deployment/prometheus-server

- name: Install Helm chart for project
run: |
helm install my-release ./dist/chart --create-namespace --namespace dis-promrulegroups-operator-system

- name: Check Helm release status
run: |
helm status my-release --namespace dis-promrulegroups-operator-system

# TODO: Uncomment if prometheus.enabled is set to true to confirm that the ServiceMonitor gets created
# - name: Check Presence of ServiceMonitor
# run: |
# kubectl wait --namespace dis-promrulegroups-operator-system --for=jsonpath='{.kind}'=ServiceMonitor servicemonitor/dis-promrulegroups-operator-controller-manager-metrics-monitor
3 changes: 3 additions & 0 deletions services/dis-promrulegroups-operator/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ go.work
*.swp
*.swo
*~

# Ignore .env
.env
33 changes: 0 additions & 33 deletions services/dis-promrulegroups-operator/Dockerfile.bak
tjololo marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

2 changes: 2 additions & 0 deletions services/dis-promrulegroups-operator/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
domain: dis.altinn.cloud
layout:
- go.kubebuilder.io/v4
plugins:
helm.kubebuilder.io/v1-alpha: {}
projectName: dis-promrulegroups-operator
repo: github.com/Altinn/altinn-platform/services/dis-promrulegroups-operator
resources:
Expand Down
25 changes: 25 additions & 0 deletions services/dis-promrulegroups-operator/dist/chart/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Patterns to ignore when building Helm packages.
# Operating system files
.DS_Store

# Version control directories
.git/
.gitignore
.bzr/
.hg/
.hgignore
.svn/

# Backup and temporary files
*.swp
*.tmp
*.bak
*.orig
*~

# IDE and editor-related files
.idea/
.vscode/

# Helm chart artifacts
dist/chart/*.tgz
7 changes: 7 additions & 0 deletions services/dis-promrulegroups-operator/dist/chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v2
name: dis-promrulegroups-operator
description: A Helm chart to distribute the project dis-promrulegroups-operator
type: application
version: 0.1.0
appVersion: "0.1.0"
icon: "https://example.com/icon.png"
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- define "chart.name" -}}
{{- if .Chart }}
{{- if .Chart.Name }}
{{- .Chart.Name | trunc 63 | trimSuffix "-" }}
{{- else if .Values.nameOverride }}
{{ .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
dis-promrulegroups-operator
{{- end }}
{{- else }}
dis-promrulegroups-operator
{{- end }}
{{- end }}


{{- define "chart.labels" -}}
{{- if .Chart.AppVersion -}}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
{{- if .Chart.Version }}
helm.sh/chart: {{ .Chart.Version | quote }}
{{- end }}
app.kubernetes.io/name: {{ include "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}


{{- define "chart.selectorLabels" -}}
app.kubernetes.io/name: {{ include "chart.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}


{{- define "chart.hasMutatingWebhooks" -}}
{{- $hasMutating := false }}
{{- range . }}
{{- if eq .type "mutating" }}
$hasMutating = true }}{{- end }}
{{- end }}
{{ $hasMutating }}}}{{- end }}


{{- define "chart.hasValidatingWebhooks" -}}
{{- $hasValidating := false }}
{{- range . }}
{{- if eq .type "validating" }}
$hasValidating = true }}{{- end }}
{{- end }}
{{ $hasValidating }}}}{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{- if .Values.certmanager.enable }}
# Self-signed Issuer
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
labels:
{{- include "chart.labels" . | nindent 4 }}
name: selfsigned-issuer
namespace: {{ .Release.Namespace }}
spec:
selfSigned: {}
{{- if .Values.webhook.enable }}
---
# Certificate for the webhook
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
annotations:
{{- if .Values.crd.keep }}
"helm.sh/resource-policy": keep
{{- end }}
name: serving-cert
namespace: {{ .Release.Namespace }}
labels:
{{- include "chart.labels" . | nindent 4 }}
spec:
dnsNames:
- dis-promrulegroups-operator.{{ .Release.Namespace }}.svc
- dis-promrulegroups-operator.{{ .Release.Namespace }}.svc.cluster.local
- dis-promrulegroups-operator-webhook-service.{{ .Release.Namespace }}.svc
issuerRef:
kind: Issuer
name: selfsigned-issuer
secretName: webhook-server-cert
{{- end }}
{{- if and .Values.metrics.enable .Values.certmanager.enable }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT
Probably generated code, the check .Values.certmanager.enable seems unnecessary as the outer most if already has checked that it is true

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generated code indeed.
One of the {{end}} blocks should be further up.

---
# Certificate for the metrics
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
annotations:
{{- if .Values.crd.keep }}
"helm.sh/resource-policy": keep
{{- end }}
labels:
{{- include "chart.labels" . | nindent 4 }}
name: metrics-certs
namespace: {{ .Release.Namespace }}
spec:
dnsNames:
- dis-promrulegroups-operator.{{ .Release.Namespace }}.svc
- dis-promrulegroups-operator.{{ .Release.Namespace }}.svc.cluster.local
- dis-promrulegroups-operator-metrics-service.{{ .Release.Namespace }}.svc
issuerRef:
kind: Issuer
name: selfsigned-issuer
secretName: metrics-server-cert
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: dis-promrulegroups-operator-controller-manager
namespace: {{ .Release.Namespace }}
labels:
{{- include "chart.labels" . | nindent 4 }}
control-plane: controller-manager
spec:
replicas: {{ .Values.controllerManager.replicas }}
selector:
matchLabels:
{{- include "chart.selectorLabels" . | nindent 6 }}
control-plane: controller-manager
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: manager
labels:
{{- include "chart.labels" . | nindent 8 }}
control-plane: controller-manager
{{- if and .Values.controllerManager.pod .Values.controllerManager.pod.labels }}
{{- range $key, $value := .Values.controllerManager.pod.labels }}
{{ $key }}: {{ $value }}
{{- end }}
{{- end }}
spec:
containers:
- name: manager
args:
{{- range .Values.controllerManager.container.args }}
- {{ . }}
{{- end }}
command:
- /manager
image: {{ .Values.controllerManager.container.image.repository }}:{{ .Values.controllerManager.container.image.tag }}
{{- if .Values.controllerManager.container.env }}
env:
{{- range $key, $value := .Values.controllerManager.container.env }}
- name: {{ $key }}
value: {{ $value }}
{{- end }}
{{- end }}
livenessProbe:
{{- toYaml .Values.controllerManager.container.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.controllerManager.container.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.controllerManager.container.resources | nindent 12 }}
securityContext:
{{- toYaml .Values.controllerManager.container.securityContext | nindent 12 }}
{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}
volumeMounts:
{{- if and .Values.metrics.enable .Values.certmanager.enable }}
- name: metrics-certs
mountPath: /tmp/k8s-metrics-server/metrics-certs
readOnly: true
{{- end }}
{{- end }}
securityContext:
{{- toYaml .Values.controllerManager.securityContext | nindent 8 }}
serviceAccountName: {{ .Values.controllerManager.serviceAccountName }}
terminationGracePeriodSeconds: {{ .Values.controllerManager.terminationGracePeriodSeconds }}
{{- if and .Values.certmanager.enable (or .Values.webhook.enable .Values.metrics.enable) }}
volumes:
{{- if and .Values.metrics.enable .Values.certmanager.enable }}
- name: metrics-certs
secret:
secretName: metrics-server-cert
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- if .Values.metrics.enable }}
apiVersion: v1
kind: Service
metadata:
name: dis-promrulegroups-operator-controller-manager-metrics-service
namespace: {{ .Release.Namespace }}
labels:
{{- include "chart.labels" . | nindent 4 }}
spec:
ports:
- port: 8443
targetPort: 8443
protocol: TCP
name: https
selector:
control-plane: controller-manager
{{- end }}
Loading