-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Addons: helm based addons #21847
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
Merged
medyagh
merged 10 commits into
kubernetes:master
from
volatilemolotov:addons/helm_addon
Nov 21, 2025
Merged
Addons: helm based addons #21847
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
59ecb15
add support for helm based addons
volatilemolotov 1fe32a0
refactor helm install
volatilemolotov 3d9e4a2
add description to helmcommand and rename helminstall to helminstallb…
volatilemolotov 4779d97
refactor helm functions
volatilemolotov c3caac3
refactor helm functions - fix install and tests
volatilemolotov dd0222e
add documentation for the helm based addons
volatilemolotov 0ea2f09
add clarification comments on some implementation details, link docum…
volatilemolotov 00a2be2
add proper boilerplate
volatilemolotov 00cfd2b
replace link with relref
volatilemolotov fa4d670
run make fmt
volatilemolotov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package addons | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os/exec" | ||
| "path" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "k8s.io/minikube/pkg/minikube/assets" | ||
| "k8s.io/minikube/pkg/minikube/command" | ||
| "k8s.io/minikube/pkg/minikube/vmpath" | ||
| ) | ||
|
|
||
| // runs a helm install within the minikube vm or container based on the contents of chart *assets.HelmChart | ||
| func installHelmChart(ctx context.Context, chart *assets.HelmChart) *exec.Cmd { | ||
| args := []string{ | ||
| fmt.Sprintf("KUBECONFIG=%s", path.Join(vmpath.GuestPersistentDir, "kubeconfig")), | ||
| "helm", "upgrade", "--install", chart.Name, chart.Repo, "--create-namespace", | ||
| } | ||
| if chart.Namespace != "" { | ||
| args = append(args, "--namespace", chart.Namespace) | ||
| } | ||
|
|
||
| if chart.Values != nil { | ||
| for _, value := range chart.Values { | ||
| args = append(args, "--set", value) | ||
| } | ||
| } | ||
|
|
||
| if chart.ValueFiles != nil { | ||
| for _, value := range chart.ValueFiles { | ||
| args = append(args, "--values", value) | ||
| } | ||
| } | ||
|
|
||
| return exec.CommandContext(ctx, "sudo", args...) | ||
| } | ||
|
|
||
| // runs a helm uninstall based on the contents of chart *assets.HelmChart | ||
| func uninstalllHelmChart(ctx context.Context, chart *assets.HelmChart) *exec.Cmd { | ||
| args := []string{ | ||
| fmt.Sprintf("KUBECONFIG=%s", path.Join(vmpath.GuestPersistentDir, "kubeconfig")), | ||
| "helm", "uninstall", chart.Name, | ||
| } | ||
| if chart.Namespace != "" { | ||
| args = append(args, "--namespace", chart.Namespace) | ||
| } | ||
| return exec.CommandContext(ctx, "sudo", args...) | ||
| } | ||
|
|
||
| // based on enable will execute installHelmChart or uninstallHelmChart | ||
| func helmUninstallOrInstall(ctx context.Context, chart *assets.HelmChart, enable bool) *exec.Cmd { | ||
| if enable { | ||
| return installHelmChart(ctx, chart) | ||
| } | ||
| return uninstalllHelmChart(ctx, chart) | ||
| } | ||
|
|
||
| func helmInstallBinary(addon *assets.Addon, runner command.Runner) error { | ||
| _, err := runner.RunCmd(exec.Command("test", "-f", "/usr/bin/helm")) | ||
| if err != nil { | ||
| _, err = runner.RunCmd(exec.Command("test", "-d", "/usr/local/bin")) | ||
| if err != nil { | ||
| _, err = runner.RunCmd(exec.Command("sudo", "mkdir", "-p", "/usr/local/bin")) | ||
| } | ||
|
|
||
| installCmd := fmt.Sprint("curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 && chmod 700 get_helm.sh && ./get_helm.sh") | ||
| _, err = runner.RunCmd(exec.Command("sudo", "bash", "-c", installCmd)) | ||
| // we copy the binary from /usr/local/bin to /usr/bin because /usr/local/bin is not in PATH in both iso and kicbase | ||
| _, err = runner.RunCmd(exec.Command("sudo", "mv", "/usr/local/bin/helm", "/usr/bin/helm")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add comment explain the reason we do this is /usr/loca/bin/helm is not in PATH on both iso/kicbase
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added |
||
| if err != nil { | ||
| return errors.Wrap(err, "installing helm") | ||
| } | ||
| } | ||
| return err | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| Copyright 2025 The Kubernetes Authors All rights reserved. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package addons | ||
|
|
||
| import ( | ||
| "context" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "k8s.io/minikube/pkg/minikube/assets" | ||
| ) | ||
|
|
||
| func TestHelmCommand(t *testing.T) { | ||
| tests := []struct { | ||
| description string | ||
| chart *assets.HelmChart | ||
| enable bool | ||
| expected string | ||
| mode string | ||
| }{ | ||
| { | ||
| description: "enable an addon", | ||
| chart: &assets.HelmChart{ | ||
| Name: "addon-name", | ||
| Repo: "addon-repo/addon-chart", | ||
| Namespace: "addon-namespace", | ||
| Values: []string{"key=value"}, | ||
| ValueFiles: []string{"/etc/kubernetes/addons/values.yaml"}, | ||
| }, | ||
| enable: true, | ||
| expected: "sudo KUBECONFIG=/var/lib/minikube/kubeconfig helm upgrade --install addon-name addon-repo/addon-chart --create-namespace --namespace addon-namespace --set key=value --values /etc/kubernetes/addons/values.yaml", | ||
| }, | ||
| { | ||
| description: "enable an addon without namespace", | ||
| chart: &assets.HelmChart{ | ||
| Name: "addon-name", | ||
| Repo: "addon-repo/addon-chart", | ||
| Values: []string{"key=value"}, | ||
| ValueFiles: []string{"/etc/kubernetes/addons/values.yaml"}, | ||
| }, | ||
| enable: true, | ||
| expected: "sudo KUBECONFIG=/var/lib/minikube/kubeconfig helm upgrade --install addon-name addon-repo/addon-chart --create-namespace --set key=value --values /etc/kubernetes/addons/values.yaml", | ||
| }, | ||
| { | ||
| description: "disable an addon", | ||
| chart: &assets.HelmChart{ | ||
| Name: "addon-name", | ||
| Namespace: "addon-namespace", | ||
| }, | ||
| enable: false, | ||
| expected: "sudo KUBECONFIG=/var/lib/minikube/kubeconfig helm uninstall addon-name --namespace addon-namespace", | ||
| mode: "cpu", | ||
| }, | ||
| } | ||
|
|
||
| for _, test := range tests { | ||
| t.Run(test.description, func(t *testing.T) { | ||
| command := helmUninstallOrInstall(context.Background(), test.chart, test.enable) | ||
| actual := strings.Join(command.Args, " ") | ||
| if actual != test.expected { | ||
| t.Errorf("helm command mismatch:\nexpected: %s\nactual: %s", test.expected, actual) | ||
| } | ||
| }) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.