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

[DEVHAS-528] Add validating webhook for build-nudges-ref #401

Merged
merged 4 commits into from
Oct 28, 2023

Conversation

johnmcollier
Copy link
Member

@johnmcollier johnmcollier commented Oct 23, 2023

What does this PR do?:

This PR adds changes to the Component's validating webhook to handle the build-nudges-ref field:

  • If any nudged components belong to a different application, an error is returned and the create/update operation is blocked
  • If any nudged components refer to the nudging component, either directly or indirectly, an error is returned and the operation is blocked

This PR also adds back the stub Default() functions for the Application and Component webhooks, as they were accidentally removed when migrating the webhooks from application-api. These functions will be needed to implement mutating webhooks as part of DEVHAS-529

Which issue(s)/story(ies) does this PR fixes:

https://issues.redhat.com/browse/DEVHAS-528

PR acceptance criteria:

  • Unit/Functional tests

  • Documentation

N/A

  • Client Impact

N/A

How to test changes / Special notes to the reviewer:

Signed-off-by: John Collier <jcollier@redhat.com>
Signed-off-by: John Collier <jcollier@redhat.com>
Signed-off-by: John Collier <jcollier@redhat.com>
controllers/webhooks/component_webhook.go Outdated Show resolved Hide resolved
return fmt.Errorf("component %s cannot be added to spec.build-nudges-ref as it belongs to a different application", nudgedComponentName)
}

err = r.validateBuildNudgesRefGraph(ctx, nudgedComponent.Spec.BuildNudgesRef, componentNamespace, componentName, componentApp)
Copy link
Contributor

Choose a reason for hiding this comment

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

in this case, it only checks the component being created. so I guess we assumes the created components have no ref cycles?
That makes sense actually.
just thinking any other edge cases can bypass the check and result in any cycles?

Copy link
Member Author

Choose a reason for hiding this comment

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

in this case, it only checks the component being created. so I guess we assumes the created components have no ref cycles?

Yes, we don't validate other created components, as the webhook should have already validated those components when they were first created. It saves CPU cycles on a webhook that needs to complete before the resource can be created

Co-authored-by: Stephanie Cao <yangcao@redhat.com>
Copy link
Contributor

@yangcao77 yangcao77 left a comment

Choose a reason for hiding this comment

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

change looks good

@openshift-ci
Copy link

openshift-ci bot commented Oct 27, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: johnmcollier, yangcao77

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [johnmcollier,yangcao77]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@johnmcollier johnmcollier merged commit 7078934 into redhat-appstudio:main Oct 28, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants