Skip to content

Commit 01b1d89

Browse files
authored
Prevent worker to run before main deployment readiness
1 parent b4f2c7b commit 01b1d89

File tree

6 files changed

+292
-5
lines changed

6 files changed

+292
-5
lines changed

charts/netbox/Chart.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v2
22
name: netbox
3-
version: 5.0.69
3+
version: 5.1.0
44
# renovate: image=ghcr.io/netbox-community/netbox
55
appVersion: "v4.2.8"
66
type: application
@@ -33,7 +33,7 @@ dependencies:
3333
annotations:
3434
artifacthub.io/images: |
3535
- name: netbox
36-
image: ghcr.io/netbox-community/netbox:v4.2.8
36+
image: ghcr.io/netbox-community/netbox:v4.2.6
3737
- name: busybox
3838
image: docker.io/busybox:1.37.0
3939
artifacthub.io/license: Apache-2.0

charts/netbox/templates/role.yaml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{{- if .Values.rbac.create }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: Role
4+
metadata:
5+
name: {{ include "common.names.fullname" . }}
6+
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
7+
namespace: {{ include "common.names.namespace" . | quote }}
8+
{{- if .Values.commonAnnotations }}
9+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
10+
{{- end }}
11+
rules:
12+
{{- if and .Values.statusLabeler.enabled }}
13+
- apiGroups:
14+
- apps
15+
resources:
16+
- statefulsets
17+
- deployments
18+
- replicasets
19+
verbs:
20+
- get
21+
- list
22+
- watch
23+
{{- end }}
24+
{{- if .Values.rbac.rules }}
25+
{{- include "common.tplvalues.render" ( dict "value" .Values.rbac.rules "context" $ ) | nindent 2 }}
26+
{{- end }}
27+
{{- end }}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{{- if .Values.rbac.create }}
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: RoleBinding
4+
metadata:
5+
name: {{ include "common.names.fullname" . }}
6+
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
7+
namespace: {{ include "common.names.namespace" . | quote }}
8+
{{- if .Values.commonAnnotations }}
9+
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
10+
{{- end }}
11+
roleRef:
12+
kind: Role
13+
name: {{ include "common.names.fullname" . }}
14+
apiGroup: rbac.authorization.k8s.io
15+
subjects:
16+
- kind: ServiceAccount
17+
name: {{ include "netbox.serviceAccountName" . }}
18+
namespace: {{ include "common.names.namespace" . | quote }}
19+
{{- end }}

charts/netbox/templates/worker/deployment.yaml

+27-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,33 @@ spec:
3939
{{- if .Values.worker.podSecurityContext.enabled }}
4040
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.worker.podSecurityContext "context" $) | nindent 8 }}
4141
{{- end }}
42-
{{- if .Values.worker.initContainers }}
43-
initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.worker.initContainers "context" $) | trim | nindent 8 }}
42+
{{- if or .Values.worker.initContainers .Values.worker.waitForBackend.enabled }}
43+
initContainers:
44+
{{- if .Values.worker.waitForBackend.enabled }}
45+
- name: wait-for-backend
46+
image: {{ include "common.images.image" (dict "imageRoot" .Values.worker.waitForBackend.image "global" .Values.global) }}
47+
imagePullPolicy: {{ .Values.worker.waitForBackend.image.pullPolicy | quote }}
48+
{{- if .Values.worker.waitForBackend.command }}
49+
command: {{- include "common.tplvalues.render" (dict "value" .Values.worker.waitForBackend.command "context" $) | nindent 10 }}
50+
{{- end }}
51+
{{- if .Values.worker.waitForBackend.args }}
52+
args: {{- include "common.tplvalues.render" (dict "value" .Values.worker.waitForBackend.args "context" $) | nindent 10 }}
53+
{{- end }}
54+
{{- if .Values.worker.waitForBackend.containerSecurityContext.enabled }}
55+
securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.worker.waitForBackend.containerSecurityContext "context" $) | nindent 12 }}
56+
{{- end }}
57+
{{- if .Values.worker.waitForBackend.resources }}
58+
resources: {{- include "common.tplvalues.render" (dict "value" .Values.worker.waitForBackend.resources "context" $) | nindent 12 }}
59+
{{- else if ne .Values.worker.waitForBackend.resourcesPreset "none" }}
60+
resources: {{- include "common.resources.preset" (dict "type" .Values.worker.waitForBackend.resourcesPreset) | nindent 12 }}
61+
{{- end }}
62+
env:
63+
- name: DEPLOYMENT_NAME
64+
value: {{ include "common.names.fullname" . }}
65+
{{- end }}
66+
{{- if .Values.worker.initContainers }}
67+
{{- include "common.tplvalues.render" (dict "value" .Values.worker.initContainers "context" $) | nindent 8 }}
68+
{{- end }}
4469
{{- end }}
4570
containers:
4671
- name: {{ .Chart.Name }}-worker

