-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix: correctly delete proxy resources if namespace is not "kubevirt" #538
Conversation
Skipping CI for Draft Pull Request. |
f0b461c
to
18c793b
Compare
Cleanup() method of vm-console-proxy deletes resources from the correct namespace. Signed-off-by: Andrej Krejcir <akrejcir@redhat.com>
18c793b
to
b72b74f
Compare
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/test e2e-single-node-functests |
@akrejcir: No presubmit jobs available for kubevirt/ssp-operator@master In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@akrejcir: The following test failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
The /override ci/prow/e2e-single-node-functests |
@akrejcir: Overrode contexts on behalf of akrejcir: ci/prow/e2e-single-node-functests In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
ExpectResourceExists(route, request) | ||
|
||
delete(request.Instance.Annotations, EnableAnnotation) | ||
delete(request.Instance.Annotations, VmConsoleProxyNamespaceAnnotation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason of deleting VmConsoleProxyNamespaceAnnotation
if it's not going to be used in Reconcile
?
Then without deleting it, it makes sense to write it as: should remove resources from the namespace once enable annotation removed
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both annotations are for the proxy functionality, so I just deleted both.
We can improve it later, this PR is to unblock failing d/s tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
This looks okay to unblock testing but I'd like to see my two comments discussed and possibly resolved in follow ups if you have time.
}, PtrT interface { | ||
*T | ||
client.Object | ||
}, L any, T any](ctx context.Context, name string, cli client.Client, itemsFunc func(list PtrL) []T) ([]client.Object, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would love to see this simplified with better variable names if possible but that's something for a follow up as this works as expected at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately these Ptr*
type parameters are needed for creating generic objects and calling methods on them.
I would like to write it on one line like:
func findResourcesUsingLabels[PtrL interface { *L; client.ObjectList }, PtrT interface { *T; client.Object}, L any, T any](ctx context.Context, name string, cli client.Client, itemsFunc func(list PtrL) []T) ([]client.Object, error) {
But my IDE expands it automatically and I cannot turn it off.
I will try to simplify it. Do you have some suggestion?
} | ||
|
||
// Filtering in a loop instead of using a FieldSelector in the List() call. | ||
// It is only slightly inefficient, because all objects are already cached locally, so there is no API call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again something for a follow up but doesn't this duplicate what the client would be doing when using FieldSelector anyway? I didn't think it would fire off additional API calls to filter by fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, but it was easier to implement here because of the internals of the client.
We use the cached client from the controller-runtime
library. It watches and stores objects locally.
If we want to use a field selector for a specific type, we first need to add an index for the field name into the cache. These indexes are separate for every type of object [1].
I think the code would look like this:
const field = "metadata.name"
var indexerFunc client.IndexerFunc = func(object client.Object) []string {
return []string{object.GetName()}
}
mgr.GetFieldIndexer().IndexField(ctx, &v1.ServiceAccount{}, field, indexerFunc)
mgr.GetFieldIndexer().IndexField(ctx, &v1.ConfigMap{}, field, indexerFunc)
mgr.GetFieldIndexer().IndexField(ctx, &v1.Service{}, field, indexerFunc)
mgr.GetFieldIndexer().IndexField(ctx, &appsv1.Deployment{}, field, indexerFunc)
mgr.GetFieldIndexer().IndexField(ctx, &routev1.Route{}, field, indexerFunc)
I haven't tested it, so maybe it's incorrect.
I didn't like that we need to register the index for each type separately.
[1] -
ssp-operator/vendor/sigs.k8s.io/controller-runtime/pkg/client/interfaces.go
Lines 187 to 198 in 862a7ef
// FieldIndexer knows how to index over a particular "field" such that it | |
// can later be used by a field selector. | |
type FieldIndexer interface { | |
// IndexFields adds an index with the given field name on the given object type | |
// by using the given function to extract the value for that field. If you want | |
// compatibility with the Kubernetes API server, only return one key, and only use | |
// fields that the API server supports. Otherwise, you can return multiple keys, | |
// and "equality" in the field selector means that at least one key matches the value. | |
// The FieldIndexer will automatically take care of indexing over namespace | |
// and supporting efficient all-namespace queries. | |
IndexField(ctx context.Context, obj Object, field string, extractValue IndexerFunc) error | |
} |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: lyarwood 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:
Approvers can indicate their approval by writing |
/cherry-pick release-v0.17 |
@akrejcir: #538 failed to apply on top of branch "release-v0.17":
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
What this PR does / why we need it:
Cleanup()
method of vm-console-proxy deletes resources from the correct namespace.Release note: