-
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
Open
volatilemolotov
wants to merge
6
commits into
kubernetes:master
Choose a base branch
from
volatilemolotov:addons/helm_addon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+323
−41
Open
Addons: helm based addons #21847
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ba89aec
add support for helm based addons
volatilemolotov 8b29c65
refactor helm install
volatilemolotov 9e336a9
add description to helmcommand and rename helminstall to helminstallb…
volatilemolotov 82621d2
refactor helm functions
volatilemolotov d82101b
refactor helm functions - fix install and tests
volatilemolotov 0cb66d3
add documentation for the helm based addons
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,89 @@ | ||
| /* | ||
| 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 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)) | ||
| _, err = runner.RunCmd(exec.Command("sudo", "mv", "/usr/local/bin/helm", "/usr/bin/helm")) | ||
| 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,76 @@ | ||
| /* | ||
| 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.
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.
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.
we can add a documentation to the website https://minikube.sigs.k8s.io/docs/contrib/addons/
we can add a block (how to add helm based addons)
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.
Pushed a new site doc with some explanation. As we work on adding a actual addon we will update the doc for the helm based addon