Skip to content

Commit

Permalink
second
Browse files Browse the repository at this point in the history
  • Loading branch information
11janci committed Sep 4, 2020
1 parent 9a9ffd4 commit 89144af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/addons/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ var Addons = []*Addon{
{
name: "csi-hostpath-driver",
set: SetBool,
validations: []setFn{HasVolumesnapshotsEnabled},
callbacks: []setFn{enableOrDisableAddon, verifyAddonStatus},
},
}
35 changes: 34 additions & 1 deletion pkg/addons/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ package addons

import (
"fmt"

"k8s.io/minikube/pkg/minikube/assets"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/out"
"strconv"
)

const volumesnapshotsAddon = "volumesnapshots"

// containerdOnlyMsg is the message shown when a containerd-only addon is enabled
const containerdOnlyAddonMsg = `
This addon can only be enabled with the containerd runtime backend. To enable this backend, please first stop minikube with:
Expand All @@ -33,6 +37,12 @@ and then start minikube again with the following flags:
minikube start --container-runtime=containerd --docker-opt containerd=/var/run/containerd/containerd.sock`

// volumesnapshotsDisabledMsg is the message shown when csi-hostpath-driver addon is enabled without the volumesnapshots addon
const volumesnapshotsDisabledMsg = `[WARNING] For full functionality, the 'csi-hostpath-driver' addon requires the 'volumesnapshots' addon to be enabled.
You can enable 'volumesnapshots' addon by running: 'minikube addons enable volumesnapshots'
`

// IsRuntimeContainerd is a validator which returns an error if the current runtime is not containerd
func IsRuntimeContainerd(cc *config.ClusterConfig, _, _ string) error {
r, err := cruntime.New(cruntime.Config{Type: cc.KubernetesConfig.ContainerRuntime})
Expand All @@ -46,6 +56,20 @@ func IsRuntimeContainerd(cc *config.ClusterConfig, _, _ string) error {
return nil
}

// IsRuntimeContainerd is a validator which returns an error if the current runtime is not containerd
func HasVolumesnapshotsEnabled(cc *config.ClusterConfig, _, value string) error {
isCsiDriverEnabled, _ := strconv.ParseBool(value)
// assets.Addons[x].IsEnabled() returns the current status of the addon or default value.
// config.AddonList contains list of addons to be enabled.
isVolumesnapshotsEnabled := assets.Addons[volumesnapshotsAddon].IsEnabled(cc) || contains(config.AddonList, volumesnapshotsAddon)
if isCsiDriverEnabled && !isVolumesnapshotsEnabled {
// just print out a warning directly, we don't want to return any errors since
// that would prevent the addon from being enabled (callbacks wouldn't be run)
out.WarningT(volumesnapshotsDisabledMsg)
}
return nil
}

// isAddonValid returns the addon, true if it is valid
// otherwise returns nil, false
func isAddonValid(name string) (*Addon, bool) {
Expand All @@ -56,3 +80,12 @@ func isAddonValid(name string) (*Addon, bool) {
}
return nil, false
}

func contains(slice []string, val string) bool {
for _, item := range slice {
if item == val {
return true
}
}
return false
}

0 comments on commit 89144af

Please sign in to comment.