-
Notifications
You must be signed in to change notification settings - Fork 38
fix: move managed resource VAP out of CRDinstaller #1202
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
66f06fb
Manage lifecycle of the VAP properly
tsujiri 140603d
Adjust the code
tsujiri 5bbffb8
Add logs and e2e test cases
tsujiri 323249f
Fix bugs and add more tests
tsujiri 3a20471
Avoid updating ResourceVersion
tsujiri 6166175
Preserve ObjectMeta.ResourceVersion
tsujiri 8541c2a
Fix lint
tsujiri 46bb179
Fix name gets overridden
tsujiri d38f3a7
Remove IsNotFound error check
tsujiri 203407e
Add explanation for complex test logics and TODO for refactoring
tsujiri f0ed0f4
Fix comments
tsujiri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ CROs | |
| NotIn | ||
| fo | ||
| allReady | ||
| AtLeast | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| Copyright (c) Microsoft Corporation. | ||
| Licensed under the MIT license. | ||
| */ | ||
|
|
||
| package managedresource | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| v1 "k8s.io/api/admissionregistration/v1" | ||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| "k8s.io/apimachinery/pkg/api/meta" | ||
| "k8s.io/klog/v2" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
| ) | ||
|
|
||
| func EnsureNoVAP(ctx context.Context, c client.Client, isHub bool) error { | ||
| objs := []client.Object{getValidatingAdmissionPolicy(isHub), getValidatingAdmissionPolicyBinding()} | ||
| for _, obj := range objs { | ||
| err := c.Delete(ctx, obj) | ||
| switch { | ||
| case err == nil, apierrors.IsNotFound(err): | ||
| // continue | ||
| case meta.IsNoMatchError(err): | ||
| klog.Infof("object type %T is not supported in this cluster, continuing", obj) | ||
| // continue | ||
| default: | ||
| klog.Errorf("Delete object type %T failed: %s", obj, err) | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func EnsureVAP(ctx context.Context, c client.Client, isHub bool) error { | ||
ryanzhang-oss marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| type vapObjectAndMutator struct { | ||
| obj client.Object | ||
| mutate func() error | ||
| } | ||
| // TODO: this can be simplified by dealing with the specific type rather than using client.Object | ||
| vap, mutateVAP := getVAPWithMutator(isHub) | ||
| vapb, mutateVAPB := getVAPBindingWithMutator() | ||
| objsAndMutators := []vapObjectAndMutator{ | ||
| { | ||
| obj: vap, | ||
| mutate: mutateVAP, | ||
| }, | ||
| { | ||
| obj: vapb, | ||
| mutate: mutateVAPB, | ||
| }, | ||
| } | ||
|
|
||
| for _, objectMutator := range objsAndMutators { | ||
| opResult, err := controllerutil.CreateOrUpdate(ctx, c, objectMutator.obj, objectMutator.mutate) | ||
| switch { | ||
| case err == nil: | ||
| // continue | ||
| case meta.IsNoMatchError(err): | ||
| klog.Infof("object type %T is not supported in this cluster, continuing", objectMutator.obj) | ||
| // continue | ||
| default: | ||
| klog.Errorf("CreateOrUpdate (operation: %s) for object type %T failed: %s", opResult, objectMutator.obj, err) | ||
| return err | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func getVAPWithMutator(isHub bool) (*v1.ValidatingAdmissionPolicy, func() error) { | ||
| vap := getValidatingAdmissionPolicy(isHub) | ||
| return vap, func() error { | ||
| mutateValidatingAdmissionPolicy(vap, isHub) | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func getVAPBindingWithMutator() (*v1.ValidatingAdmissionPolicyBinding, func() error) { | ||
| vapb := getValidatingAdmissionPolicyBinding() | ||
| return vapb, func() error { | ||
| mutateValidatingAdmissionPolicyBinding(vapb) | ||
| return nil | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.