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

KEP-27: Detailed pod restart control by dependencies hash #1483

Merged
merged 21 commits into from
May 5, 2020

Conversation

ANeumann82
Copy link
Member

@ANeumann82 ANeumann82 commented Apr 24, 2020

What this PR does / why we need it:

  • Restart pods from a deployment or stateful set only if the pod template spec or any of the used config maps or secrets are changed.
  • Removes the last-plan-execution-uid from the pod template spec
  • Calculate a hash from all used resources in a pod template spec and adds that to trigger pod restarts

Fixes #1424 #1036

Documention: kudobuilder/kudo.dev#238

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Reorganize code

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
@gerred
Copy link
Member

gerred commented Apr 24, 2020

@ANeumann82 I'll get this reviewed, sorry for the delay!

@gerred gerred self-assigned this Apr 24, 2020
Added unit test
Moved kuttl test to e2e, deployments won't work with integration

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Copy link
Contributor

@zen-dog zen-dog left a comment

Choose a reason for hiding this comment

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

Nice work! 👏
I left a few comments, most of them are nits. I'd like to question the use of metav1.Object and the resulting reflection in the form of reflect.TypeOf. Aren't we better using the Unstructured and the GetObjectKind() method to build keys/cache/sort especially because the enhancer already converts all passed objects to unstructered?

pkg/controller/instance/instance_controller.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
Copy link
Member

@nfnt nfnt left a comment

Choose a reason for hiding this comment

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

The hash dependency handling looks fine, I'm mostly worried about compatibility with older and newer API versions of Kubernetes objects. This is handled with Group/Version/Kind of runtime objects and we should do the same instead of using Go reflection. This will complicate functions like setTemplateHash but will also ensure that operators don't break when using different API versions of resources.

pkg/engine/renderer/dependencies_test.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
@ANeumann82 ANeumann82 requested a review from nfnt April 29, 2020 15:50
Adjusted e2e test

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Copy link
Contributor

@zen-dog zen-dog left a comment

Choose a reason for hiding this comment

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

Aside from a few nits, my only wish would be to have more unit test coverage. Lower test levels - higher development speed 😉

pkg/engine/renderer/dependencies.go Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Outdated Show resolved Hide resolved
pkg/engine/renderer/dependencies.go Show resolved Hide resolved
pkg/engine/renderer/enhancer.go Outdated Show resolved Hide resolved
pkg/engine/renderer/enhancer.go Show resolved Hide resolved
pkg/engine/renderer/enhancer.go Outdated Show resolved Hide resolved
pkg/engine/renderer/enhancer_test.go Outdated Show resolved Hide resolved
assert.Equal(t, "929a2dffa86ad2460fdcf72977998bd0", hash, "Hashes are not the same")
assert.True(t, ok, "Statefulset contains no dependency hash field")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to see more test coverage on the unit test level. For example, could you add a test, where a parameter change leads to a hash change (where a hash is already set)? And could you also through in an independent object (e.g. a Deployment) and check that the hash is not set on it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added unit tests, let me know if you have another idea for one.

Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Copy link
Contributor

@zen-dog zen-dog left a comment

Choose a reason for hiding this comment

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

A few testing nits but this is great work! Definitely a release highlight (and needs some better PR description showcasing the greatness)! 👏

pkg/engine/renderer/dependencies_test.go Outdated Show resolved Hide resolved
assert.Nil(t, hash, "Pod template spec annotations contains a dependency hash but no dependencies")
}

func TestEnhancerApply_dependencyHash_changes(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: for long tests like this, which go through multiple states ginkgo might offer a better structure (and closer to scalatest). Take a look at the instance_admission_integration_test.go

@zen-dog zen-dog added the release/highlight This PR is a highlight for the next release label May 4, 2020
Signed-off-by: Andreas Neumann <aneumann@mesosphere.com>
Copy link
Member

@nfnt nfnt left a comment

Choose a reason for hiding this comment

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

LGTM!
Using Kubernetes's own typing mechanism instead of reflection makes this more abstract and, IMO, less readable but keeps us compatible with possible API changes.

@ANeumann82 ANeumann82 merged commit 1d1a9c1 into master May 5, 2020
@ANeumann82 ANeumann82 deleted the an/kep-27-dependencies-hash branch May 5, 2020 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release/highlight This PR is a highlight for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fine control over when Pods in a StatefulSet are restarted
4 participants