charts/netbox/values.schema.json

+104
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,17 @@
917917
"rackElevationDefaultUnitWidth": {
918918
"type": "integer"
919919
},
920+
"rbac": {
921+
"type": "object",
922+
"properties": {
923+
"create": {
924+
"type": "boolean"
925+
},
926+
"rules": {
927+
"type": "array"
928+
}
929+
}
930+
},
920931
"readinessProbe": {
921932
"$ref": "#/$defs/probe"
922933
},
@@ -1625,6 +1636,99 @@
16251636
}
16261637
},
16271638
"type": "object"
1639+
},
1640+
"waitForBackend": {
1641+
"properties": {
1642+
"args": {
1643+
"type": "array"
1644+
},
1645+
"command": {
1646+
"items": {
1647+
"type": "string"
1648+
},
1649+
"type": "array"
1650+
},
1651+
"enabled": {
1652+
"type": "boolean"
1653+
},
1654+
"podSecurityContext": {
1655+
"properties": {
1656+
"enabled": {
1657+
"type": "boolean"
1658+
},
1659+
"fsGroup": {
1660+
"type": "integer"
1661+
},
1662+
"fsGroupChangePolicy": {
1663+
"type": "string"
1664+
},
1665+
"supplementalGroups": {
1666+
"type": "array"
1667+
},
1668+
"sysctls": {
1669+
"type": "array"
1670+
}
1671+
},
1672+
"type": "object"
1673+
},
1674+
"resources": {
1675+
"properties": {},
1676+
"type": "object"
1677+
},
1678+
"resourcesPreset": {
1679+
"type": "string"
1680+
},
1681+
"securityContext": {
1682+
"properties": {
1683+
"allowPrivilegeEscalation": {
1684+
"type": "boolean"
1685+
},
1686+
"capabilities": {
1687+
"properties": {
1688+
"drop": {
1689+
"items": {
1690+
"type": "string"
1691+
},
1692+
"type": "array"
1693+
}
1694+
},
1695+
"type": "object"
1696+
},
1697+
"enabled": {
1698+
"type": "boolean"
1699+
},
1700+
"privileged": {
1701+
"type": "boolean"
1702+
},
1703+
"readOnlyRootFilesystem": {
1704+
"type": "boolean"
1705+
},
1706+
"runAsGroup": {
1707+
"type": "integer"
1708+
},
1709+
"runAsNonRoot": {
1710+
"type": "boolean"
1711+
},
1712+
"runAsUser": {
1713+
"type": "integer"
1714+
},
1715+
"seLinuxOptions": {
1716+
"properties": {},
1717+
"type": "object"
1718+
},
1719+
"seccompProfile": {
1720+
"properties": {
1721+
"type": {
1722+
"type": "string"
1723+
}
1724+
},
1725+
"type": "object"
1726+
}
1727+
},
1728+
"type": "object"
1729+
}
1730+
},
1731+
"type": "object"
16281732
}
16291733
},
16301734
"type": "object"

charts/netbox/values.yaml

