fix the verify job

This commit is contained in:
Lucas Käldström 2018-06-01 17:14:26 +03:00
parent 67a9f1bfe7
commit d01a7be2ac
No known key found for this signature in database
GPG Key ID: 3FA3783D77751514
6 changed files with 20 additions and 9 deletions

View File

@ -84,24 +84,24 @@ func BootstrapTokenFromSecret(secret *v1.Secret) (*BootstrapToken, error) {
// Get the Token ID field from the Secret data // Get the Token ID field from the Secret data
tokenID := getSecretString(secret, bootstrapapi.BootstrapTokenIDKey) tokenID := getSecretString(secret, bootstrapapi.BootstrapTokenIDKey)
if len(tokenID) == 0 { 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 // Enforce the right naming convention
if secret.Name != bootstraputil.BootstrapTokenSecretName(tokenID) { 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)) bootstrapapi.BootstrapTokenSecretPrefix, secret.Name, bootstraputil.BootstrapTokenSecretName(tokenID))
} }
tokenSecret := getSecretString(secret, bootstrapapi.BootstrapTokenSecretKey) tokenSecret := getSecretString(secret, bootstrapapi.BootstrapTokenSecretKey)
if len(tokenSecret) == 0 { 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 // Create the BootstrapTokenString object based on the ID and Secret
bts, err := NewBootstrapTokenStringFromIDAndSecret(tokenID, tokenSecret) bts, err := NewBootstrapTokenStringFromIDAndSecret(tokenID, tokenSecret)
if err != nil { 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 // Get the description (if any) from the Secret
@ -116,7 +116,7 @@ func BootstrapTokenFromSecret(secret *v1.Secret) (*BootstrapToken, error) {
if err != nil { if err != nil {
return nil, fmt.Errorf("can't parse expiration time of bootstrap token %q: %v", secret.Name, err) 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 // Build an usages string slice from the Secret data

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. 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 // 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 // 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. // (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 // 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 // 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 // "kubeadm join". This token is and should be short-lived
type BootstrapTokenString struct { type BootstrapTokenString struct {

View File

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. 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 // 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 // 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. // (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 // 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 // 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 // "kubeadm join". This token is and should be short-lived
type BootstrapTokenString struct { type BootstrapTokenString struct {

View File

@ -178,6 +178,7 @@ func ValidateDiscoveryFile(discoveryFile string, fldPath *field.Path) field.Erro
return allErrs return allErrs
} }
// ValidateBootstrapTokens validates a slice of BootstrapToken objects
func ValidateBootstrapTokens(bts []kubeadm.BootstrapToken, fldPath *field.Path) field.ErrorList { func ValidateBootstrapTokens(bts []kubeadm.BootstrapToken, fldPath *field.Path) field.ErrorList {
allErrs := field.ErrorList{} allErrs := field.ErrorList{}
for i, bt := range bts { for i, bt := range bts {

View File

@ -27,6 +27,7 @@ import (
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
) )
// NewBootstrapTokenOptions creates a new BootstrapTokenOptions object with the default values
func NewBootstrapTokenOptions() *BootstrapTokenOptions { func NewBootstrapTokenOptions() *BootstrapTokenOptions {
bto := &BootstrapTokenOptions{&kubeadmapiv1alpha2.BootstrapToken{}, ""} bto := &BootstrapTokenOptions{&kubeadmapiv1alpha2.BootstrapToken{}, ""}
kubeadmapiv1alpha2.SetDefaults_BootstrapToken(bto.BootstrapToken) kubeadmapiv1alpha2.SetDefaults_BootstrapToken(bto.BootstrapToken)
@ -41,6 +42,7 @@ type BootstrapTokenOptions struct {
TokenStr string TokenStr string
} }
// AddTokenFlag adds the --token flag to the given flagset
func (bto *BootstrapTokenOptions) AddTokenFlag(fs *pflag.FlagSet) { func (bto *BootstrapTokenOptions) AddTokenFlag(fs *pflag.FlagSet) {
fs.StringVar( fs.StringVar(
&bto.TokenStr, "token", "", &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) { func (bto *BootstrapTokenOptions) AddTTLFlag(fs *pflag.FlagSet) {
fs.DurationVar( 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", "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) { func (bto *BootstrapTokenOptions) AddUsagesFlag(fs *pflag.FlagSet) {
fs.StringSliceVar( fs.StringSliceVar(
&bto.Usages, "usages", bto.Usages, &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) { func (bto *BootstrapTokenOptions) AddGroupsFlag(fs *pflag.FlagSet) {
fs.StringSliceVar( fs.StringSliceVar(
&bto.Groups, "groups", bto.Groups, &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) { func (bto *BootstrapTokenOptions) AddDescriptionFlag(fs *pflag.FlagSet) {
fs.StringVar( fs.StringVar(
&bto.Description, "description", bto.Description, &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 { func (bto *BootstrapTokenOptions) ApplyTo(cfg *kubeadmapiv1alpha2.MasterConfiguration) error {
if len(bto.TokenStr) > 0 { if len(bto.TokenStr) > 0 {
var err error var err error

View File

@ -66,7 +66,7 @@ func SetInitDynamicDefaults(cfg *kubeadmapi.MasterConfiguration) error {
// Populate the .Token field with a random value if unset // Populate the .Token field with a random value if unset
// We do this at this layer, and not the API defaulting layer // 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 // because we can't return errors in the API object defaulting
// process but here we can. // process but here we can.
for i, bt := range cfg.BootstrapTokens { for i, bt := range cfg.BootstrapTokens {