From 4befdf5b499c119b996ae36f691e7f9eb70a8283 Mon Sep 17 00:00:00 2001 From: kargakis Date: Tue, 20 Oct 2015 17:50:20 +0200 Subject: [PATCH] Make CanBeExposed and CanBeAutoscaled composable --- hack/test-cmd.sh | 4 ++-- pkg/kubectl/cmd/util/factory.go | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/hack/test-cmd.sh b/hack/test-cmd.sh index 4646b69f915..51e4c82cb17 100755 --- a/hack/test-cmd.sh +++ b/hack/test-cmd.sh @@ -766,8 +766,8 @@ __EOF__ # Pre-condition: don't need # Command output_message=$(! kubectl expose nodes 127.0.0.1 2>&1 "${kube_flags[@]}") - # Post-condition: the error message has "invalid resource" string - kube::test::if_has_string "${output_message}" 'invalid resource' + # Post-condition: the error message has "cannot expose" string + kube::test::if_has_string "${output_message}" 'cannot expose' ### Try to generate a service with invalid name (exceeding maximum valid size) # Pre-condition: use --name flag diff --git a/pkg/kubectl/cmd/util/factory.go b/pkg/kubectl/cmd/util/factory.go index f2b8f67a33d..317d1178f0b 100644 --- a/pkg/kubectl/cmd/util/factory.go +++ b/pkg/kubectl/cmd/util/factory.go @@ -262,14 +262,21 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory { return generator, ok }, CanBeExposed: func(kind string) error { - if kind != "ReplicationController" && kind != "Service" && kind != "Pod" { - return fmt.Errorf("invalid resource provided: %v, only a replication controller, service or pod is accepted", kind) + switch kind { + case "ReplicationController", "Service", "Pod": + // nothing to do here + default: + return fmt.Errorf("cannot expose a %s", kind) } return nil }, - CanBeAutoscaled: func(kind string) error { // TODO: support autoscale for deployments - if kind != "ReplicationController" { - return fmt.Errorf("invalid resource provided: %v, only a replication controller is accepted", kind) + CanBeAutoscaled: func(kind string) error { + switch kind { + // TODO: support autoscale for deployments + case "ReplicationController": + // nothing to do here + default: + return fmt.Errorf("cannot autoscale a %s", kind) } return nil },