Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Dynamic Admission Control for Application #1619

Merged
merged 3 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,29 @@ webhooks:
- UPDATE
resources:
- podspecworkloads

- clientConfig:
caBundle: Cg==
service:
name: {{ template "kubevela.name" . }}-webhook
namespace: {{ .Release.Namespace }}
path: /validating-core-oam-dev-v1beta1-applications
{{- if .Values.admissionWebhooks.patch.enabled }}
failurePolicy: Ignore
{{- else }}
failurePolicy: {{ .Values.admissionWebhooks.failurePolicy }}
{{- end }}
name: validating.core.oam.dev.v1beta1.applications
admissionReviewVersions:
- v1beta1
sideEffects: None
rules:
- apiGroups:
- core.oam.dev
apiVersions:
- v1beta1
operations:
- CREATE
- UPDATE
resources:
- applications
{{- end -}}
2 changes: 1 addition & 1 deletion e2e/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
svcName: map[string]interface{}{
"type": workloadType,
"image": "wordpress:php7.4-apache",
"port": "80",
"port": 80,
"cpu": "1",
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ func (h *ValidatingHandler) Handle(ctx context.Context, req admission.Request) a
if err := h.Decoder.DecodeRaw(req.AdmissionRequest.OldObject, oldApp); err != nil {
return admission.Errored(http.StatusBadRequest, err)
}

if allErrs := h.ValidateUpdate(ctx, app, oldApp); len(allErrs) > 0 {
return admission.Errored(http.StatusUnprocessableEntity, allErrs.ToAggregate())
if app.ObjectMeta.DeletionTimestamp.IsZero() {
if allErrs := h.ValidateUpdate(ctx, app, oldApp); len(allErrs) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if allErrs := h.ValidateUpdate(ctx, app, oldApp); len(allErrs) > 0 {
if len(h.ValidateUpdate(ctx, app, oldApp)) > 0 {

Better? :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cannot be modified here, because the following logic needs to return the error in allErrs

return admission.Errored(http.StatusUnprocessableEntity, allErrs.ToAggregate())
}
}
default:
// Do nothing for DELETE and CONNECT
Expand All @@ -98,5 +99,5 @@ func (h *ValidatingHandler) Handle(ctx context.Context, req admission.Request) a
// RegisterValidatingHandler will register application validate handler to the webhook
func RegisterValidatingHandler(mgr manager.Manager, args controller.Args) {
server := mgr.GetWebhookServer()
server.Register("/validating-core-oam-dev-v1alpha2-applications", &webhook.Admission{Handler: &ValidatingHandler{dm: args.DiscoveryMapper, pd: args.PackageDiscover}})
server.Register("/validating-core-oam-dev-v1beta1-applications", &webhook.Admission{Handler: &ValidatingHandler{dm: args.DiscoveryMapper, pd: args.PackageDiscover}})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happed if there the old webhook is already registered and running in a cluster?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, vela has never enable the Admission Control for Application

}
10 changes: 2 additions & 8 deletions test/e2e-test/definition_revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,7 @@ var _ = Describe("Test application of the specified definition version", func()
},
},
}
Expect(k8sClient.Patch(ctx, &app, client.Merge)).Should(Succeed())

apprev := &v1beta1.ApplicationRevision{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: fmt.Sprintf("%s-v3", appName)}, apprev)).Should(HaveOccurred())
Expect(k8sClient.Patch(ctx, &app, client.Merge)).Should(HaveOccurred())
})

It("Test deploy application which containing helm module", func() {
Expand Down Expand Up @@ -709,10 +706,7 @@ var _ = Describe("Test application of the specified definition version", func()
},
},
}
Expect(k8sClient.Patch(ctx, &app, client.Merge)).Should(Succeed())

apprev := &v1beta1.ApplicationRevision{}
Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: namespace, Name: fmt.Sprintf("%s-v3", appName)}, apprev)).Should(HaveOccurred())
Expect(k8sClient.Patch(ctx, &app, client.Merge)).Should(HaveOccurred())
})

})
Expand Down