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 feature gates support for Kubeadm #2951

Merged
merged 4 commits into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const (
keepContext = "keep-context"
createMount = "mount"
featureGates = "feature-gates"
kubeadmFeatureGates = "kubeadm-feature-gates"
apiServerName = "apiserver-name"
dnsDomain = "dns-domain"
mountString = "mount-string"
Expand Down Expand Up @@ -217,6 +218,7 @@ func runStart(cmd *cobra.Command, args []string) {
APIServerIPs: apiServerIPs,
DNSDomain: viper.GetString(dnsDomain),
FeatureGates: viper.GetString(featureGates),
KubeadmFeatureGates: viper.GetString(kubeadmFeatureGates),
ContainerRuntime: viper.GetString(containerRuntime),
NetworkPlugin: viper.GetString(networkPlugin),
ServiceCIDR: pkgutil.DefaultServiceCIDR,
Expand Down Expand Up @@ -411,6 +413,7 @@ func init() {
startCmd.Flags().String(containerRuntime, "", "The container runtime to be used")
startCmd.Flags().String(networkPlugin, "", "The name of the network plugin")
startCmd.Flags().String(featureGates, "", "A set of key=value pairs that describe feature gates for alpha/experimental features.")
startCmd.Flags().String(kubeadmFeatureGates, "", "A set of key=value pairs that describe feature gates for kubeadm alpha/experimental features.")
startCmd.Flags().Bool(cacheImages, false, "If true, cache docker images for the current bootstrapper and load them into the machine.")
startCmd.Flags().Var(&extraOptions, "extra-config",
`A set of key=value pairs that describe configuration that may be passed to different components.
Expand Down
8 changes: 8 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,12 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) {
return "", errors.Wrap(err, "generating extra component config for kubeadm")
}

// generates a map of the feature gates for kubeadm
kubeadmFeatureArgs, err := ParseKubeadmFeatureArgs(k8s.KubeadmFeatureGates)
if err != nil {
return "", errors.Wrap(err, "generating feature gate config for kubeadm")
}

opts := struct {
CertDir string
ServiceCIDR string
Expand All @@ -349,6 +355,7 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) {
EtcdDataDir string
NodeName string
ExtraArgs []ComponentExtraArgs
FeatureArgs FeatureArgs
}{
CertDir: util.DefaultCertPath,
ServiceCIDR: util.DefaultServiceCIDR,
Expand All @@ -358,6 +365,7 @@ func generateConfig(k8s config.KubernetesConfig) (string, error) {
EtcdDataDir: "/data/minikube", //TODO(r2d4): change to something else persisted
NodeName: k8s.NodeName,
ExtraArgs: extraComponentConfig,
FeatureArgs: kubeadmFeatureArgs,
}

b := bytes.Buffer{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ etcd:
nodeName: {{.NodeName}}
{{range .ExtraArgs}}{{.Component}}:{{range $i, $val := printMapInOrder .Options ": " }}
{{$val}}{{end}}
{{end}}{{if .FeatureArgs}}featureGates: {{range $i, $val := .FeatureArgs}}
{{$i}}: {{$val}}{{end}}
{{end}}`))

var kubeletSystemdTemplate = template.Must(template.New("kubeletSystemdTemplate").Parse(`
Expand Down
27 changes: 27 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"path"
"sort"
"strconv"
"strings"

"github.com/blang/semver"
Expand Down Expand Up @@ -63,6 +64,8 @@ type ComponentExtraArgs struct {
Options map[string]string
}

type FeatureArgs map[string]bool

var componentToKubeadmConfigKey = map[string]string{
Apiserver: "apiServerExtraArgs",
ControllerManager: "controllerManagerExtraArgs",
Expand Down Expand Up @@ -108,6 +111,30 @@ func NewComponentExtraArgs(opts util.ExtraOptionSlice, version semver.Version, f
return kubeadmExtraArgs, nil
}

func ParseKubeadmFeatureArgs(featureGates string) (FeatureArgs, error) {
featureArgs := map[string]bool{}
for _, s := range strings.Split(featureGates, ",") {
if len(s) == 0 {
continue
}

fg := strings.SplitN(s, "=", 2)
if len(fg) != 2 {
return nil, fmt.Errorf("missing value for key \"%v\"", s)
}

k := strings.TrimSpace(fg[0])
v := strings.TrimSpace(fg[1])

boolValue, err := strconv.ParseBool(v)
if err != nil {
return nil, errors.Wrapf(err, "failed to convert bool value \"%v\"", v)
}
featureArgs[k] = boolValue
}
return featureArgs, nil
}

func ParseKubernetesVersion(version string) (semver.Version, error) {
// Strip leading 'v' prefix from version for semver parsing
v, err := semver.Make(version[1:])
Expand Down
25 changes: 13 additions & 12 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ type MachineConfig struct {

// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
type KubernetesConfig struct {
KubernetesVersion string
NodeIP string
NodeName string
APIServerName string
APIServerNames []string
APIServerIPs []net.IP
DNSDomain string
ContainerRuntime string
NetworkPlugin string
FeatureGates string
ServiceCIDR string
ExtraOptions util.ExtraOptionSlice
KubernetesVersion string
NodeIP string
NodeName string
APIServerName string
APIServerNames []string
APIServerIPs []net.IP
DNSDomain string
ContainerRuntime string
NetworkPlugin string
FeatureGates string
KubeadmFeatureGates string
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to reuse the existing FeatureGates field here instead of adding a new one?

Copy link
Contributor Author

@kairen kairen Jul 4, 2018

Choose a reason for hiding this comment

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

Yes, I will try to remove it and reuse FeatureGates field.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dlorenc I have been updated, could you review this changes? thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ping.

ServiceCIDR string
ExtraOptions util.ExtraOptionSlice

ShouldLoadCachedImages bool
}