Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Add an optional workload type field in the component workload spec. #198

Merged
merged 2 commits into from
Sep 11, 2020

Conversation

ryanzhang-oss
Copy link
Collaborator

@ryanzhang-oss ryanzhang-oss commented Sep 7, 2020

Use component webhooks to mutate and validate the component workload spec when workload "type" is used instead of a full CR.

Unit tests added

manually E2E tested

Copy link
Member

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

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

The idea is really good and interesting, This could also fix #182 I think.

@@ -139,5 +139,5 @@ func (h *ValidatingHandler) InjectDecoder(d *admission.Decoder) error {
// Register will regsiter application configuration validation to webhook
func Register(mgr manager.Manager) {
server := mgr.GetWebhookServer()
server.Register("/validating-applicationconfigurations", &webhook.Admission{Handler: &ValidatingHandler{}})
server.Register("/validating-core-oam-dev-v1alpha2-applicationconfigurations", &webhook.Admission{Handler: &ValidatingHandler{}})
Copy link
Member

Choose a reason for hiding this comment

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

I would vote for /v1alpha2/validating-applicationconfigurations if we want to add version in path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think we need to come up with a uniformed way for webhooks register in vela. Let's add a PR after this

}
if content[TypeField] != nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("workload"), obj.Spec.Workload,
fmt.Sprintf("the workload `%+v` is not a CR", obj.Spec.Workload)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fmt.Sprintf("the workload `%+v` is not a CR", obj.Spec.Workload)))
fmt.Sprintf("the workload `%+v` is not a K8s CR", obj.Spec.Workload)))


// ValidateUpdate validates the Component on update
func ValidateUpdate(r *v1alpha2.Component, _ *v1alpha2.Component) field.ErrorList {
validatelog.Info("validate update", "name", r.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Should validate the same thing like ValidateCreate

@ryanzhang-oss
Copy link
Collaborator Author

#195

@resouer
Copy link
Contributor

resouer commented Sep 9, 2020

Is this PR ready for review?

@ryanzhang-oss ryanzhang-oss force-pushed the add-workload-type branch 2 times, most recently from ad1378a to 3c01d27 Compare September 10, 2020 01:12
@ryanzhang-oss ryanzhang-oss changed the title [WIP] Add an optional workload type field in the component workload spec. Add an optional workload type field in the component workload spec. Sep 10, 2020
@ryanzhang-oss
Copy link
Collaborator Author

Is this PR ready for review?

The test took me some time to add

@ryanzhang-oss ryanzhang-oss force-pushed the add-workload-type branch 3 times, most recently from 8ffd901 to 36d9a48 Compare September 10, 2020 06:39
pkg/oam/util/helper.go Outdated Show resolved Hide resolved
Comment on lines +107 to +114
var _ inject.Client = &ValidatingHandler{}

// InjectClient injects the client into the ComponentValidatingHandler
func (h *ValidatingHandler) InjectClient(c client.Client) error {
h.Client = c
return nil
}
*/
Copy link
Member

Choose a reason for hiding this comment

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

don't we need them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not for the validating handler

Copy link
Member

@wonderflow wonderflow left a comment

Choose a reason for hiding this comment

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

Generally LGTM, good job

@ryanzhang-oss ryanzhang-oss force-pushed the add-workload-type branch 2 times, most recently from 9a35637 to 4224c23 Compare September 10, 2020 21:42
Signed-off-by: Ryan Zhang <yangzhangrice@hotmail.com>
Signed-off-by: Ryan Zhang <yangzhangrice@hotmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants