Skip to content

Commit

Permalink
Merge pull request #821 from jlandowner/template-webhook2
Browse files Browse the repository at this point in the history
Add Template webhook to check the same name Template and ClusterTemplate is not accepted
  • Loading branch information
oruharo authored May 22, 2024
2 parents 08fe232 + 5185c55 commit a905c8c
Show file tree
Hide file tree
Showing 30 changed files with 1,638 additions and 87 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ all: manager cosmoctl dashboard
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
ifeq ($(QUICK_BUILD),no)
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./internal/webhooks" output:crd:artifacts:config=config/crd/bases
endif

.PHONY: generate
Expand Down
6 changes: 3 additions & 3 deletions charts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
HELM = ../bin/helm
KUSTOMIZE = ../bin/kustomize

all: crd cosmo-username-headers-addon.yaml webhook.yaml

helm:
make -C ../ helm

Expand All @@ -19,8 +21,6 @@ test: chartsnap helm helm-dependency-update
test-list:
grep -R '{{[-|] if .*}}' cosmo/templates/* | grep .Values | awk -F':' '{print $$2}' | sed -n 's/.*\(.Values[^ ]*\).*/\1/p' | tr -d ')' | sort | uniq | awk -F'.Values.' '{print $$2}' > cosmo/test/if-values.list

update-charts: crd cosmo-username-headers-addon.yaml webhook.yaml

