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

Implement updates of deployment when echo changes #33

Closed
wants to merge 1 commit into from

Conversation

AlexanderThaller
Copy link

Implements updating the replicas field for the deployment when the accociated echo resource gets updated.

Not sure if this the best approach.

Implements updating the replicas field for the deployment when the
accociated echo resource gets updated.
@Pscheidl
Copy link
Owner

Pscheidl commented Dec 2, 2023

Thank you for your contribution. I'll review tomorrow.

let deployment = deployment_api.get(&echo.name_any()).await?;

if deployment.spec.expect("expected spec to be set").replicas != Some(echo.spec.replicas) {
Ok(EchoAction::Update)
Copy link
Owner

Choose a reason for hiding this comment

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

There's a difference between patch and update, as described e.g. here https://kubernetes.io/docs/reference/using-api/api-concepts/#patch-and-apply

The action is named update, yet it performs a patch.


let deployment = deployment_api.get(&echo.name_any()).await?;

if deployment.spec.expect("expected spec to be set").replicas != Some(echo.spec.replicas) {
Copy link
Owner

Choose a reason for hiding this comment

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

This repository contains a minimalistic custom resource, with one field only. Even in this case, the kubernetes API should be allowed to handle the diff, not the application code. Kubernetes itself compares the resources using resource version (update) or checks for conflicts (patch).

The patched resource should simply be serialized and sent in an HTTP Patch request, and let Kubernetes handle the rest. Checking parts of the resource locally would be a bad practice in general. Between the version comparison and the HTTP request, yet another change to the resource can be applied.

https://kubernetes.io/docs/reference/using-api/api-concepts/#patch-and-apply

@Pscheidl Pscheidl self-requested a review December 4, 2023 14:17
@Pscheidl Pscheidl closed this Jan 21, 2024
@Pscheidl
Copy link
Owner

Closing due to inactivity. Feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants