diff --git a/cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers.go b/cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers.go index 3bc0ed5a190..fc18701c616 100644 --- a/cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers.go +++ b/cmd/kubeadm/app/apis/kubeadm/bootstraptokenhelpers.go @@ -84,24 +84,24 @@ func BootstrapTokenFromSecret(secret *v1.Secret) (*BootstrapToken, error) { // Get the Token ID field from the Secret data tokenID := getSecretString(secret, bootstrapapi.BootstrapTokenIDKey) if len(tokenID) == 0 { - return nil, fmt.Errorf("Bootstrap Token Secret has no token-id data: %s\n", secret.Name) + return nil, fmt.Errorf("Bootstrap Token Secret has no token-id data: %s", secret.Name) } // Enforce the right naming convention if secret.Name != bootstraputil.BootstrapTokenSecretName(tokenID) { - return nil, fmt.Errorf("bootstrap token name is not of the form '%s(token-id)'. Actual: %q. Expected: %q\n", + return nil, fmt.Errorf("bootstrap token name is not of the form '%s(token-id)'. Actual: %q. Expected: %q", bootstrapapi.BootstrapTokenSecretPrefix, secret.Name, bootstraputil.BootstrapTokenSecretName(tokenID)) } tokenSecret := getSecretString(secret, bootstrapapi.BootstrapTokenSecretKey) if len(tokenSecret) == 0 { - return nil, fmt.Errorf("Bootstrap Token Secret has no token-secret data: %s\n", secret.Name) + return nil, fmt.Errorf("Bootstrap Token Secret has no token-secret data: %s", secret.Name) } // Create the BootstrapTokenString object based on the ID and Secret bts, err := NewBootstrapTokenStringFromIDAndSecret(tokenID, tokenSecret) if err != nil { - return nil, fmt.Errorf("Bootstrap Token Secret is invalid and couldn't be parsed: %v\n", err) + return nil, fmt.Errorf("Bootstrap Token Secret is invalid and couldn't be parsed: %v", err) } // Get the description (if any) from the Secret @@ -116,7 +116,7 @@ func BootstrapTokenFromSecret(secret *v1.Secret) (*BootstrapToken, error) { if err != nil { return nil, fmt.Errorf("can't parse expiration time of bootstrap token %q: %v", secret.Name, err) } - expires = &metav1.Time{expTime} + expires = &metav1.Time{Time: expTime} } // Build an usages string slice from the Secret data diff --git a/cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring.go b/cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring.go index 8bbd11ebada..440c2534a64 100644 --- a/cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring.go +++ b/cmd/kubeadm/app/apis/kubeadm/bootstraptokenstring.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package kubeadm holds the internal kubeadm API types // Note: This file should be kept in sync with the similar one for the external API // TODO: The BootstrapTokenString object should move out to either k8s.io/client-go or k8s.io/api in the future // (probably as part of Bootstrap Tokens going GA). It should not be staged under the kubeadm API as it is now. @@ -28,7 +29,7 @@ import ( ) // BootstrapTokenString is a token of the format abcdef.abcdef0123456789 that is used -// for both validation of the authenticy of the API server from a joining node's point +// for both validation of the practically of the API server from a joining node's point // of view and as an authentication method for the node in the bootstrap phase of // "kubeadm join". This token is and should be short-lived type BootstrapTokenString struct { diff --git a/cmd/kubeadm/app/apis/kubeadm/v1alpha2/bootstraptokenstring.go b/cmd/kubeadm/app/apis/kubeadm/v1alpha2/bootstraptokenstring.go index 546b8f898b4..d62d5a7438c 100644 --- a/cmd/kubeadm/app/apis/kubeadm/v1alpha2/bootstraptokenstring.go +++ b/cmd/kubeadm/app/apis/kubeadm/v1alpha2/bootstraptokenstring.go @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +// Package v1alpha2 holds the external kubeadm API types of version v1alpha2 // Note: This file should be kept in sync with the similar one for the internal API // TODO: The BootstrapTokenString object should move out to either k8s.io/client-go or k8s.io/api in the future // (probably as part of Bootstrap Tokens going GA). It should not be staged under the kubeadm API as it is now. @@ -28,7 +29,7 @@ import ( ) // BootstrapTokenString is a token of the format abcdef.abcdef0123456789 that is used -// for both validation of the authenticy of the API server from a joining node's point +// for both validation of the practically of the API server from a joining node's point // of view and as an authentication method for the node in the bootstrap phase of // "kubeadm join". This token is and should be short-lived type BootstrapTokenString struct { diff --git a/cmd/kubeadm/app/apis/kubeadm/validation/validation.go b/cmd/kubeadm/app/apis/kubeadm/validation/validation.go index 53afcaeb4c6..ad542f36f00 100644 --- a/cmd/kubeadm/app/apis/kubeadm/validation/validation.go +++ b/cmd/kubeadm/app/apis/kubeadm/validation/validation.go @@ -178,6 +178,7 @@ func ValidateDiscoveryFile(discoveryFile string, fldPath *field.Path) field.Erro return allErrs } +// ValidateBootstrapTokens validates a slice of BootstrapToken objects func ValidateBootstrapTokens(bts []kubeadm.BootstrapToken, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} for i, bt := range bts { diff --git a/cmd/kubeadm/app/cmd/options/token.go b/cmd/kubeadm/app/cmd/options/token.go index 204fdb4342c..2b793f14322 100644 --- a/cmd/kubeadm/app/cmd/options/token.go +++ b/cmd/kubeadm/app/cmd/options/token.go @@ -27,6 +27,7 @@ import ( kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" ) +// NewBootstrapTokenOptions creates a new BootstrapTokenOptions object with the default values func NewBootstrapTokenOptions() *BootstrapTokenOptions { bto := &BootstrapTokenOptions{&kubeadmapiv1alpha2.BootstrapToken{}, ""} kubeadmapiv1alpha2.SetDefaults_BootstrapToken(bto.BootstrapToken) @@ -41,6 +42,7 @@ type BootstrapTokenOptions struct { TokenStr string } +// AddTokenFlag adds the --token flag to the given flagset func (bto *BootstrapTokenOptions) AddTokenFlag(fs *pflag.FlagSet) { fs.StringVar( &bto.TokenStr, "token", "", @@ -48,13 +50,15 @@ func (bto *BootstrapTokenOptions) AddTokenFlag(fs *pflag.FlagSet) { ) } +// AddTTLFlag adds the --token-ttl flag to the given flagset func (bto *BootstrapTokenOptions) AddTTLFlag(fs *pflag.FlagSet) { fs.DurationVar( - &bto.TTL.Duration, "ttl", bto.TTL.Duration, + &bto.TTL.Duration, "token-ttl", bto.TTL.Duration, "The duration before the token is automatically deleted (e.g. 1s, 2m, 3h). If set to '0', the token will never expire", ) } +// AddUsagesFlag adds the --usages flag to the given flagset func (bto *BootstrapTokenOptions) AddUsagesFlag(fs *pflag.FlagSet) { fs.StringSliceVar( &bto.Usages, "usages", bto.Usages, @@ -62,6 +66,7 @@ func (bto *BootstrapTokenOptions) AddUsagesFlag(fs *pflag.FlagSet) { ) } +// AddGroupsFlag adds the --groups flag to the given flagset func (bto *BootstrapTokenOptions) AddGroupsFlag(fs *pflag.FlagSet) { fs.StringSliceVar( &bto.Groups, "groups", bto.Groups, @@ -69,6 +74,7 @@ func (bto *BootstrapTokenOptions) AddGroupsFlag(fs *pflag.FlagSet) { ) } +// AddDescriptionFlag adds the --description flag to the given flagset func (bto *BootstrapTokenOptions) AddDescriptionFlag(fs *pflag.FlagSet) { fs.StringVar( &bto.Description, "description", bto.Description, @@ -76,6 +82,8 @@ func (bto *BootstrapTokenOptions) AddDescriptionFlag(fs *pflag.FlagSet) { ) } +// ApplyTo applies the values set internally in the BootstrapTokenOptions object to a MasterConfiguration object at runtime +// If --token was specified in the CLI (as a string), it's parsed and validated before it's added to the BootstrapToken object. func (bto *BootstrapTokenOptions) ApplyTo(cfg *kubeadmapiv1alpha2.MasterConfiguration) error { if len(bto.TokenStr) > 0 { var err error diff --git a/cmd/kubeadm/app/util/config/masterconfig.go b/cmd/kubeadm/app/util/config/masterconfig.go index 1b5bb95e51d..c74f93109ea 100644 --- a/cmd/kubeadm/app/util/config/masterconfig.go +++ b/cmd/kubeadm/app/util/config/masterconfig.go @@ -66,7 +66,7 @@ func SetInitDynamicDefaults(cfg *kubeadmapi.MasterConfiguration) error { // Populate the .Token field with a random value if unset // We do this at this layer, and not the API defaulting layer - // because of possible security concerns, and more practially + // because of possible security concerns, and more practically // because we can't return errors in the API object defaulting // process but here we can. for i, bt := range cfg.BootstrapTokens {