Skip to content

Commit

Permalink
Feature: webhook automation (#6)
Browse files Browse the repository at this point in the history
* feat: deployment webhook automation

Co-authored-by: Luca Terracciano <[email protected]>
  • Loading branch information
DragonBanana and lterrac authored Aug 3, 2021
1 parent 0a99a3a commit 7e2eac9
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 15 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ pkg/*/system-controller
pkg/*/edge-scheduler

.idea/
pkg/function-deployment-webhook/deploy/server-key.pem
pkg/function-deployment-webhook/deploy/server-cert.pem
pkg/function-deployment-webhook/deploy/admission-registration-subst.yaml
5 changes: 5 additions & 0 deletions config/cluster-conf/kind.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ nodes:
- role: worker
- role: worker
- role: worker
- role: worker
- role: worker
- role: worker
- role: worker
- role: worker
2 changes: 1 addition & 1 deletion config/deploy/allocation-algorithm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: allocation-algorithm
image: systemautoscaler/allocation-algorithm-rest:0.0.1
image: systemautoscaler/allocation-algorithm-rest:dev
imagePullPolicy: Always
ports:
- containerPort: 5000
Expand Down
2 changes: 1 addition & 1 deletion config/deploy/system-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ spec:
serviceAccountName: system-controller
containers:
- name: system-controller
image: systemautoscaler/system-controller:0.0.2
image: systemautoscaler/system-controller:dev
imagePullPolicy: Always
ports:
- containerPort: 443
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion config/permissions/community-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: community-controller
namespace: openfaas-fn
namespace: kube-system
apiGroup: ""
roleRef:
kind: ClusterRole
Expand Down
22 changes: 22 additions & 0 deletions example/figlet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: openfaas.com/v1
kind: Function
metadata:
creationTimestamp: "2021-07-19T21:22:34Z"
generation: 1
name: figlet
namespace: openfaas-fn
resourceVersion: "1689214"
selfLink: /apis/openfaas.com/v1/namespaces/openfaas-fn/functions/figlet
uid: 21b5f4f5-3315-40d6-a900-25b11bca95bb
spec:
image: ghcr.io/openfaas/figlet:latest
labels:
com.openfaas.scale.factor: "20"
com.openfaas.scale.max: "100"
com.openfaas.scale.min: "1"
com.openfaas.scale.zero: "false"
edgeautoscaler.polimi.it/scheduler: edge-autoscaler
name: figlet
readOnlyRootFilesystem: false
requests:
memory: 1M
4 changes: 2 additions & 2 deletions pkg/function-deployment-webhook/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM gcr.io/distroless/static:nonroot
LABEL name="Function Deployment Webhook"

COPY function-deployment-webhook /usr/local/bin/
COPY server-cert.pem .
COPY server-key.pem .
COPY ./deploy/server-cert.pem .
COPY ./deploy/server-key.pem .

CMD ["function-deployment-webhook"]
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
name: "openfaas-fn.function-deployment-custom-scheduler.svc"
name: "kube-system.function-deployment-custom-scheduler.svc"
webhooks:
- name: "openfaas-fn.function-deployment-custom-scheduler.svc"
- name: "kube-system.function-deployment-custom-scheduler.svc"
rules:
- apiGroups: ["*"]
apiVersions: ["*"]
Expand All @@ -12,11 +12,11 @@ webhooks:
scope: "Namespaced"
clientConfig:
service:
namespace: openfaas-fn
namespace: kube-system
name: function-deployment-custom-scheduler
path: /mutate
port: 8443
caBundle: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJeE1EWXhNREUwTlRZMU4xb1hEV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80R0tCbFlPczVjQVJZVXhnaUJyWUhGUQpZdXMxNWovMHZjclFhaXBJYm90ZzV2Ri9IWTdhSE5haGs2S29GRmNMSTBrdkd1R0NDVk5pMm9MWWJERT0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
caBundle: ${CA_BUNDLE}
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: Some
sideEffects: NoneOnDryRun
timeoutSeconds: 5
2 changes: 1 addition & 1 deletion pkg/function-deployment-webhook/deploy/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: openfaas-fn
namespace: kube-system
name: function-deployment-custom-scheduler
spec:
selector:
Expand Down
10 changes: 10 additions & 0 deletions pkg/function-deployment-webhook/deploy/gen-certificates.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ kubectl create secret generic ${secret} \
--dry-run -o yaml |
kubectl -n ${namespace} apply -f -


mv ${tmpdir}/server-key.pem $(dirname "$0")
mv ${tmpdir}/server-cert.pem $(dirname "$0")


chmod 777 $(dirname "$0")/server-key.pem
chmod 777 $(dirname "$0")/server-cert.pem



# run this file with
# the certificates are in a tmp directory
#./gen-certificates.sh --namespace openfaas-fn --service function-deployment-custom-scheduler --secret function-deployment-custom-scheduler
33 changes: 33 additions & 0 deletions pkg/function-deployment-webhook/deploy/instructions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
BASEDIR=$(dirname "$0")

# create cluster
# kind create cluster --config ./config/cluster-conf/kind.conf --image systemautoscaler/kindest-node:latest

# openfaas
# kubectl create ns openfaas
# kubectl create ns openfaas-fn
# helm install openfaas-kind openfaas/openfaas --namespace openfaas --set basic_auth=false --set functionNamespace=openfaas-fn --set operator.create=true

# otherwise install with arkade
# arkade install openfaas --operator

# crd
# make manifests
# kubectl apply -f ./config/crd/bases

# generate admission webhook certificates and secret in tmpdir
chmod +x $BASEDIR/gen-certificates.sh
$BASEDIR/gen-certificates.sh --namespace kube-system --service function-deployment-custom-scheduler --secret function-deployment-custom-scheduler

# patch new mutitating webhook
chmod +x $BASEDIR/patch-manifests.sh
$BASEDIR/patch-manifests.sh

# build docker image again
cd $BASEDIR/..
make dev

# apply manifests
kubectl apply -f $BASEDIR/deployment.yaml
kubectl apply -f $BASEDIR/service.yaml
kubectl apply -f $BASEDIR/admission-registration-subst.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ set -o pipefail

export CA_BUNDLE=$(kubectl get configmap -n kube-system extension-apiserver-authentication -o=jsonpath='{.data.client-ca-file}' | base64 | tr -d '\n')

if command -v envsubst >/dev/null 2>&1; then
envsubst
#if command -v envsubst >/dev/null 2>&1; then
if command -v envsubst; then
envsubst < $(dirname $0)/admission-registration.yaml > $(dirname $0)/admission-registration-subst.yaml
else
sed -e "s|\${CA_BUNDLE}|${CA_BUNDLE}|g"
fi
2 changes: 1 addition & 1 deletion pkg/function-deployment-webhook/deploy/service.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Service
metadata:
namespace: openfaas-fn
namespace: kube-system
name: function-deployment-custom-scheduler
labels:
app: function-deployment-custom-scheduler
Expand Down
2 changes: 1 addition & 1 deletion pkg/system-controller/pkg/controller/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func NewCommunityController(namespace, name string) *appsv1.Deployment {
return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Namespace: "kube-system",
Labels: map[string]string{
ealabels.CommunityControllerDeploymentLabel: "",
},
Expand Down

0 comments on commit 7e2eac9

Please sign in to comment.