mirror of https://github.com/k3s-io/k3s
kubectl expose should extract ports from service
parent
d397d88499
commit
242910e57c
|
@ -634,9 +634,13 @@ __EOF__
|
|||
kubectl expose rc frontend --port=80 --name=frontend-4 --generator=service/v1 "${kube_flags[@]}"
|
||||
# Post-condition: service exists and the port is named default.
|
||||
kube::test::get_object_assert 'service frontend-4' "{{$port_name}} {{$port_field}}" 'default 80'
|
||||
# Verify that expose service works without specifying a port.
|
||||
kubectl expose service frontend --name=frontend-5 "${kube_flags[@]}"
|
||||
# Post-condition: service exists with the same port as the original service.
|
||||
kube::test::get_object_assert 'service frontend-5' "{{$port_field}}" '80'
|
||||
# Cleanup services
|
||||
kubectl delete pod valid-pod "${kube_flags[@]}"
|
||||
kubectl delete service frontend{,-2,-3,-4} "${kube_flags[@]}"
|
||||
kubectl delete service frontend{,-2,-3,-4,-5} "${kube_flags[@]}"
|
||||
|
||||
### Perform a rolling update with --image
|
||||
# Command
|
||||
|
|
|
@ -177,9 +177,9 @@ func NewFactory(optionalClientConfig clientcmd.ClientConfig) *Factory {
|
|||
return getPorts(t.Spec.Template.Spec), nil
|
||||
case *api.Pod:
|
||||
return getPorts(t.Spec), nil
|
||||
case *api.Service:
|
||||
return getServicePorts(t.Spec), nil
|
||||
default:
|
||||
// TODO: support extracting ports from service:
|
||||
// https://github.com/GoogleCloudPlatform/kubernetes/issues/11392
|
||||
_, kind, err := api.Scheme.ObjectVersionAndKind(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -263,6 +263,15 @@ func getPorts(spec api.PodSpec) []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(servicePort.Port))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
type clientSwaggerSchema struct {
|
||||
c *client.Client
|
||||
t runtime.ObjectTyper
|
||||
|
|
Loading…
Reference in New Issue