Skip to content

Commit

Permalink
Improvie APPUiO compatibility
Browse files Browse the repository at this point in the history
Now with k8s 1.29.x and networkpolicy support.

Also installs espejo with a rule to create an approximation of APPUiO's
default network policies in each appcat namespace.
  • Loading branch information
Kidswiss committed Nov 7, 2024
1 parent 96327d3 commit 283fc85
Show file tree
Hide file tree
Showing 14 changed files with 629 additions and 3 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ appcat-apiserver: vshnpostgresql ## Install appcat-apiserver dependencies
vshnall: vshnpostgresql vshnredis

.PHONY: vshnpostgresql
vshnpostgresql: certmanager-setup stackgres-setup prometheus-setup minio-setup metallb-setup ## Install vshn postgres dependencies
vshnpostgresql: certmanager-setup stackgres-setup prometheus-setup minio-setup metallb-setup netpols-setup ## Install vshn postgres dependencies

.PHONY: vshnredis
vshnredis: certmanager-setup k8up-setup ## Install vshn redis dependencies
vshnredis: certmanager-setup k8up-setup netpols-setup ## Install vshn redis dependencies

.PHONY: help
help: ## Show this help
Expand Down Expand Up @@ -128,6 +128,7 @@ $(prometheus_sentinel): kind-setup-ingress
--values prometheus/values.yaml \
prometheus-community/kube-prometheus-stack
kubectl -n prometheus-system wait --for condition=Available deployment/kube-prometheus-kube-prome-operator --timeout 120s
kubectl apply -f prometheus/netpol.yaml
@echo -e "***\n*** Installed Prometheus in http://prometheus.127.0.0.1.nip.io:8088/ and AlertManager in http://alertmanager.127.0.0.1.nip.io:8088/.\n***"
@touch $@

Expand Down Expand Up @@ -175,3 +176,11 @@ unset-default-sc:
for sc in $$(kubectl get sc -o name) ; do \
kubectl patch $$sc -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'; \
done

netpols-setup: $(netpols_sentinel) ## Install netpols to simulate appuio's netpols

$(netpols_sentinel): export KUBECONFIG = $(KIND_KUBECONFIG)
$(netpols_sentinel):
kubectl apply -f netpols/sync.appuio.ch_syncconfigs.yaml
kubectl apply -f netpols
touch $@
3 changes: 2 additions & 1 deletion Makefile.vars.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local_pv_sentinel = $(kind_dir)/local_pv
csi_sentinel = $(kind_dir)/csi_provider
metallb_sentinel = $(kind_dir)/metallb
komoplane_sentinel = $(kind_dir)/komoplane
netpols_sentinel = $(kind_dir)/netpols
enable_xfn = true

PROJECT_ROOT_DIR = .
Expand All @@ -18,7 +19,7 @@ DOCKER_CMD ?= docker
## KIND:setup

# https://hub.docker.com/r/kindest/node/tags
KIND_NODE_VERSION ?= v1.28.9
KIND_NODE_VERSION ?= v1.29.7
KIND_IMAGE ?= docker.io/kindest/node:$(KIND_NODE_VERSION)
KIND_CMD ?= go run sigs.k8s.io/kind
KIND_KUBECONFIG ?= $(kind_dir)/kind-kubeconfig-$(KIND_NODE_VERSION)
Expand Down
6 changes: 6 additions & 0 deletions netpols/00_namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: Namespace
metadata:
labels:
control-plane: controller-manager
name: system
31 changes: 31 additions & 0 deletions netpols/leader_election_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# permissions to do leader election.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: leader-election-role
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch
- create
- update
- patch
- delete
- apiGroups:
- ""
resources:
- configmaps/finalizers
verbs:
- update
- apiGroups:
- ""
resources:
- events
verbs:
- create
- patch
12 changes: 12 additions & 0 deletions netpols/leader_election_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: leader-election-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: leader-election-role
subjects:
- kind: ServiceAccount
name: default
namespace: system
35 changes: 35 additions & 0 deletions netpols/manager.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: espejo
namespace: system
spec:
selector:
matchLabels:
control-plane: controller-manager
replicas: 1
template:
metadata:
labels:
control-plane: controller-manager
spec:
securityContext:
runAsUser: 65532
containers:
- name: operator
image: quay.io/vshn/espejo:v0.5.0
args:
- --enable-leader-election
resources:
limits:
cpu: 300m
memory: 100Mi
requests:
cpu: 20m
memory: 50Mi
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
terminationGracePeriodSeconds: 10
98 changes: 98 additions & 0 deletions netpols/netpol-controller.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kube-network-policies
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
verbs:
- list
- watch
- apiGroups:
- "networking.k8s.io"
resources:
- networkpolicies
verbs:
- list
- watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kube-network-policies
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kube-network-policies
subjects:
- kind: ServiceAccount
name: kube-network-policies
namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: kube-network-policies
namespace: kube-system
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: kube-network-policies
namespace: kube-system
labels:
tier: node
app: kube-network-policies
k8s-app: kube-network-policies
spec:
selector:
matchLabels:
app: kube-network-policies
template:
metadata:
labels:
tier: node
app: kube-network-policies
k8s-app: kube-network-policies
spec:
hostNetwork: true
dnsPolicy: ClusterFirst
nodeSelector:
kubernetes.io/os: linux
tolerations:
- operator: Exists
effect: NoSchedule
serviceAccountName: kube-network-policies
containers:
- name: kube-network-policies
image: registry.k8s.io/networking/kube-network-policies:v0.6.0
args:
- /bin/netpol
- --hostname-override=$(MY_NODE_NAME)
- --v=2
- --nfqueue-id=98
volumeMounts:
- name: lib-modules
mountPath: /lib/modules
readOnly: true
resources:
requests:
cpu: "100m"
memory: "50Mi"
securityContext:
privileged: true
capabilities:
add: ["NET_ADMIN"]
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumes:
- name: lib-modules
hostPath:
path: /lib/modules
73 changes: 73 additions & 0 deletions netpols/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: manager-role
rules:
- apiGroups:
- coordination.k8s.io
resources:
- leases
verbs:
- create
- get
- list
- update
- apiGroups:
- ""
resources:
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- ""
resources:
- namespaces/status
verbs:
- get
- apiGroups:
- ""
resources:
- events
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- sync.appuio.ch
resources:
- syncconfigs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- sync.appuio.ch
resources:
- syncconfigs/status
verbs:
- get
- patch
- update
- apiGroups:
- networking.k8s.io
resources:
- networkpolicies
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
12 changes: 12 additions & 0 deletions netpols/role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: manager-rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: manager-role
subjects:
- kind: ServiceAccount
name: default
namespace: system
Loading

0 comments on commit 283fc85

Please sign in to comment.