mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #15766 from feihujiang/supportNamespaceSelectorInAllNamespacesEndpoint
Auto commit by PR queue bot
This commit is contained in:
commit
33dabe00a8
@ -98,12 +98,13 @@ func (rcStrategy) AllowUnconditionalUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ControllerToSelectableFields returns a label set that represents the object.
|
||||
// ControllerToSelectableFields returns a field set that represents the object.
|
||||
func ControllerToSelectableFields(controller *api.ReplicationController) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": controller.Name,
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(controller.ObjectMeta)
|
||||
controllerSpecificFieldsSet := fields.Set{
|
||||
"status.replicas": strconv.Itoa(controller.Status.Replicas),
|
||||
}
|
||||
return generic.MergeFieldsSets(objectMetaFieldsSet, controllerSpecificFieldsSet)
|
||||
}
|
||||
|
||||
// MatchController is the filter used by the generic etcd backend to route
|
||||
|
@ -102,9 +102,7 @@ func (daemonSetStrategy) AllowUnconditionalUpdate() bool {
|
||||
|
||||
// DaemonSetToSelectableFields returns a field set that represents the object.
|
||||
func DaemonSetToSelectableFields(daemon *extensions.DaemonSet) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": daemon.Name,
|
||||
}
|
||||
return generic.ObjectMetaFieldsSet(daemon.ObjectMeta)
|
||||
}
|
||||
|
||||
// MatchSetDaemon is the filter used by the generic etcd backend to route
|
||||
|
@ -74,9 +74,7 @@ func (deploymentStrategy) AllowUnconditionalUpdate() bool {
|
||||
|
||||
// DeploymentToSelectableFields returns a field set that represents the object.
|
||||
func DeploymentToSelectableFields(deployment *extensions.Deployment) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": deployment.Name,
|
||||
}
|
||||
return generic.ObjectMetaFieldsSet(deployment.ObjectMeta)
|
||||
}
|
||||
|
||||
// MatchDeployment is the filter used by the generic etcd backend to route
|
||||
|
@ -89,7 +89,5 @@ func EndpointsAttributes(obj runtime.Object) (objLabels labels.Set, objFields fi
|
||||
if !ok {
|
||||
return nil, nil, fmt.Errorf("invalid object type %#v", obj)
|
||||
}
|
||||
return endpoints.Labels, fields.Set{
|
||||
"metadata.name": endpoints.Name,
|
||||
}, nil
|
||||
return endpoints.Labels, generic.ObjectMetaFieldsSet(endpoints.ObjectMeta), nil
|
||||
}
|
||||
|
@ -79,8 +79,9 @@ func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, e
|
||||
if l == nil {
|
||||
l = labels.Set{}
|
||||
}
|
||||
return l, fields.Set{
|
||||
"metadata.name": event.Name,
|
||||
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(event.ObjectMeta)
|
||||
specificFieldsSet := fields.Set{
|
||||
"involvedObject.kind": event.InvolvedObject.Kind,
|
||||
"involvedObject.namespace": event.InvolvedObject.Namespace,
|
||||
"involvedObject.name": event.InvolvedObject.Name,
|
||||
@ -90,5 +91,6 @@ func getAttrs(obj runtime.Object) (objLabels labels.Set, objFields fields.Set, e
|
||||
"involvedObject.fieldPath": event.InvolvedObject.FieldPath,
|
||||
"reason": event.Reason,
|
||||
"source": event.Source.Component,
|
||||
}, nil
|
||||
}
|
||||
return l, generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet), nil
|
||||
}
|
||||
|
@ -42,7 +42,10 @@ func testEvent(name string) *api.Event {
|
||||
|
||||
func TestGetAttrs(t *testing.T) {
|
||||
eventA := &api.Event{
|
||||
ObjectMeta: api.ObjectMeta{Name: "f0118"},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "f0118",
|
||||
Namespace: "default",
|
||||
},
|
||||
InvolvedObject: api.ObjectReference{
|
||||
Kind: "Pod",
|
||||
Name: "foo",
|
||||
@ -64,6 +67,7 @@ func TestGetAttrs(t *testing.T) {
|
||||
}
|
||||
expect := fields.Set{
|
||||
"metadata.name": "f0118",
|
||||
"metadata.namespace": "default",
|
||||
"involvedObject.kind": "Pod",
|
||||
"involvedObject.name": "foo",
|
||||
"involvedObject.namespace": "baz",
|
||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package generic
|
||||
|
||||
import (
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/fields"
|
||||
"k8s.io/kubernetes/pkg/labels"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@ -25,6 +26,22 @@ import (
|
||||
// AttrFunc returns label and field sets for List or Watch to compare against, or an error.
|
||||
type AttrFunc func(obj runtime.Object) (label labels.Set, field fields.Set, err error)
|
||||
|
||||
// ObjectMetaFieldsSet returns a fields set that represents the ObjectMeta.
|
||||
func ObjectMetaFieldsSet(objectMeta api.ObjectMeta) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": objectMeta.Name,
|
||||
"metadata.namespace": objectMeta.Namespace,
|
||||
}
|
||||
}
|
||||
|
||||
// MergeFieldsSets merges a fields'set from fragment into the source.
|
||||
func MergeFieldsSets(source fields.Set, fragment fields.Set) fields.Set {
|
||||
for k, value := range fragment {
|
||||
source[k] = value
|
||||
}
|
||||
return source
|
||||
}
|
||||
|
||||
// SelectionPredicate implements a generic predicate that can be passed to
|
||||
// GenericRegistry's List or Watch methods. Implements the Matcher interface.
|
||||
type SelectionPredicate struct {
|
||||
|
@ -93,11 +93,9 @@ func (ingressStrategy) AllowUnconditionalUpdate() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IngressToSelectableFields returns a label set that represents the object.
|
||||
// IngressToSelectableFields returns a field set that represents the object.
|
||||
func IngressToSelectableFields(ingress *extensions.Ingress) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": ingress.Name,
|
||||
}
|
||||
return generic.ObjectMetaFieldsSet(ingress.ObjectMeta)
|
||||
}
|
||||
|
||||
// MatchIngress is the filter used by the generic etcd backend to ingress
|
||||
|
@ -97,10 +97,11 @@ func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object
|
||||
|
||||
// JobSelectableFields returns a field set that represents the object for matching purposes.
|
||||
func JobToSelectableFields(job *extensions.Job) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": job.Name,
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(job.ObjectMeta)
|
||||
specificFieldsSet := fields.Set{
|
||||
"status.successful": strconv.Itoa(job.Status.Succeeded),
|
||||
}
|
||||
return generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet)
|
||||
}
|
||||
|
||||
// MatchJob is the filter used by the generic etcd backend to route
|
||||
|
@ -144,10 +144,11 @@ func MatchNamespace(label labels.Selector, field fields.Selector) generic.Matche
|
||||
|
||||
// NamespaceToSelectableFields returns a label set that represents the object
|
||||
func NamespaceToSelectableFields(namespace *api.Namespace) labels.Set {
|
||||
return labels.Set{
|
||||
"metadata.name": namespace.Name,
|
||||
"status.phase": string(namespace.Status.Phase),
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(namespace.ObjectMeta)
|
||||
specificFieldsSet := fields.Set{
|
||||
"status.phase": string(namespace.Status.Phase),
|
||||
// This is a bug, but we need to support it for backward compatibility.
|
||||
"name": namespace.Name,
|
||||
}
|
||||
return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet))
|
||||
}
|
||||
|
@ -104,9 +104,10 @@ func MatchPersistentVolumes(label labels.Selector, field fields.Selector) generi
|
||||
|
||||
// PersistentVolumeToSelectableFields returns a label set that represents the object
|
||||
func PersistentVolumeToSelectableFields(persistentvolume *api.PersistentVolume) labels.Set {
|
||||
return labels.Set{
|
||||
"metadata.name": persistentvolume.Name,
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolume.ObjectMeta)
|
||||
specificFieldsSet := fields.Set{
|
||||
// This is a bug, but we need to support it for backward compatibility.
|
||||
"name": persistentvolume.Name,
|
||||
}
|
||||
return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet))
|
||||
}
|
||||
|
@ -104,9 +104,10 @@ func MatchPersistentVolumeClaim(label labels.Selector, field fields.Selector) ge
|
||||
|
||||
// PersistentVolumeClaimToSelectableFields returns a label set that represents the object
|
||||
func PersistentVolumeClaimToSelectableFields(persistentvolumeclaim *api.PersistentVolumeClaim) labels.Set {
|
||||
return labels.Set{
|
||||
"metadata.name": persistentvolumeclaim.Name,
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(persistentvolumeclaim.ObjectMeta)
|
||||
specificFieldsSet := fields.Set{
|
||||
// This is a bug, but we need to support it for backward compatibility.
|
||||
"name": persistentvolumeclaim.Name,
|
||||
}
|
||||
return labels.Set(generic.MergeFieldsSets(objectMetaFieldsSet, specificFieldsSet))
|
||||
}
|
||||
|
@ -163,14 +163,15 @@ func MatchPod(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||
}
|
||||
}
|
||||
|
||||
// PodToSelectableFields returns a label set that represents the object
|
||||
// PodToSelectableFields returns a field set that represents the object
|
||||
// TODO: fields are not labels, and the validation rules for them do not apply.
|
||||
func PodToSelectableFields(pod *api.Pod) fields.Set {
|
||||
return fields.Set{
|
||||
"metadata.name": pod.Name,
|
||||
objectMetaFieldsSet := generic.ObjectMetaFieldsSet(pod.ObjectMeta)
|
||||
podSpecificFieldsSet := fields.Set{
|
||||
"spec.nodeName": pod.Spec.NodeName,
|
||||
"status.phase": string(pod.Status.Phase),
|
||||
}
|
||||
return generic.MergeFieldsSets(objectMetaFieldsSet, podSpecificFieldsSet)
|
||||
}
|
||||
|
||||
// ResourceGetter is an interface for retrieving resources by ResourceLocation.
|
||||
|
@ -107,7 +107,5 @@ func MatchResourceQuota(label labels.Selector, field fields.Selector) generic.Ma
|
||||
|
||||
// ResourceQuotaToSelectableFields returns a label set that represents the object
|
||||
func ResourceQuotaToSelectableFields(resourcequota *api.ResourceQuota) labels.Set {
|
||||
return labels.Set{
|
||||
"metadata.name": resourcequota.Name,
|
||||
}
|
||||
return labels.Set(generic.ObjectMetaFieldsSet(resourcequota.ObjectMeta))
|
||||
}
|
||||
|
@ -86,7 +86,5 @@ func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {
|
||||
|
||||
// SelectableFields returns a label set that represents the object
|
||||
func SelectableFields(obj *api.ServiceAccount) labels.Set {
|
||||
return labels.Set{
|
||||
"metadata.name": obj.Name,
|
||||
}
|
||||
return labels.Set(generic.ObjectMetaFieldsSet(obj.ObjectMeta))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user