+113-1
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,25 @@ serviceAccount:
625625
annotations: {}
626626
name: ""
627627
automountServiceAccountToken: false
628+
## Role Based Access
629+
## ref: https://kubernetes.io/docs/admin/authorization/rbac/
630+
##
631+
rbac:
632+
## @param rbac.create Specifies whether RBAC resources should be created
633+
##
634+
create: true
635+
## @param rbac.rules Custom RBAC rules to set
636+
## e.g:
637+
## rules:
638+
## - apiGroups:
639+
## - ""
640+
## resources:
641+
## - pods
642+
## verbs:
643+
## - get
644+
## - list
645+
##
646+
rules: []
628647
## @param hostAliases [array] Add deployment host aliases
629648
## https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/
630649
##
@@ -1504,7 +1523,7 @@ worker:
15041523
readOnlyPersistence: false
15051524
## @param worker.automountServiceAccountToken Mount Service Account token in pod
15061525
##
1507-
automountServiceAccountToken: false
1526+
automountServiceAccountToken: true
15081527
## @param worker.affinity Affinity for worker pod assignment
15091528
## Ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity
15101529
## Note: podAffinityPreset, podAntiAffinityPreset, and nodeAffinityPreset will be ignored when it's set
@@ -1627,3 +1646,96 @@ worker:
16271646
## command: ['sh', '-c', 'echo "init"']
16281647
##
16291648
initContainers: []
1649+
## Init containers parameters:
1650+
## wait-for-backend: Wait for NetBox backend before running workers
1651+
##
1652+
waitForBackend:
1653+
## @param waitForBackend.enabled Wait for NetBox backend before running workers
1654+
##
1655+
enabled: true
1656+
## @param waitForBackend.image.registry [default: REGISTRY_NAME] Init container wait-for-backend image registry
1657+
## @param waitForBackend.image.repository [default: REPOSITORY_NAME/kubectl] Init container wait-for-backend image name
1658+
## @param waitForBackend.image.tag Init container wait-for-backend image tag
1659+
## @param waitForBackend.image.digest Init container wait-for-backend image digest in the way sha256:aa.... Please note this parameter, if set, will override the tag
1660+
## @param waitForBackend.image.pullPolicy Init container wait-for-backend image pull policy
1661+
## @param waitForBackend.image.pullSecrets Specify docker-registry secret names as an array
1662+
##
1663+
image:
1664+
registry: docker.io
1665+
repository: bitnami/kubectl
1666+
tag: 1.32.2-debian-12-r3
1667+
digest: ""
1668+
## Specify a imagePullPolicy
1669+
## ref: https://kubernetes.io/docs/concepts/containers/images/#pre-pulled-images
1670+
##
1671+
pullPolicy: IfNotPresent
1672+
## Optionally specify an array of imagePullSecrets (secrets must be manually created in the namespace)
1673+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
1674+
## Example:
1675+
## pullSecrets:
1676+
## - myRegistryKeySecretName
1677+
##
1678+
pullSecrets: []
1679+
## @param waitForBackend.command The command to execute in the wait-for-backend container
1680+
##
1681+
command:
1682+
- /bin/bash
1683+
- -ec
1684+
## @param waitForBackend.args Override wait-for-backend container args
1685+
##
1686+
args:
1687+
- |
1688+
deployment=${DEPLOYMENT_NAME:?deployment name is missing}
1689+
return_code=0
1690+
1691+
echo "Waiting for deployment \"${deployment}\" to be successfully rolled out..."
1692+
kubectl rollout status deployment "$deployment" 2>&1 || return_code=$?
1693+
echo "Rollout exit code: '${return_code}'"
1694+
exit $return_code
1695+
## waitForBackend containers' Security Context (init container).
1696+
## ref: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/#set-the-security-context-for-a-container
1697+
## @param waitForBackend.containerSecurityContext.enabled Enabled containers' Security Context
1698+
## @param waitForBackend.containerSecurityContext.seLinuxOptions [object,nullable] Set SELinux options in container
1699+
## @param waitForBackend.containerSecurityContext.runAsUser Set containers' Security Context runAsUser
1700+
## @param waitForBackend.containerSecurityContext.runAsGroup Set containers' Security Context runAsGroup
1701+
## @param waitForBackend.containerSecurityContext.runAsNonRoot Set container's Security Context runAsNonRoot
1702+
## @param waitForBackend.containerSecurityContext.privileged Set container's Security Context privileged
1703+
## @param waitForBackend.containerSecurityContext.readOnlyRootFilesystem Set container's Security Context readOnlyRootFilesystem
1704+
## @param waitForBackend.containerSecurityContext.allowPrivilegeEscalation Set container's Security Context allowPrivilegeEscalation
1705+
## @param waitForBackend.containerSecurityContext.capabilities.drop List of capabilities to be dropped
1706+
## @param waitForBackend.containerSecurityContext.seccompProfile.type Set container's Security Context seccomp profile
1707+
##
1708+
containerSecurityContext:
1709+
enabled: true
1710+
seLinuxOptions: {}
1711+
runAsUser: 1001
1712+
runAsGroup: 1001
1713+
runAsNonRoot: true
1714+
privileged: false
1715+
readOnlyRootFilesystem: true
1716+
allowPrivilegeEscalation: false
1717+
capabilities:
1718+
drop: ["ALL"]
1719+
seccompProfile:
1720+
type: "RuntimeDefault"
1721+
## Init container resource requests and limits.
1722+
## ref: https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/
1723+
## We usually recommend not to specify default resources and to leave this as a conscious
1724+
## choice for the user. This also increases chances charts run on environments with little
1725+
## resources, such as Minikube. If you do want to specify resources, uncomment the following
1726+
## lines, adjust them as necessary, and remove the curly braces after 'resources:'.
1727+
## @param waitForBackend.resourcesPreset Set container resources according to one common preset (allowed values: none, nano, micro, small, medium, large, xlarge, 2xlarge). This is ignored if waitForBackend.resources is set (waitForBackend.resources is recommended for production).
1728+
## More information: https://github.com/bitnami/charts/blob/main/bitnami/common/templates/_resources.tpl#L15
1729+
##
1730+
resourcesPreset: "nano"
1731+
## @param waitForBackend.resources Set container requests and limits for different resources like CPU or memory (essential for production workloads)
1732+
## Example:
1733+
## resources:
1734+
## requests:
1735+
## cpu: 2
1736+
## memory: 512Mi
1737+
## limits:
1738+
## cpu: 3
1739+
## memory: 1024Mi
1740+
##
1741+
resources: {}

0 commit comments

Comments
 (0)