mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #25035 from kargakis/remove-dead-factory-code
kubectl: remove dead factory code
This commit is contained in:
commit
76912008b4
@ -311,7 +311,6 @@ func NewAPIFactory() (*cmdutil.Factory, *testFactory, runtime.Codec) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
rf := cmdutil.NewFactory(nil)
|
rf := cmdutil.NewFactory(nil)
|
||||||
f.PodSelectorForObject = rf.PodSelectorForObject
|
|
||||||
f.MapBasedSelectorForObject = rf.MapBasedSelectorForObject
|
f.MapBasedSelectorForObject = rf.MapBasedSelectorForObject
|
||||||
f.PortsForObject = rf.PortsForObject
|
f.PortsForObject = rf.PortsForObject
|
||||||
f.LabelsForObject = rf.LabelsForObject
|
f.LabelsForObject = rf.LabelsForObject
|
||||||
|
@ -100,8 +100,6 @@ type Factory struct {
|
|||||||
HistoryViewer func(mapping *meta.RESTMapping) (kubectl.HistoryViewer, error)
|
HistoryViewer func(mapping *meta.RESTMapping) (kubectl.HistoryViewer, error)
|
||||||
// Returns a Rollbacker for changing the rollback version of the specified RESTMapping type or an error
|
// Returns a Rollbacker for changing the rollback version of the specified RESTMapping type or an error
|
||||||
Rollbacker func(mapping *meta.RESTMapping) (kubectl.Rollbacker, error)
|
Rollbacker func(mapping *meta.RESTMapping) (kubectl.Rollbacker, error)
|
||||||
// PodSelectorForObject returns the pod selector associated with the provided object
|
|
||||||
PodSelectorForObject func(object runtime.Object) (string, error)
|
|
||||||
// MapBasedSelectorForObject returns the map-based selector associated with the provided object. If a
|
// MapBasedSelectorForObject returns the map-based selector associated with the provided object. If a
|
||||||
// new set-based selector is provided, an error is returned if the selector cannot be converted to a
|
// new set-based selector is provided, an error is returned if the selector cannot be converted to a
|
||||||
// map-based selector
|
// map-based selector
|
||||||
@ -364,41 +362,6 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
|||||||
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, showLabels bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
|
Printer: func(mapping *meta.RESTMapping, noHeaders, withNamespace bool, wide bool, showAll bool, showLabels bool, absoluteTimestamps bool, columnLabels []string) (kubectl.ResourcePrinter, error) {
|
||||||
return kubectl.NewHumanReadablePrinter(noHeaders, withNamespace, wide, showAll, showLabels, absoluteTimestamps, columnLabels), nil
|
return kubectl.NewHumanReadablePrinter(noHeaders, withNamespace, wide, showAll, showLabels, absoluteTimestamps, columnLabels), nil
|
||||||
},
|
},
|
||||||
PodSelectorForObject: func(object runtime.Object) (string, error) {
|
|
||||||
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
|
||||||
switch t := object.(type) {
|
|
||||||
case *api.ReplicationController:
|
|
||||||
return kubectl.MakeLabels(t.Spec.Selector), nil
|
|
||||||
case *api.Pod:
|
|
||||||
if len(t.Labels) == 0 {
|
|
||||||
return "", fmt.Errorf("the pod has no labels and cannot be exposed")
|
|
||||||
}
|
|
||||||
return kubectl.MakeLabels(t.Labels), nil
|
|
||||||
case *api.Service:
|
|
||||||
if t.Spec.Selector == nil {
|
|
||||||
return "", fmt.Errorf("the service has no pod selector set")
|
|
||||||
}
|
|
||||||
return kubectl.MakeLabels(t.Spec.Selector), nil
|
|
||||||
case *extensions.Deployment:
|
|
||||||
selector, err := unversioned.LabelSelectorAsSelector(t.Spec.Selector)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("invalid label selector: %v", err)
|
|
||||||
}
|
|
||||||
return selector.String(), nil
|
|
||||||
case *extensions.ReplicaSet:
|
|
||||||
selector, err := unversioned.LabelSelectorAsSelector(t.Spec.Selector)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("failed to convert label selector to selector: %v", err)
|
|
||||||
}
|
|
||||||
return selector.String(), nil
|
|
||||||
default:
|
|
||||||
gvk, err := api.Scheme.ObjectKind(object)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return "", fmt.Errorf("cannot extract pod selector from %v", gvk)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MapBasedSelectorForObject: func(object runtime.Object) (string, error) {
|
MapBasedSelectorForObject: func(object runtime.Object) (string, error) {
|
||||||
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
||||||
switch t := object.(type) {
|
switch t := object.(type) {
|
||||||
|
@ -58,28 +58,6 @@ func TestNewFactoryNoFlagBindings(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPodSelectorForObject(t *testing.T) {
|
|
||||||
f := NewFactory(nil)
|
|
||||||
|
|
||||||
svc := &api.Service{
|
|
||||||
ObjectMeta: api.ObjectMeta{Name: "baz", Namespace: "test"},
|
|
||||||
Spec: api.ServiceSpec{
|
|
||||||
Selector: map[string]string{
|
|
||||||
"foo": "bar",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
expected := "foo=bar"
|
|
||||||
got, err := f.PodSelectorForObject(svc)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
if expected != got {
|
|
||||||
t.Fatalf("Selector mismatch! Expected %s, got %s", expected, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPortsForObject(t *testing.T) {
|
func TestPortsForObject(t *testing.T) {
|
||||||
f := NewFactory(nil)
|
f := NewFactory(nil)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user