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

Add an option for tasks to mutate the State object #2528

Merged
merged 1 commit into from
Dec 8, 2022

Conversation

xmudrii
Copy link
Member

@xmudrii xmudrii commented Dec 8, 2022

What this PR does / why we need it:

We have a task to determine the pause image by asking kubeadm what pause image we should use:

func determinePauseImage(s *state.State) error {
if rc := s.Cluster.RegistryConfiguration; rc == nil || rc.OverwriteRegistry == "" {
return nil
}
s.Logger.Infoln("Determining Kubernetes pause image...")
return s.RunTaskOnLeader(determinePauseImageExecutor)
}
func determinePauseImageExecutor(s *state.State, node *kubeoneapi.HostConfig, conn executor.Interface) error {
cmd, err := scripts.KubeadmPauseImageVersion(s.Cluster.Versions.Kubernetes)
if err != nil {
return err
}
out, _, err := s.Runner.RunRaw(cmd)
if err != nil {
return fail.SSH(err, "getting kubeadm PauseImage version")
}
s.PauseImage = s.Cluster.RegistryConfiguration.ImageRegistry("registry.k8s.io") + "/pause:" + out
return nil
}

The output from kubeadm is taken and the State object is updated by using state.PauseImage = .... However, that doesn't work because when running a task, we're creating a shallow copy of the State object and we use that one for running the task:

ctx := s.Clone()

Copying the State object is required because we might be running a task concurrently and multiple goroutines editing the same struct concurrently is never a good idea. But we still need a way to mutate the State from a task, for example, in this case, the only way to get the pause image is to ask kubeadm.

This issue is addressed by adding a state mutator function to the task executor (RunTaskOnNodes). This mutator function is guarded with a mutex so that it's safe to run it concurrently. This PR also integrates this mutator into a task responsible for getting the pause image, so this is now supposed to work properly.

What type of PR is this?

/kind bug

Does this PR introduce a user-facing change? Then add your Release Note here:

Use the pause image from `registry.k8s.io` for all Kubernetes releases

Documentation:

NONE

Signed-off-by: Marko Mudrinić <mudrinic.mare@gmail.com>
@xmudrii xmudrii added the backport-needed Denotes a PR or issue that has not been fully backported. label Dec 8, 2022
@xmudrii xmudrii requested a review from embik December 8, 2022 13:45
@kubermatic-bot kubermatic-bot added kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. docs/none Denotes a PR that doesn't need documentation (changes). dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 8, 2022
@xmudrii
Copy link
Member Author

xmudrii commented Dec 8, 2022

/cherrypick release/v1.5

@kubermatic-bot
Copy link
Contributor

@xmudrii: once the present PR merges, I will cherry-pick it on top of release/v1.5 in a new PR and assign it to you.

In response to this:

/cherrypick release/v1.5

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.

@xmudrii
Copy link
Member Author

xmudrii commented Dec 8, 2022

/cherrypick release/v1.4

@kubermatic-bot
Copy link
Contributor

@xmudrii: once the present PR merges, I will cherry-pick it on top of release/v1.4 in a new PR and assign it to you.

In response to this:

/cherrypick release/v1.4

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.

@kubermatic-bot kubermatic-bot added the lgtm Indicates that a PR is ready to be merged. label Dec 8, 2022
@kubermatic-bot
Copy link
Contributor

LGTM label has been added.

Git tree hash: 1a19b608c6e286857a15e6661488b6f400eb85cb

Copy link
Member

@ahmedwaleedmalik ahmedwaleedmalik left a comment

Choose a reason for hiding this comment

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

/approve

@kubermatic-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmedwaleedmalik

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubermatic-bot kubermatic-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 8, 2022
@kubermatic-bot kubermatic-bot merged commit 2e12000 into main Dec 8, 2022
@kubermatic-bot kubermatic-bot added this to the KubeOne 1.6 milestone Dec 8, 2022
@kubermatic-bot kubermatic-bot deleted the state-mutator branch December 8, 2022 14:53
@kubermatic-bot
Copy link
Contributor

@xmudrii: new pull request created: #2529

In response to this:

/cherrypick release/v1.5

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.

@kubermatic-bot
Copy link
Contributor

@xmudrii: #2528 failed to apply on top of branch "release/v1.4":

Applying: Add an option for tasks to mutate the State object
Using index info to reconstruct a base tree...
M	pkg/state/task.go
M	pkg/tasks/kubeadm_config.go
M	pkg/tasks/tasks.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/tasks/tasks.go
CONFLICT (content): Merge conflict in pkg/tasks/tasks.go
Auto-merging pkg/tasks/kubeadm_config.go
CONFLICT (content): Merge conflict in pkg/tasks/kubeadm_config.go
Auto-merging pkg/state/task.go
CONFLICT (content): Merge conflict in pkg/state/task.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Add an option for tasks to mutate the State object
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

In response to this:

/cherrypick release/v1.4

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.

@xmudrii xmudrii added backport-complete Denotes a PR or issue which has been fully backported to all required release branches. and removed backport-needed Denotes a PR or issue that has not been fully backported. labels Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. backport-complete Denotes a PR or issue which has been fully backported to all required release branches. dco-signoff: yes Denotes that all commits in the pull request have the valid DCO signoff message. docs/none Denotes a PR that doesn't need documentation (changes). kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants