Skip to content

Commit

Permalink
Enable deletion of extra network policies in job (#167)
Browse files Browse the repository at this point in the history
* Enable deletion of extra network policies in job

Signed-off-by: Matias Charriere <[email protected]>

* bring pending changes from upstream

Signed-off-by: Matias Charriere <[email protected]>

---------

Signed-off-by: Matias Charriere <[email protected]>
  • Loading branch information
mcharriere authored Mar 26, 2024
1 parent 04ad13a commit 065e3cf
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 19 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Add safe-to-evict annotations to Hubble Relay and UI pods.

### Added

- Add helm values schema.

### Changed

- Add safe-to-evict annotations to Hubble Relay and UI pods.
- Enable deletion of extra network policies.

## [0.21.0] - 2024-02-29

### Added
Expand Down
8 changes: 7 additions & 1 deletion helm/cilium/templates/extra-policies/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{{- if or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled -}}
{{- if and .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.remove -}}
{{- fail "extraPolicies.allowEgressToCoreDNS.enabled and extraPolicies.remove cannot both be true" -}}
{{- end -}}
{{- if and .Values.extraPolicies.allowEgressToProxy.enabled .Values.extraPolicies.remove -}}
{{- fail "extraPolicies.allowEgressToProxy.enabled and extraPolicies.remove cannot both be true" -}}
{{- end -}}
{{- if or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled .Values.extraPolicies.remove -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand Down
26 changes: 19 additions & 7 deletions helm/cilium/templates/extra-policies/job.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{- if or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled -}}
{{- if or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled .Values.extraPolicies.remove }}
apiVersion: batch/v1
kind: Job
metadata:
name: cilium-create-extra-policies
name: cilium-{{ ternary "remove" "create" .Values.extraPolicies.remove }}-extra-policies
namespace: {{ .Release.Namespace }}
labels:
app: cilium-create-extra-policies
app: cilium-{{ ternary "remove" "create" .Values.extraPolicies.remove }}-extra-policies
annotations:
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "1"
Expand All @@ -15,7 +15,7 @@ spec:
template:
metadata:
labels:
app: cilium-create-extra-policies
app: cilium-{{ ternary "remove" "create" .Values.extraPolicies.remove }}-extra-policies
spec:
hostNetwork: true
restartPolicy: OnFailure
Expand Down Expand Up @@ -47,7 +47,7 @@ spec:
done
done
containers:
- name: cilium-create-extra-policies
- name: cilium-{{ ternary "remove" "create" .Values.extraPolicies.remove }}-extra-policies
image: "{{ .Values.image.registry }}/giantswarm/docker-kubectl:latest"
imagePullPolicy: IfNotPresent
volumeMounts:
Expand All @@ -60,5 +60,17 @@ spec:
- |
set -o errexit ; set -o xtrace ; set -o nounset
kubectl apply --server-side=true --field-manager='kubectl-client-side-apply' --force-conflicts -f /policies/ 2>&1
{{- end -}}
{{- if .Values.extraPolicies.remove }}
{{- range $_, $ns := $.Values.extraPolicies.allowEgressToCoreDNS.namespaces }}
{{ printf "kubectl delete cnp -n %s %s --ignore-not-found 2>&1" $ns "cilium-extra-policies-dns" }}
{{- end }}
{{- range $_, $ns := $.Values.extraPolicies.allowEgressToProxy.namespaces }}
{{ printf "kubectl delete cnp -n %s %s --ignore-not-found 2>&1" $ns "cilium-extra-policies-proxy" }}
{{- end }}
{{- else }}
kubectl \
apply \
--server-side=true --field-manager='kubectl-client-side-apply' --force-conflicts \
-f /policies/ 2>&1
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and (or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled) (not .Values.global.podSecurityStandards.enforced) -}}
{{- if and (or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled .Values.extraPolicies.remove) (not .Values.global.podSecurityStandards.enforced) -}}
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
Expand Down
3 changes: 2 additions & 1 deletion helm/cilium/templates/extra-policies/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled -}}
{{- if or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled .Values.extraPolicies.remove -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
Expand All @@ -12,6 +12,7 @@ rules:
verbs:
- patch
- create
- delete
- apiGroups:
- apiextensions.k8s.io
resources:
Expand Down
2 changes: 1 addition & 1 deletion helm/cilium/templates/extra-policies/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if and (or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled) .Values.serviceAccounts.extraPolicies.create -}}
{{- if and (or .Values.extraPolicies.allowEgressToCoreDNS.enabled .Values.extraPolicies.allowEgressToProxy.enabled .Values.extraPolicies.remove) .Values.serviceAccounts.extraPolicies.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
Expand Down
5 changes: 4 additions & 1 deletion helm/cilium/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2090,6 +2090,9 @@
},
"extraPolicies": {
"properties": {
"remove": {
"type": "boolean"
},
"allowEgressToCoreDNS": {
"properties": {
"enabled": {
Expand Down Expand Up @@ -5045,4 +5048,4 @@
},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object"
}
}
2 changes: 2 additions & 0 deletions helm/cilium/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3784,6 +3784,8 @@ defaultPolicies:
- operator: Exists

extraPolicies:
remove: false

allowEgressToCoreDNS:
enabled: false
namespaces:
Expand Down
2 changes: 2 additions & 0 deletions helm/cilium/values.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3781,6 +3781,8 @@ defaultPolicies:
- operator: Exists

extraPolicies:
remove: false

allowEgressToCoreDNS:
enabled: false
namespaces:
Expand Down
6 changes: 3 additions & 3 deletions vendir.lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ apiVersion: vendir.k14s.io/v1alpha1
directories:
- contents:
- git:
commitTitle: Backport helm schema from upstream (#20)
sha: 3e632da7ab56811ce7a430a86ca4274f385e9fd9
commitTitle: add some extra checks for extra policies deletion (#23)...
sha: d03ff1c98125211dbd4b243982ddde35192e9309
tags:
- 1.15.1-42-g3e632da7ab
- 1.15.1-45-gd03ff1c981
path: cilium
path: vendor
- contents:
Expand Down

0 comments on commit 065e3cf

Please sign in to comment.