Remove the creation and use of the Kubectl image to apply configuration (#198)

Using kubectl to manage configuration is not a sustainable solution and
not something that we want to promote users to do. This removes the
creation of the image and use of the image in the Helm charts.
This commit is contained in:
Philip Laine
2026-04-23 11:58:09 +02:00
committed by GitHub
parent 20a3ddd4ed
commit 7bc9c87de7
13 changed files with 4 additions and 588 deletions
-62
View File
@@ -1,62 +0,0 @@
name: Docker
on:
push:
paths:
- 'Dockerfile.kubectl'
tags:
- "v*"
branches:
- main
jobs:
kubectl-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
netbirdio/kubectl
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=pr
type=ref,event=branch
type=semver,pattern={{version}}
- name: Login to Docker Hub
if: github.repository == github.event.pull_request.head.repo.full_name || !github.head_ref
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
file: "Dockerfile.kubectl"
labels: |
"org.opencontainers.image.created={{.Date}}"
"org.opencontainers.image.title={{.ProjectName}}"
"org.opencontainers.image.version={{.Version}}"
"org.opencontainers.image.revision={{.FullCommit}}"
"org.opencontainers.image.version={{.Version}}"
"maintainer=dev@netbird.io"
-12
View File
@@ -1,12 +0,0 @@
FROM alpine:3 AS builder
RUN apk update && apk add curl bash
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" && \
chmod +x kubectl && \
mv kubectl /usr/local/bin/kubectl
FROM alpine:3 AS final
RUN apk add --no-cache gettext-envsubst
COPY --from=builder /usr/local/bin/kubectl /usr/local/bin/kubectl
@@ -1,71 +0,0 @@
{{- 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 "kubernetes-operator.fullname" . }}-kubernetes-service-expose
labels:
app.kubernetes.io/component: operator
{{- include "kubernetes-operator.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 "kubernetes-operator.fullname" . }}
labels:
app.kubernetes.io/component: operator
{{- include "kubernetes-operator.labels" . | nindent 8 }}
{{- with .Values.operator.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
initContainers:
- name: wait-network-ready
image: "netbirdio/kubectl:latest"
command:
- sh
- -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.ingress.kubernetesAPI.groups }}
{{ toYaml .Values.ingress.kubernetesAPI.groups }}
{{- else }}
- {{ .Values.cluster.name }}-default-api-access
{{- end }}
name: {{ .Values.ingress.kubernetesAPI.resourceName | default "default-kubernetes-api" }}
networkID: ${NETWORK_ID}
{{- if .Values.ingress.kubernetesAPI.policies }}
policyName: "{{ join "," .Values.ingress.kubernetesAPI.policies }}"
{{- end }}
tcpPorts:
- 443
command:
- sh
- -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 "kubernetes-operator.serviceAccountName" . }}
restartPolicy: Never
{{- end }}
+4 -46
View File
@@ -133,6 +133,7 @@ operator:
affinity: {}
# DEPRECATED: Use NetworkRouters and NetworkResources instead.
ingress:
# Enable ingress capabilities to expose services
enabled: false
@@ -140,52 +141,6 @@ ingress:
namespacedNetworks: false
# Allow creating policies through Service annotations
allowAutomaticPolicyCreation: false
kubernetesAPI: # DEPRECATED: Use netbirdio/netbird-operator-configs Chart instead
enabled: false
groups: []
# - group1
# - group2
policies: []
# - default
router: # DEPRECATED: Use netbirdio/netbird-operator-configs Chart instead
# Deploy routing peer(s)
enabled: false
# replicas: 3
# resources:
# requests:
# cpu: 100m
# memory: 100Mi
# limits:
# cpu: 100m
# memory: 100Mi
# labels: {}
# annotations: {}
# nodeSelector: {}
# tolerations: []
# Only needed if namespacedNetworks is set to true
namespaces: {}
# default:
# replicas: 3
# resources:
# requests:
# cpu: 100m
# memory: 100Mi
# limits:
# cpu: 100m
# memory: 100Mi
# labels: {}
# annotations: {}
# nodeSelector: {}
# tolerations: []
# NetBird Policies for use with exposed services
policies: {} # DEPRECATED: Use netbirdio/netbird-operator-configs Chart instead
# default:
# name: Kubernetes Default Policy
# sourceGroups:
# - All
gatewayAPI:
enabled: false
cluster:
# Cluster DNS name (used for webhooks certificates and for network resource DNS names)
@@ -202,6 +157,9 @@ netbirdAPI: {}
#routingClientImage: "netbirdio/netbird:latest"
gatewayAPI:
enabled: false
general:
# General labels, applied to all created K8s resources
labels: {}
-23
View File
@@ -1,23 +0,0 @@
# 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/
-6
View File
@@ -1,6 +0,0 @@
apiVersion: v2
name: netbird-operator-config
description: NetBird Operator Configuration
type: application
version: 0.1.0
appVersion: "0.2.0"
@@ -1,62 +0,0 @@
{{/*
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 }}
@@ -1,68 +0,0 @@
{{- if .Values.kubernetesAPI.enabled }}
{{- $routerNS := .Release.Namespace }}
{{- if .Values.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 }}
spec:
initContainers:
- name: wait-network-ready
image: "netbirdio/kubectl:latest"
command:
- sh
- -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:
- sh
- -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 }}
@@ -1,30 +0,0 @@
{{- 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 }}
@@ -1,89 +0,0 @@
{{- 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 (or $spec.nodeSelector $spec.tolerations) $spec.privileged) }}
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 }}
{{- if $spec.privileged }}
privileged: {{ $spec.privileged }}
{{- 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 (or .nodeSelector .tolerations) .privileged) }}
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 }}
{{- if .privileged }}
privileged: {{ .privileged }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
@@ -1,47 +0,0 @@
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
- list
- watch
- 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 }}
@@ -1,13 +0,0 @@
{{- 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 }}
-59
View File
@@ -1,59 +0,0 @@
cluster:
name: "kubernetes"
dns: "svc.cluster.local"
# Create router per namespace, useful for strict networking requirements
namespacedNetworks: false
router:
# Deploy routing peer(s)
enabled: false
# replicas: 3
# resources:
# requests:
# cpu: 100m
# memory: 100Mi
# limits:
# cpu: 100m
# memory: 100Mi
# labels: {}
# annotations: {}
# nodeSelector: {}
# tolerations: []
# privileged: false
# Only needed if namespacedNetworks is set to true
namespaces: {}
# default:
# replicas: 3
# resources:
# requests:
# cpu: 100m
# memory: 100Mi
# limits:
# cpu: 100m
# memory: 100Mi
# labels: {}
# annotations: {}
# nodeSelector: {}
# tolerations: []
# privileged: false
# NetBird Policies for use with exposed services
policies: {}
# default:
# name: Kubernetes Default Policy
# sourceGroups:
# - All
kubernetesAPI:
enabled: false
groups: []
# - group1
# - group2
policies: []
# - default
# resourceName: "my-cluster-kubernetes"
serviceAccount:
create: true
name: ""
annotations: {}