Commit 3753e2bd authored by k8s-merge-robot's avatar k8s-merge-robot

Merge pull request #24180 from AdoHe/reuse_node_port

Automatic merge from submit-queue Fix unintended change of Service.spec.ports[].nodePort during kubectl apply Please refer #23551 for more detail. @bgrant0607 I think this simple fix should be ok to reuse nodePort. @thockin ptal. Release note: Fix unintended change of `Service.spec.ports[].nodePort` during `kubectl apply`.
parents f3f6ffaa 16960d3a
...@@ -1784,7 +1784,7 @@ type LoadBalancerIngress struct { ...@@ -1784,7 +1784,7 @@ type LoadBalancerIngress struct {
type ServiceSpec struct { type ServiceSpec struct {
// The list of ports that are exposed by this service. // The list of ports that are exposed by this service.
// More info: http://releases.k8s.io/HEAD/docs/user-guide/services.md#virtual-ips-and-service-proxies // More info: http://releases.k8s.io/HEAD/docs/user-guide/services.md#virtual-ips-and-service-proxies
Ports []ServicePort `json:"ports"` Ports []ServicePort `json:"ports" patchStrategy:"merge" patchMergeKey:"port"`
// This service will route traffic to pods having labels matching this selector. // This service will route traffic to pods having labels matching this selector.
// Label keys and values that must match in order to receive traffic for this service. // Label keys and values that must match in order to receive traffic for this service.
......
...@@ -574,6 +574,25 @@ var _ = framework.KubeDescribe("Kubectl client", func() { ...@@ -574,6 +574,25 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
By("checking the result") By("checking the result")
forEachReplicationController(c, ns, "app", "redis", validateReplicationControllerConfiguration) forEachReplicationController(c, ns, "app", "redis", validateReplicationControllerConfiguration)
}) })
It("should reuse nodePort when apply to an existing SVC", func() {
mkpath := func(file string) string {
return filepath.Join(framework.TestContext.RepoRoot, "examples/guestbook-go", file)
}
serviceJson := mkpath("redis-master-service.json")
nsFlag := fmt.Sprintf("--namespace=%v", ns)
By("creating Redis SVC")
framework.RunKubectlOrDie("create", "-f", serviceJson, nsFlag)
By("getting the original nodePort")
originalNodePort := framework.RunKubectlOrDie("get", "service", "redis-master", nsFlag, "-o", "jsonpath={.spec.ports[0].nodePort}")
By("applying the same configuration")
framework.RunKubectlOrDie("apply", "-f", serviceJson, nsFlag)
By("getting the nodePort after applying configuration")
currentNodePort := framework.RunKubectlOrDie("get", "service", "redis-master", nsFlag, "-o", "jsonpath={.spec.ports[0].nodePort}")
By("checking the result")
if originalNodePort != currentNodePort {
framework.Failf("nodePort should keep the same")
}
})
}) })
framework.KubeDescribe("Kubectl cluster-info", func() { framework.KubeDescribe("Kubectl cluster-info", func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment