Refactor uninstallation process (#74)

Docs PR: https://github.com/netbirdio/docs/pull/457

Changes:
* Split kubernetes-operator Chart to operator only chart
(kubernetes-operator) and configuration chart (netbird-operator-config)
* Remove delete validation webhooks for non-needed resources
* Allow abandoning Groups when still linked to a resource for over a
minute after deletion
* Fix duplciate Network Resource retrying heavily
* Fix SetupKey creation duplication
* Skip deleting routing peer since deleting network automatically
deletes it anyway
This commit is contained in:
M. Essam
2025-11-25 20:36:17 +02:00
committed by GitHub
parent 6c855c5d4e
commit f1b131be7d
31 changed files with 580 additions and 721 deletions
@@ -0,0 +1,62 @@
{{/*
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 "netbird-operator-config.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 }}
{{/*
Expand the name of the chart.
*/}}
{{- define "netbird-operator-config.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "netbird-operator-config.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "netbird-operator-config.labels" -}}
helm.sh/chart: {{ include "netbird-operator-config.chart" . }}
{{ include "netbird-operator-config.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "netbird-operator-config.selectorLabels" -}}
app.kubernetes.io/name: {{ include "netbird-operator-config.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "netbird-operator-config.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "netbird-operator-config.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
@@ -0,0 +1,71 @@
{{- if and .Values.ingress.enabled .Values.ingress.kubernetesAPI.enabled }}
{{- $routerNS := .Release.Namespace }}
{{- if .Values.ingress.namespacedNetworks }}
{{- $routerNS = "default" }}
{{- end }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "netbird-operator-config.fullname" . }}-kubernetes-service-expose
labels:
app.kubernetes.io/component: operator
{{- include "netbird-operator-config.labels" . | nindent 4 }}
annotations:
helm.sh/hook: post-upgrade,post-install
helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded
spec:
backoffLimit: 3
template:
metadata:
name: {{ include "netbird-operator-config.fullname" . }}
labels:
app.kubernetes.io/component: operator
{{- include "netbird-operator-config.labels" . | nindent 8 }}
{{- with .Values.operator.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
initContainers:
- name: wait-network-ready
image: "netbirdio/kubectl:latest"
command:
- bash
- -c
args:
- kubectl wait --for 'jsonpath={.status.networkID}' -n {{ $routerNS }} nbroutingpeer router;
containers:
- name: apply-nbresource
image: "netbirdio/kubectl:latest"
env:
- name: NBRESOURCE_VALUE
value: |
apiVersion: netbird.io/v1
kind: NBResource
metadata:
finalizers:
- netbird.io/cleanup
name: kubernetes
namespace: default
spec:
address: kubernetes.default.{{.Values.cluster.dns}}
groups:
{{- if .Values.kubernetesAPI.groups }}
{{ toYaml .Values.kubernetesAPI.groups }}
{{- else }}
- {{ .Values.cluster.name }}-default-api-access
{{- end }}
name: {{ .Values.kubernetesAPI.resourceName | default "default-kubernetes-api" }}
networkID: ${NETWORK_ID}
{{- if .Values.kubernetesAPI.policies }}
policyName: "{{ join "," .Values.kubernetesAPI.policies }}"
{{- end }}
tcpPorts:
- 443
command:
- bash
- -c
args:
- kubectl delete NBResource --ignore-not-found -n default kubernetes; export NETWORK_ID=$(kubectl get NBRoutingPeer -n {{ $routerNS }} router -o 'jsonpath={.status.networkID}'); echo "$NBRESOURCE_VALUE" | envsubst | kubectl apply -f -
serviceAccountName: {{ include "netbird-operator-config.serviceAccountName" . }}
restartPolicy: Never
{{- end }}
@@ -0,0 +1,30 @@
{{- range $k, $v := $.Values.policies }}
---
apiVersion: netbird.io/v1
kind: NBPolicy
metadata:
annotations:
helm.sh/resource-policy: keep
finalizers:
- netbird.io/cleanup
labels:
app.kubernetes.io/component: operator
{{- include "netbird-operator-config.labels" $ | nindent 4 }}
name: {{ $k }}
spec:
name: {{ $v.name }}
sourceGroups:
{{ toYaml $v.sourceGroups | nindent 4}}
{{- if $v.description }}
description: {{ $v.description }}
{{- end }}
{{- if $v.protocols }}
protocols: {{ $v.protocols }}
{{- end }}
{{- if $v.ports }}
ports: {{ $v.ports }}
{{- end }}
{{- if hasKey $v "bidirectional" }}
bidirectional: {{ $v.bidirectional }}
{{- end }}
{{- end }}
@@ -0,0 +1,83 @@
{{- if .Values.router.enabled }}
{{- if .Values.namespacedNetworks }}
{{ $defaults := .Values.router }}
{{ range $k, $v := .Values.router.namespaces }}
apiVersion: netbird.io/v1
kind: NBRoutingPeer
metadata:
finalizers:
- netbird.io/cleanup
labels:
app.kubernetes.io/component: operator
{{- include "netbird-operator-config.labels" $ | nindent 4 }}
name: router
namespace: {{ $k }}
{{ $spec := merge $defaults $v }}
{{- if or (or (or $spec.replicas $spec.resources) (or $spec.labels $spec.annotations)) (or $spec.nodeSelector $spec.tolerations) }}
spec:
{{- if $spec.replicas }}
replicas: {{ $spec.replicas }}
{{- end }}
{{- if $spec.resources }}
resources:
{{- toYaml $spec.resources | nindent 4 }}
{{- end }}
{{- if $spec.labels }}
labels:
{{- toYaml $spec.labels | nindent 4 }}
{{- end }}
{{- if $spec.annotations }}
annotations:
{{- toYaml $spec.annotations | nindent 4 }}
{{- end }}
{{- if $spec.nodeSelector }}
nodeSelector:
{{- toYaml $spec.nodeSelector | nindent 4 }}
{{- end }}
{{- if $spec.tolerations }}
tolerations:
{{- toYaml $spec.tolerations | nindent 4 }}
{{- end }}
{{- end }}
---
{{- end }}
{{- else }}
{{- with .Values.router }}
apiVersion: netbird.io/v1
kind: NBRoutingPeer
metadata:
finalizers:
- netbird.io/cleanup
labels:
app.kubernetes.io/component: operator
{{- include "netbird-operator-config.labels" $ | nindent 4 }}
name: router
{{- if or (or (or .replicas .resources) (or .labels .annotations)) (or .nodeSelector .tolerations) }}
spec:
{{- if .replicas }}
replicas: {{ .replicas }}
{{- end }}
{{- if .resources }}
resources:
{{- toYaml .resources | nindent 4 }}
{{- end }}
{{- if .labels }}
labels:
{{- toYaml .labels | nindent 4 }}
{{- end }}
{{- if .annotations }}
annotations:
{{- toYaml .annotations | nindent 4 }}
{{- end }}
{{- if .nodeSelector }}
nodeSelector:
{{- toYaml .nodeSelector | nindent 4 }}
{{- end }}
{{- if .tolerations }}
tolerations:
{{- toYaml .tolerations | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
@@ -0,0 +1,45 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "netbird-operator-config.fullname" . }}
labels:
{{- include "netbird-operator-config.labels" . | nindent 4 }}
rules:
- apiGroups:
- netbird.io
resources:
- nbresources
verbs:
- patch
- update
- list
- watch
- create
- delete
- apiGroups:
- netbird.io
resources:
- nbroutingpeers
verbs:
- get
- apiGroups:
- netbird.io
resources:
- nbresources/finalizers
verbs:
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "netbird-operator-config.fullname" . }}
labels:
{{- include "netbird-operator-config.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "netbird-operator-config.fullname" . }}
subjects:
- kind: ServiceAccount
name: {{ include "netbird-operator-config.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
@@ -0,0 +1,13 @@
{{- if and .Values.kubernetesAPI.enabled .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "netbird-operator-config.serviceAccountName" . }}
labels:
{{- include "netbird-operator-config.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: true
{{- end }}