crd:
cp ../config/crd/bases/* cosmo/crds/

Expand All @@ -40,6 +40,6 @@ webhook.yaml:
$(KUSTOMIZE) build ../config/webhook-chart \
| sed -e 's/namespace: system/namespace: {{ .Release.Namespace }}/g' \
| sed -z 's;apiVersion: v1\nkind: Service\nmetadata:\n name: cosmo-webhook-service\n namespace: {{ .Release.Namespace }}\nspec:\n ports:\n - port: 443\n targetPort: 9443\n selector:\n control-plane: controller-manager\n---;{{ $$tls := fromYaml ( include "cosmo.webhook.gen-certs" . ) }}\n---\n{{- if $$.Values.controllerManager.webhook.enabled }};g' \
| sed -z 's;creationTimestamp: null;{{- if $$.Values.certManager.enabled }}\n annotations:\n cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cosmo-webhook-cert\n {{- end }}\n labels:\n {{- include "cosmo.labels" . | nindent 4 }};g' \
| sed -z 's;metadata:\n;metadata:\n{{- if $$.Values.certManager.enabled }}\n annotations:\n cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cosmo-webhook-cert\n {{- end }}\n labels:\n {{- include "cosmo.labels" . | nindent 4 }}\n;g' \
| sed -z 's;clientConfig:;clientConfig:\n caBundle: {{ if not $$.Values.certManager.enabled -}}{{ $$tls.caCert }}{{- else -}}Cg=={{ end }};g' > $(WEBHOOK_CHART_YAML)
echo '{{- end }}' >> $(WEBHOOK_CHART_YAML)
56 changes: 50 additions & 6 deletions charts/cosmo/templates/controller-manager/webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
{{- if $.Values.certManager.enabled }}
{{- if $.Values.certManager.enabled }}
annotations:
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cosmo-webhook-cert
{{- end }}
Expand All @@ -22,7 +22,7 @@ webhooks:
namespace: {{ .Release.Namespace }}
path: /mutate-cosmo-workspace-github-io-v1alpha1-instance
failurePolicy: Fail
name: minstance.kb.io
name: mclusterinstance.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
Expand All @@ -32,7 +32,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- instances
- clusterinstances
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -44,7 +44,7 @@ webhooks:
namespace: {{ .Release.Namespace }}
path: /mutate-cosmo-workspace-github-io-v1alpha1-instance
failurePolicy: Fail
name: mclusterinstance.kb.io
name: minstance.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
Expand All @@ -54,7 +54,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- clusterinstances
- instances
sideEffects: None
- admissionReviewVersions:
- v1
Expand Down Expand Up @@ -104,7 +104,7 @@ webhooks:
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
{{- if $.Values.certManager.enabled }}
{{- if $.Values.certManager.enabled }}
annotations:
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/cosmo-webhook-cert
{{- end }}
Expand Down Expand Up @@ -134,6 +134,28 @@ webhooks:
resources:
- clusterinstances
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
clientConfig:
caBundle: {{ if not $.Values.certManager.enabled -}}{{ $tls.caCert }}{{- else -}}Cg=={{ end }}
service:
name: cosmo-webhook-service
namespace: {{ .Release.Namespace }}
path: /validate-cosmo-workspace-github-io-v1alpha1-template
failurePolicy: Fail
name: vclustertemplate.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- clustertemplates
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
Expand All @@ -156,6 +178,28 @@ webhooks:
resources:
- instances
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
clientConfig:
caBundle: {{ if not $.Values.certManager.enabled -}}{{ $tls.caCert }}{{- else -}}Cg=={{ end }}
service:
name: cosmo-webhook-service
namespace: {{ .Release.Namespace }}
path: /validate-cosmo-workspace-github-io-v1alpha1-template
failurePolicy: Fail
name: vtemplate.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- templates
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,23 @@ rules:
- get
- list
- watch
- apiGroups:
- events.k8s.io
resources:
- events
verbs:
- get
- list
- watch
- apiGroups:
- authentication.k8s.io
resources:
- tokenreviews
verbs:
- create
- get
- list
- watch
---
# Source: cosmo/charts/traefik/templates/rbac/clusterrolebinding.yaml
kind: ClusterRoleBinding
Expand Down Expand Up @@ -530,6 +547,10 @@ spec:
port: 8443
protocol: TCP
targetPort: 8443
- name: incluster-insecure-server
port: 8080
protocol: TCP
targetPort: 8080
selector:
cosmo-workspace.github.io: dashboard
app.kubernetes.io/instance: chartsnap
Expand Down Expand Up @@ -833,6 +854,8 @@ spec:
- --timeout-seconds=5
- --tls-key=/app/cert/tls.key
- --tls-cert=/app/cert/tls.crt
- --ca-cert=/app/cert/ca.crt
- --incluster-port=8080
command:
- /app/dashboard
image: "ghcr.io/cosmo-workspace/cosmo-dashboard:v1.0.0-rc5"
Expand Down Expand Up @@ -922,6 +945,7 @@ metadata:
name: cosmo-dashboard-cert
namespace: cosmo-system
spec:
commonName: cosmo-dashboard.cosmo-system.svc.cluster.local
dnsNames:
- cosmo-dashboard.cosmo-system.svc
- cosmo-dashboard.cosmo-system.svc.cluster.local
Expand Down Expand Up @@ -1029,7 +1053,7 @@ webhooks:
namespace: cosmo-system
path: /mutate-cosmo-workspace-github-io-v1alpha1-instance
failurePolicy: Fail
name: minstance.kb.io
name: mclusterinstance.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
Expand All @@ -1039,7 +1063,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- instances
- clusterinstances
sideEffects: None
- admissionReviewVersions:
- v1
Expand All @@ -1051,7 +1075,7 @@ webhooks:
namespace: cosmo-system
path: /mutate-cosmo-workspace-github-io-v1alpha1-instance
failurePolicy: Fail
name: mclusterinstance.kb.io
name: minstance.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
Expand All @@ -1061,7 +1085,7 @@ webhooks:
- CREATE
- UPDATE
resources:
- clusterinstances
- instances
sideEffects: None
- admissionReviewVersions:
- v1
Expand Down Expand Up @@ -1173,6 +1197,28 @@ webhooks:
resources:
- clusterinstances
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
clientConfig:
caBundle: Cg==
service:
name: cosmo-webhook-service
namespace: cosmo-system
path: /validate-cosmo-workspace-github-io-v1alpha1-template
failurePolicy: Fail
name: vclustertemplate.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- clustertemplates
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
Expand All @@ -1195,6 +1241,28 @@ webhooks:
resources:
- instances
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
clientConfig:
caBundle: Cg==
service:
name: cosmo-webhook-service
namespace: cosmo-system
path: /validate-cosmo-workspace-github-io-v1alpha1-template
failurePolicy: Fail
name: vtemplate.kb.io
rules:
- apiGroups:
- cosmo-workspace.github.io
apiVersions:
- v1alpha1
operations:
- CREATE
- UPDATE
resources:
- templates
sideEffects: None
- admissionReviewVersions:
- v1
- v1alpha1
Expand Down
Loading

0 comments on commit a905c8c

Please sign in to comment.