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

Fix unintended change of Service.spec.ports[].nodePort during kubectl apply #24180

Merged
merged 1 commit into from
Apr 20, 2016
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
2 changes: 1 addition & 1 deletion pkg/api/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1784,7 +1784,7 @@ type LoadBalancerIngress struct {
type ServiceSpec struct {
// 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
Ports []ServicePort `json:"ports"`
Ports []ServicePort `json:"ports" patchStrategy:"merge" patchMergeKey:"port"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is fully backwards compatible, right?

Copy link
Member

Choose a reason for hiding this comment

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

@roberthbailey It will change patch and apply behavior for this resource, though the current behavior is unusable.

Copy link
Member

Choose a reason for hiding this comment

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

If someone did manage to workaround this problem and was using strategic merge patch, their patches should still work.

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks.


// 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.
Expand Down
19 changes: 19 additions & 0 deletions test/e2e/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,25 @@ var _ = framework.KubeDescribe("Kubectl client", func() {
By("checking the result")
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() {
Expand Down