-
Notifications
You must be signed in to change notification settings - Fork 917
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
karmada-search: support field selector for corev1 resources #5801
Conversation
Welcome @SataQiu! It looks like this is your first PR to karmada-io/karmada 🎉 |
12f1f88
to
774d133
Compare
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #5801 +/- ##
==========================================
+ Coverage 43.00% 43.16% +0.15%
==========================================
Files 656 658 +2
Lines 55888 56006 +118
==========================================
+ Hits 24034 24173 +139
+ Misses 30308 30263 -45
- Partials 1546 1570 +24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Cool! Thanks~ |
var cacheScheme = runtime.NewScheme() | ||
|
||
func init() { | ||
// This is to ensure that the cache plugin can handle the field selectors for these resources. |
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.
Resources that are not listed here can't be processed, can they? So how do you determine which resources can be listed here? In other words, are there any plans to add resources that are not listed?
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.
Thanks @XiShanYongYe-Chang I checked the resource kinds of Kubernetes and the corev1 group is the most important and the most common used. Most definitions of fieldSelector are in the corev1 group. IMO, we should support the corev1 resource kinds first, and the other resource types can be gradually added based on community feedback.
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.
In other words, are there any plans to add resources that are not listed?
There are two ways to handle this:
-
According to users feedback, support more resource types, such as apps, these can be added in subsequent PRs
-
Waiting for the Kubernetes runtime scheme package to support automatic ConversionFuncs registration, the community is trying to remove the legacyscheme
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.
@SataQiu, thanks for your quick reply!
Where does the Kubernetes community maintain Corev1 resources?
Waiting for the Kubernetes runtime scheme package to support automatic ConversionFuncs registration, the community is trying to remove the legacyscheme
Is the Kuberenetes community working on this plan? Do we have to rely on this plan to add resources in the future?
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.
Where does the Kubernetes community maintain Corev1 resources?
Is the Kuberenetes community working on this plan? Do we have to rely on this plan to add resources in the future?
We don't have to rely on community plan.
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.
Let me understand method two again, which means that when the upstream community implements this, other resources will automatically support it, and we don't need to register additional conversion functions. Am I right?
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.
Yes, you understand correctly.
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.
Thanks~
According to users feedback, support more resource types, such as apps, these can be added in subsequent PRs
I think we can do what you say. In addition, can you help create an issue to track this task, and if we don't get feedback on other resources for a long time, we may be able to proactively plan in the future.
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 it be better if we added a comment to the file stating that the implementation is referenced from xxx?
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.
Good idea, updated.
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.
Thanks a lot~
_ = cacheScheme.AddFieldLabelConversionFunc(corev1.SchemeGroupVersion.WithKind("Event"), | ||
func(label, value string) (string, string, error) { | ||
switch label { | ||
case "involvedObject.kind", | ||
"involvedObject.namespace", | ||
"involvedObject.name", | ||
"involvedObject.uid", | ||
"involvedObject.apiVersion", | ||
"involvedObject.resourceVersion", | ||
"involvedObject.fieldPath", | ||
"reason", | ||
"reportingComponent", | ||
"source", | ||
"type", | ||
"metadata.namespace", | ||
"metadata.name": | ||
return label, value, nil | ||
default: | ||
return "", "", fmt.Errorf("field label not supported: %s", label) | ||
} | ||
}, | ||
) | ||
_ = cacheScheme.AddFieldLabelConversionFunc(corev1.SchemeGroupVersion.WithKind("Namespace"), | ||
func(label, value string) (string, string, error) { | ||
switch label { | ||
case "status.phase", | ||
"metadata.name": | ||
return label, value, nil | ||
default: | ||
return "", "", fmt.Errorf("field label not supported: %s", label) | ||
} | ||
}, | ||
) | ||
_ = cacheScheme.AddFieldLabelConversionFunc(corev1.SchemeGroupVersion.WithKind("Secret"), | ||
func(label, value string) (string, string, error) { | ||
switch label { | ||
case "type", | ||
"metadata.namespace", | ||
"metadata.name": | ||
return label, value, nil | ||
default: | ||
return "", "", fmt.Errorf("field label not supported: %s", label) | ||
} | ||
}, | ||
) |
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.
For these methods, can we directly import Kubernetes open functions?
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.
Emm... I guess we can't, because these functions are defined in the k/k repository, but we can't import it directly, which is not recommended.
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.
Okay, I get it. It doesn't exit in the https://github.com/kubernetes/api repo.
_ = cacheScheme.AddFieldLabelConversionFunc(corev1.SchemeGroupVersion.WithKind("Service"), | ||
func(label, value string) (string, string, error) { | ||
switch label { | ||
case "metadata.namespace", | ||
"metadata.name", | ||
"spec.clusterIP", | ||
"spec.type": | ||
return label, value, nil | ||
default: | ||
return "", "", fmt.Errorf("field label not supported: %s", label) | ||
} | ||
}, | ||
) |
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.
I don't seem to find any service code in the Kubernetes repository. Can you point it out?
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.
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.
Although the AddFieldLabelConversionsForService
function is exported, we can't use it because we can't import k8s.io/kubernetes/...
directly.
https://github.com/kubernetes/kubernetes/tree/master?tab=readme-ov-file#to-start-using-k8s
To use Kubernetes code as a library in other applications, see the list of published components. Use of the k8s.io/kubernetes module or k8s.io/kubernetes/... packages as libraries is not supported.
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.
Oh, I can see why I can't find it, it hasn't existed since version 1.31 and my code is still in v1.28.
774d133
to
3876d97
Compare
Thanks~ |
lgtm |
@XiShanYongYe-Chang need approve, PTAL! |
Let's wait for a review from @RainbowMango Hi @SataQiu, are you using Karmada now? |
/assign |
Just for an advice, we can organize code in kubernetes style:
scheme.go: package cache
import (
corev1 "github.com/karmada-io/karmada/pkg/search/proxy/framework/plugins/cache/apis/core/v1"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
)
var cacheScheme = runtime.NewScheme()
func init() {
AddToScheme(cacheScheme)
}
func AddToScheme(scheme *runtime.Scheme) {
utilruntime.Must(corev1.AddToScheme(scheme))
} apis/core/v1/register.go: package v1
import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
)
var SchemeGroupVersion = corev1.SchemeGroupVersion
var (
SchemeBuilder = runtime.NewSchemeBuilder(addConversionFuncs)
AddToScheme = SchemeBuilder.AddToScheme
) conversion.go: // copy it from kubernetes
func addConversionFuncs(scheme *runtime.Scheme) error {
...
} |
3876d97
to
056daa5
Compare
056daa5
to
84816c8
Compare
Signed-off-by: SataQiu <[email protected]>
84816c8
to
c9e6ce5
Compare
ping @ikaven1024 |
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
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
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: RainbowMango, yanfeng1992 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 |
What type of PR is this?
/kind feature
What this PR does / why we need it:
karmada-search: support field selector for corev1 resources.
This supports most scenarios that use fieldSelector, such as finding a list of pods by node name.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
without this patch:
with this patch:
# kubectl get pod --kubeconfig karmada-search.config --field-selector="spec.nodeName=member1-worker" example-app-6c847589df-xmjm5 2024-10-29T03:15:25Z ...
Does this PR introduce a user-facing change?: