mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-11-12 21:40:29 +00:00
remove portsforobject from factory
This commit is contained in:
@@ -82,8 +82,6 @@ type ClientAccessFactory interface {
|
||||
// new set-based selector is provided, an error is returned if the selector cannot be converted to a
|
||||
// map-based selector
|
||||
MapBasedSelectorForObject(object runtime.Object) (string, error)
|
||||
// PortsForObject returns the ports associated with the provided object
|
||||
PortsForObject(object runtime.Object) ([]string, error)
|
||||
// ProtocolsForObject returns the <port, protocol> mapping associated with the provided object
|
||||
ProtocolsForObject(object runtime.Object) (map[string]string, error)
|
||||
|
||||
@@ -111,8 +109,6 @@ type ClientAccessFactory interface {
|
||||
Generators(cmdName string) map[string]kubectl.Generator
|
||||
// Check whether the kind of resources could be exposed
|
||||
CanBeExposed(kind schema.GroupKind) error
|
||||
// Check whether the kind of resources could be autoscaled
|
||||
CanBeAutoscaled(kind schema.GroupKind) error
|
||||
}
|
||||
|
||||
// ObjectMappingFactory holds the second level of factory methods. These functions depend upon ClientAccessFactory methods.
|
||||
@@ -178,16 +174,6 @@ func makePortsString(ports []api.ServicePort, useNodePort bool) string {
|
||||
return strings.Join(pieces, ",")
|
||||
}
|
||||
|
||||
func getPorts(spec api.PodSpec) []string {
|
||||
result := []string{}
|
||||
for _, container := range spec.Containers {
|
||||
for _, port := range container.Ports {
|
||||
result = append(result, strconv.Itoa(int(port.ContainerPort)))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func getProtocols(spec api.PodSpec) map[string]string {
|
||||
result := make(map[string]string)
|
||||
for _, container := range spec.Containers {
|
||||
@@ -198,15 +184,6 @@ func getProtocols(spec api.PodSpec) map[string]string {
|
||||
return result
|
||||
}
|
||||
|
||||
// Extracts the ports exposed by a service from the given service spec.
|
||||
func getServicePorts(spec api.ServiceSpec) []string {
|
||||
result := []string{}
|
||||
for _, servicePort := range spec.Ports {
|
||||
result = append(result, strconv.Itoa(int(servicePort.Port)))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// Extracts the protocols exposed by a service from the given service spec.
|
||||
func getServiceProtocols(spec api.ServiceSpec) map[string]string {
|
||||
result := make(map[string]string)
|
||||
|
||||
@@ -160,24 +160,6 @@ func (f *ring0Factory) MapBasedSelectorForObject(object runtime.Object) (string,
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ring0Factory) PortsForObject(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 getPorts(t.Spec.Template.Spec), nil
|
||||
case *api.Pod:
|
||||
return getPorts(t.Spec), nil
|
||||
case *api.Service:
|
||||
return getServicePorts(t.Spec), nil
|
||||
case *extensions.Deployment:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *extensions.ReplicaSet:
|
||||
return getPorts(t.Spec.Template.Spec), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("cannot extract ports from %T", object)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *ring0Factory) ProtocolsForObject(object runtime.Object) (map[string]string, error) {
|
||||
// TODO: replace with a swagger schema based approach (identify pod selector via schema introspection)
|
||||
switch t := object.(type) {
|
||||
@@ -488,17 +470,6 @@ func (f *ring0Factory) CanBeExposed(kind schema.GroupKind) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (f *ring0Factory) CanBeAutoscaled(kind schema.GroupKind) error {
|
||||
switch kind {
|
||||
case api.Kind("ReplicationController"), extensions.Kind("ReplicaSet"),
|
||||
extensions.Kind("Deployment"), apps.Kind("Deployment"), apps.Kind("ReplicaSet"):
|
||||
// nothing to do here
|
||||
default:
|
||||
return fmt.Errorf("cannot autoscale a %v", kind)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// this method exists to help us find the points still relying on internal types.
|
||||
func InternalVersionDecoder() runtime.Decoder {
|
||||
return legacyscheme.Codecs.UniversalDecoder()
|
||||
|
||||
@@ -28,37 +28,6 @@ import (
|
||||
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
|
||||
)
|
||||
|
||||
func TestPortsForObject(t *testing.T) {
|
||||
f := NewFactory(genericclioptions.NewTestConfigFlags())
|
||||
|
||||
pod := &api.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "baz", Namespace: "test", ResourceVersion: "12"},
|
||||
Spec: api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Ports: []api.ContainerPort{
|
||||
{
|
||||
ContainerPort: 101,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expected := sets.NewString("101")
|
||||
ports, err := f.PortsForObject(pod)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
got := sets.NewString(ports...)
|
||||
|
||||
if !expected.Equal(got) {
|
||||
t.Fatalf("Ports mismatch! Expected %v, got %v", expected, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtocolsForObject(t *testing.T) {
|
||||
f := NewFactory(genericclioptions.NewTestConfigFlags())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user