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

kubeadm: Remove feature gates from JoinConfiguration #70755

Merged
merged 1 commit into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions cmd/kubeadm/app/apis/kubeadm/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ type JoinConfiguration struct {

// APIEndpoint represents the endpoint of the instance of the API server eventually to be deployed on this node.
APIEndpoint APIEndpoint

// FeatureGates enabled by the user.
FeatureGates map[string]bool
}

// Discovery specifies the options for the kubelet to use during the TLS Bootstrap process
Expand Down
12 changes: 10 additions & 2 deletions cmd/kubeadm/app/apis/kubeadm/v1alpha3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ filegroup(

go_test(
name = "go_default_test",
srcs = ["bootstraptokenstring_test.go"],
srcs = [
"bootstraptokenstring_test.go",
"conversion_test.go",
],
embed = [":go_default_library"],
deps = ["//vendor/github.com/pkg/errors:go_default_library"],
deps = [
"//cmd/kubeadm/app/apis/kubeadm:go_default_library",
"//cmd/kubeadm/app/apis/kubeadm/scheme:go_default_library",
"//cmd/kubeadm/test:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
5 changes: 5 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha3

import (
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
Expand All @@ -28,6 +29,10 @@ func Convert_v1alpha3_JoinConfiguration_To_kubeadm_JoinConfiguration(in *JoinCon
return err
}

if len(in.FeatureGates) != 0 {
return errors.New("featureGates has been removed from JoinConfiguration and featureGates from ClusterConfiguration will be used instead. Please cleanup JoinConfiguration.FeatureGates fields")
}

out.Discovery.Timeout = in.DiscoveryTimeout

if len(in.TLSBootstrapToken) != 0 {
Expand Down
55 changes: 55 additions & 0 deletions cmd/kubeadm/app/apis/kubeadm/v1alpha3/conversion_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright 2018 The Kubernetes Authors.

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 v1alpha3_test

import (
"testing"

"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
testutil "k8s.io/kubernetes/cmd/kubeadm/test"
)

func TestJoinConfigurationConversion(t *testing.T) {
testcases := map[string]struct {
ereslibre marked this conversation as resolved.
Show resolved Hide resolved
ereslibre marked this conversation as resolved.
Show resolved Hide resolved
old *v1alpha3.JoinConfiguration
expectedErr string
}{
"conversion succeeds": {
old: &v1alpha3.JoinConfiguration{},
expectedErr: "",
},
"feature gates fails to be converted": {
old: &v1alpha3.JoinConfiguration{
FeatureGates: map[string]bool{
"someGate": true,
},
},
expectedErr: "featureGates has been removed from JoinConfiguration and featureGates from ClusterConfiguration will be used instead. Please cleanup JoinConfiguration.FeatureGates fields",
},
}
for _, tc := range testcases {
internal := &kubeadm.JoinConfiguration{}
err := scheme.Scheme.Convert(tc.old, internal, nil)
if len(tc.expectedErr) != 0 {
testutil.AssertError(t, err, tc.expectedErr)
} else if err != nil {
t.Errorf("no error was expected but '%s' was found", err)
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions cmd/kubeadm/app/apis/kubeadm/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,6 @@ type JoinConfiguration struct {

// APIEndpoint represents the endpoint of the instance of the API server eventually to be deployed on this node.
APIEndpoint APIEndpoint `json:"apiEndpoint,omitempty"`

// FeatureGates enabled by the user.
FeatureGates map[string]bool `json:"featureGates,omitempty"`
}

// Discovery specifies the options for the kubelet to use during the TLS Bootstrap process
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions cmd/kubeadm/app/apis/kubeadm/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions cmd/kubeadm/app/apis/kubeadm/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 7 additions & 16 deletions cmd/kubeadm/app/cmd/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"io"
"os"
"path/filepath"
"strings"
"text/template"

"github.com/golang/glog"
Expand Down Expand Up @@ -164,7 +163,6 @@ func NewCmdJoin(out io.Writer) *cobra.Command {

var token string
var cfgPath string
var featureGatesString string
var ignorePreflightErrors []string

cmd := &cobra.Command{
Expand Down Expand Up @@ -192,13 +190,13 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
cfg.Discovery.TLSBootstrapToken = token
}

j, err := NewValidJoin(cmd.PersistentFlags(), cfg, cfgPath, featureGatesString, ignorePreflightErrors)
j, err := NewValidJoin(cmd.PersistentFlags(), cfg, cfgPath, ignorePreflightErrors)
kubeadmutil.CheckErr(err)
kubeadmutil.CheckErr(j.Run(out))
},
}

AddJoinConfigFlags(cmd.PersistentFlags(), cfg, &featureGatesString, &token)
AddJoinConfigFlags(cmd.PersistentFlags(), cfg, &token)
AddJoinBootstrapTokenDiscoveryFlags(cmd.PersistentFlags(), btd)
AddJoinFileDiscoveryFlags(cmd.PersistentFlags(), fd)
AddJoinOtherFlags(cmd.PersistentFlags(), &cfgPath, &ignorePreflightErrors)
Expand All @@ -207,13 +205,10 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
}

// NewValidJoin validates the command line that are passed to the cobra command
func NewValidJoin(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.JoinConfiguration, cfgPath, featureGatesString string, ignorePreflightErrors []string) (*Join, error) {
func NewValidJoin(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.JoinConfiguration, cfgPath string, ignorePreflightErrors []string) (*Join, error) {
var err error
if cfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
return nil, err
}

if err := validation.ValidateMixedArguments(flagSet); err != nil {
if err = validation.ValidateMixedArguments(flagSet); err != nil {
return nil, err
}

Expand All @@ -226,17 +221,13 @@ func NewValidJoin(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.JoinConfiguratio
}

// AddJoinConfigFlags adds join flags bound to the config to the specified flagset
func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.JoinConfiguration, featureGatesString *string, token *string) {
func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.JoinConfiguration, token *string) {
flagSet.StringVar(
&cfg.NodeRegistration.Name, "node-name", cfg.NodeRegistration.Name,
"Specify the node name.")
flagSet.StringVar(
token, "token", "",
"Use this token for both discovery-token and tls-bootstrap-token when those values are not provided.")
flagSet.StringVar(
featureGatesString, "feature-gates", *featureGatesString,
"A set of key=value pairs that describe feature gates for various features. "+
"Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n"))
flagSet.StringVar(
&cfg.NodeRegistration.CRISocket, "cri-socket", cfg.NodeRegistration.CRISocket,
`Specify the CRI socket to connect to.`,
Expand Down Expand Up @@ -513,7 +504,7 @@ func (j *Join) BootstrapKubelet(tlsBootstrapCfg *clientcmdapi.Config) error {
// register the joining node with the specified taints if the node
// is not a master. The markmaster phase will register the taints otherwise.
registerTaintsUsingFlags := !j.cfg.ControlPlane
if err := kubeletphase.WriteKubeletDynamicEnvFile(&j.cfg.NodeRegistration, j.cfg.FeatureGates, registerTaintsUsingFlags, kubeadmconstants.KubeletRunDirectory); err != nil {
if err := kubeletphase.WriteKubeletDynamicEnvFile(&j.cfg.NodeRegistration, j.initCfg.FeatureGates, registerTaintsUsingFlags, kubeadmconstants.KubeletRunDirectory); err != nil {
return err
}

Expand Down Expand Up @@ -542,7 +533,7 @@ func (j *Join) BootstrapKubelet(tlsBootstrapCfg *clientcmdapi.Config) error {
}

// This feature is disabled by default in kubeadm
if features.Enabled(j.cfg.FeatureGates, features.DynamicKubeletConfig) {
if features.Enabled(j.initCfg.FeatureGates, features.DynamicKubeletConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: in the future this should be use/be called ClusterConfiguration, because the thing returned from the cluster configmap at this stage is a clusterconfig, not an initconfig
This is not specific to this PR though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll file a bug for that later, thank you.

if err := kubeletphase.EnableDynamicConfigForNode(client, j.cfg.NodeRegistration.Name, kubeletVersion); err != nil {
return errors.Wrap(err, "error consuming base kubelet configuration")
}
Expand Down
8 changes: 1 addition & 7 deletions cmd/kubeadm/app/cmd/join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestNewValidJoin(t *testing.T) {
skipPreFlight bool
cfgPath string
configToWrite string
featureGatesString string
ereslibre marked this conversation as resolved.
Show resolved Hide resolved
ignorePreflightErrors []string
testJoinValidate bool
testJoinRun bool
Expand Down Expand Up @@ -109,11 +108,6 @@ func TestNewValidJoin(t *testing.T) {
ignorePreflightErrors: []string{"some-unsupported-preflight-arg"},
expectedError: true,
},
{
name: "invalid: incorrect featureGatesString",
featureGatesString: "bad-feature-gate-string",
expectedError: true,
},
{
name: "invalid: fail Join.Validate() with wrong flags",
skipPreFlight: true,
Expand Down Expand Up @@ -162,7 +156,7 @@ func TestNewValidJoin(t *testing.T) {
}
}

join, err := NewValidJoin(cmd.PersistentFlags(), cfg, tc.cfgPath, tc.featureGatesString, tc.ignorePreflightErrors)
join, err := NewValidJoin(cmd.PersistentFlags(), cfg, tc.cfgPath, tc.ignorePreflightErrors)

if tc.nodeConfig != nil {
join.cfg = tc.nodeConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Discovery:
File: null
TLSBootstrapToken: abcdef.0123456789abcdef
Timeout: 5m0s
FeatureGates: null
NodeRegistration:
CRISocket: /var/run/dockershim.sock
KubeletExtraArgs: null
Expand Down