Skip to content
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

Make CanBeExposed and CanBeAutoscaled composable #15951

Merged
merged 1 commit into from
Oct 27, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions pkg/kubectl/cmd/util/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kind of like how previously the error noted what can be accepted. Could that be added back into the error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually one of the reasons behind this change. We don't follow this pattern elsewhere in the factory (hardcoding supported types in error messages) and this is already known because it exists in the help string:

expose_long = `Take a replication controller, service or pod and expose it as a new Kubernetes Service.

}
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
},
Expand Down