-
Notifications
You must be signed in to change notification settings - Fork 212
Bug 1710172: lib/resourcemerge: Remove containers from existing based on required #178
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
Bug 1710172: lib/resourcemerge: Remove containers from existing based on required #178
Conversation
1630720 to
f698d4f
Compare
|
This surprises me that we dont do this |
|
ping @abhinavdahiya @crawford |
f698d4f to
b7e52bc
Compare
lib/resourcemerge/core.go
Outdated
| } | ||
| } | ||
| } | ||
| existing.Containers = requiredContainers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this (and the existing logic) square with the PodSpec docs':
Containers cannot currently be added or removed.
Is there wrapping logic that removes the previous pod if modified and adds a new Pod with the new PodSpec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A new pod will get created as part of deployment redeploy. So container will not be deleted from existing pod. Yes, the wrapping logic is deployment rollout.
|
@vikaschoudhary16: This pull request references a valid Bugzilla bug. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
Can you add a unit test for this new behavior. After that we can merge this |
b7e52bc to
8853dd0
Compare
lib/resourcemerge/core_test.go
Outdated
| expected: corev1.PodSpec{}, | ||
| }, | ||
| { | ||
| name: "remove regular containers from existing but dont remove init containers", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not clear on why we want this. If "modified" means "launch a replacement Pod", then I'd expect we want to set modified and remove entries from InitContainers that weren't in the new required PodSpec. I've floated 8c83b0c with an implementation that you can squash into your branch if that makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was trying to play safe and do minimal changes which are required for the issue that i have been trying to fix.
Updated with changes from your commit. Thanks a lot!
8853dd0 to
4f4a65a
Compare
|
/approve I'll wait for @abhinavdahiya to confirm that we want the |
lib/resourcemerge/core_test.go
Outdated
|
|
||
| if !equality.Semantic.DeepEqual(test.existing, test.expected) { | ||
| t.Errorf("mismatch PodSpec got: %v want: %v", test.existing, test.expected) | ||
| t.Errorf("mismatch PodSpec got:\n%s\nwant:\n%s", yamlOrDie(test.existing), yamlOrDie(test.expected)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to using the k8s lib (which we already vendor).
|
/lgtm |
|
@wking @abhinavdahiya Following seems to be the problem: Does not seem to be related to the changes. Thoughts? |
|
/retest |
4f4a65a to
12b9310
Compare
12b9310 to
7be5d44
Compare
|
/test e2e-aws-upgrade |
8a250cf to
2f055c4
Compare
|
/test integration |
|
integration job is failing unrelated to the PR changes, #211 |
lib/resourcemerge/core_test.go
Outdated
| } | ||
|
|
||
| func yamlOrDie(data interface{}) string { | ||
| bytes, err := yaml.Marshal(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is no longer required. Right?
lib/resourcemerge/core.go
Outdated
| for j, existingContainer := range *existing { | ||
| if existingContainer.Name == requiredContainer.Name { | ||
| existingCurr = &(*existing)[j] | ||
| ensureContainer(modified, existingCurr, requiredContainer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, Won't these containers already be ensured from previous loop??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right. But above, it dint work because existingContainer is a local variable and changes to that does not update the slice existing. Will fix, thanks!
2f055c4 to
cfaef5f
Compare
cfaef5f to
3d1ad76
Compare
|
/approve Working on getting integration tests fixed. so keeping the hold. |
|
/test integration |
|
/retest |
|
/hold cancel /lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: abhinavdahiya, vikaschoudhary16, wking The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Avoid:
$ go test ./lib/resourcemerge/
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 38 [running]:
testing.tRunner.func1(0xc0001ab000)
.../sdk/go1.12.9/src/testing/testing.go:830 +0x392
panic(0xccb520, 0x163f880)
.../sdk/go1.12.9/src/runtime/panic.go:522 +0x1b5
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensureContainers(0xc0000bbd57, 0xc0001d4040, 0xc0001cd760, 0x1, 0x1)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:69 +0x840
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensurePodSpec(0xc0001c5d57, 0xc0001d4010, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0001cd760, 0x1, ...)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:28 +0xc6
github.com/openshift/cluster-version-operator/lib/resourcemerge.TestEnsurePodSpec.func1(0xc0001ab000)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core_test.go:276 +0xc7
testing.tRunner(0xc0001ab000, 0xc0001d8770)
.../sdk/go1.12.9/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
.../sdk/go1.12.9/src/testing/testing.go:916 +0x35a
FAIL github.com/openshift/cluster-version-operator/lib/resourcemerge 0.010s
(with the core_test.go but the old core.go) when removing an entry
mutated the existing slice without re-entering the:
for i, whatever := range *existing
With this commit, we iterate from the back of the existing slice, so
any removals affect indexes that we've already covered. For both
containers and service ports, any appends happen later in the
function, so we don't need to worry about slice expansion at this
point.
The buggy logic was originally from 3d1ad76 (Remove containers if
requested in Update, 2019-04-26, openshift#178).
Avoid:
$ go test ./lib/resourcemerge/
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 38 [running]:
testing.tRunner.func1(0xc0001ab000)
.../sdk/go1.12.9/src/testing/testing.go:830 +0x392
panic(0xccb520, 0x163f880)
.../sdk/go1.12.9/src/runtime/panic.go:522 +0x1b5
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensureContainers(0xc0000bbd57, 0xc0001d4040, 0xc0001cd760, 0x1, 0x1)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:69 +0x840
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensurePodSpec(0xc0001c5d57, 0xc0001d4010, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0001cd760, 0x1, ...)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:28 +0xc6
github.com/openshift/cluster-version-operator/lib/resourcemerge.TestEnsurePodSpec.func1(0xc0001ab000)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core_test.go:276 +0xc7
testing.tRunner(0xc0001ab000, 0xc0001d8770)
.../sdk/go1.12.9/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
.../sdk/go1.12.9/src/testing/testing.go:916 +0x35a
FAIL github.com/openshift/cluster-version-operator/lib/resourcemerge 0.010s
(with the core_test.go but the old core.go) when removing an entry
mutated the existing slice without re-entering the:
for i, whatever := range *existing
With this commit, we iterate from the back of the existing slice, so
any removals affect indexes that we've already covered. For both
containers and service ports, any appends happen later in the
function, so we don't need to worry about slice expansion at this
point.
The buggy logic was originally from 3d1ad76 (Remove containers if
requested in Update, 2019-04-26, openshift#178).
Avoid:
$ go test ./lib/resourcemerge/
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 38 [running]:
testing.tRunner.func1(0xc0001ab000)
.../sdk/go1.12.9/src/testing/testing.go:830 +0x392
panic(0xccb520, 0x163f880)
.../sdk/go1.12.9/src/runtime/panic.go:522 +0x1b5
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensureContainers(0xc0000bbd57, 0xc0001d4040, 0xc0001cd760, 0x1, 0x1)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:69 +0x840
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensurePodSpec(0xc0001c5d57, 0xc0001d4010, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0001cd760, 0x1, ...)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:28 +0xc6
github.com/openshift/cluster-version-operator/lib/resourcemerge.TestEnsurePodSpec.func1(0xc0001ab000)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core_test.go:276 +0xc7
testing.tRunner(0xc0001ab000, 0xc0001d8770)
.../sdk/go1.12.9/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
.../sdk/go1.12.9/src/testing/testing.go:916 +0x35a
FAIL github.com/openshift/cluster-version-operator/lib/resourcemerge 0.010s
(with the core_test.go but the old core.go) when removing an entry
mutated the existing slice without re-entering the:
for i, whatever := range *existing
With this commit, we iterate from the back of the existing slice, so
any removals affect indexes that we've already covered. For both
containers and service ports, any appends happen later in the
function, so we don't need to worry about slice expansion at this
point.
The buggy logic was originally from 3d1ad76 (Remove containers if
requested in Update, 2019-04-26, openshift#178).
This commit cherry-picks e8e80c2 (lib/resourcemerge/core: Fix panic
on container/port removal, 2019-12-16, openshift#282) back to the 4.2 branch.
But since f268b6d (Add support to EnsureServicePorts, 2019-11-25,
branch, I've only kept the container portion of e8e80c2 in this
commit.
Avoid:
$ go test ./lib/resourcemerge/
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 38 [running]:
testing.tRunner.func1(0xc0001ab000)
.../sdk/go1.12.9/src/testing/testing.go:830 +0x392
panic(0xccb520, 0x163f880)
.../sdk/go1.12.9/src/runtime/panic.go:522 +0x1b5
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensureContainers(0xc0000bbd57, 0xc0001d4040, 0xc0001cd760, 0x1, 0x1)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:69 +0x840
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensurePodSpec(0xc0001c5d57, 0xc0001d4010, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0001cd760, 0x1, ...)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:28 +0xc6
github.com/openshift/cluster-version-operator/lib/resourcemerge.TestEnsurePodSpec.func1(0xc0001ab000)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core_test.go:276 +0xc7
testing.tRunner(0xc0001ab000, 0xc0001d8770)
.../sdk/go1.12.9/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
.../sdk/go1.12.9/src/testing/testing.go:916 +0x35a
FAIL github.com/openshift/cluster-version-operator/lib/resourcemerge 0.010s
(with the core_test.go but the old core.go) when removing an entry
mutated the existing slice without re-entering the:
for i, whatever := range *existing
With this commit, we iterate from the back of the existing slice, so
any removals affect indexes that we've already covered. For both
containers and service ports, any appends happen later in the
function, so we don't need to worry about slice expansion at this
point.
The buggy logic was originally from 3d1ad76 (Remove containers if
requested in Update, 2019-04-26, openshift#178).
This commit cherry-picks e8e80c2 (lib/resourcemerge/core: Fix panic
on container/port removal, 2019-12-16, openshift#282) back to the 4.2 branch.
But since f268b6d (Add support to EnsureServicePorts, 2019-11-25, openshift#272)
and its EnsureServicePorts was never backported to the 4.2 branch,
I've only kept the container portion of e8e80c2 in this commit.
Avoid:
$ go test ./lib/resourcemerge/
panic: runtime error: index out of range [recovered]
panic: runtime error: index out of range
goroutine 38 [running]:
testing.tRunner.func1(0xc0001ab000)
.../sdk/go1.12.9/src/testing/testing.go:830 +0x392
panic(0xccb520, 0x163f880)
.../sdk/go1.12.9/src/runtime/panic.go:522 +0x1b5
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensureContainers(0xc0000bbd57, 0xc0001d4040, 0xc0001cd760, 0x1, 0x1)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:69 +0x840
github.com/openshift/cluster-version-operator/lib/resourcemerge.ensurePodSpec(0xc0001c5d57, 0xc0001d4010, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc0001cd760, 0x1, ...)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core.go:28 +0xc6
github.com/openshift/cluster-version-operator/lib/resourcemerge.TestEnsurePodSpec.func1(0xc0001ab000)
.../lib/go/src/github.com/openshift/cluster-version-operator/lib/resourcemerge/core_test.go:276 +0xc7
testing.tRunner(0xc0001ab000, 0xc0001d8770)
.../sdk/go1.12.9/src/testing/testing.go:865 +0xc0
created by testing.(*T).Run
.../sdk/go1.12.9/src/testing/testing.go:916 +0x35a
FAIL github.com/openshift/cluster-version-operator/lib/resourcemerge 0.010s
(with the core_test.go but the old core.go) when removing an entry
mutated the existing slice without re-entering the:
for i, whatever := range *existing
With this commit, we iterate from the back of the existing slice, so
any removals affect indexes that we've already covered. For both
containers and service ports, any appends happen later in the
function, so we don't need to worry about slice expansion at this
point.
The buggy logic was originally from 3d1ad76 (Remove containers if
requested in Update, 2019-04-26, openshift#178).
This commit cherry-picks e8e80c2 (lib/resourcemerge/core: Fix panic
on container/port removal, 2019-12-16, openshift#282) back to the 4.2 branch.
But since f268b6d (Add support to EnsureServicePorts, 2019-11-25, openshift#272)
and its EnsureServicePorts was never backported to the 4.2 branch,
I've only kept the container portion of e8e80c2 in this commit.
lib does not remove containers from existing based on
Requiredwhile merging.Not sure, if this is by design or it is a bug. This PR is more for a discussion/clarification.