Service: Fix semantics for Update wrt allocations

It is not uncommon for users to Create a Service and not specify things
like ClusterIP and NodePort, which we then allocate for them.  They same
that YAML somewhere and later use it again in an Update, but then it
fails.

That's because we detected them trying to set a ClusterIP from a value
to "", which is not allowed.  If it was just NodePort, they would
actually succeed and reallocate a new port.

After this change, we try to "patch" updates where the user did not
specify those values from the old object.
This commit is contained in:
Tim Hockin
2021-07-06 18:05:19 -07:00
parent 818ed1afff
commit 80dda49ce2
3 changed files with 138 additions and 0 deletions

View File

@@ -155,6 +155,13 @@ func SetInternalTrafficPolicy(policy api.ServiceInternalTrafficPolicyType) Tweak
}
}
// SetExternalTrafficPolicy sets the externalTrafficPolicy field for a Service.
func SetExternalTrafficPolicy(policy api.ServiceExternalTrafficPolicyType) Tweak {
return func(svc *api.Service) {
svc.Spec.ExternalTrafficPolicy = policy
}
}
// SetAllocateLoadBalancerNodePorts sets the allocate LB node port field.
func SetAllocateLoadBalancerNodePorts(val bool) Tweak {
return func(svc *api.Service) {