...

Source file src/k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs/utils.go

Documentation: k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs

     1  /*
     2  Copyright 2018 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package componentconfigs
    18  
    19  import (
    20  	"fmt"
    21  	"sort"
    22  	"strings"
    23  
    24  	"k8s.io/apimachinery/pkg/runtime/schema"
    25  	"k8s.io/klog/v2"
    26  )
    27  
    28  // UnsupportedConfigVersionError is a special error type returned whenever we encounter too old config version
    29  type UnsupportedConfigVersionError struct {
    30  	// OldVersion is the config version that is causing the problem
    31  	OldVersion schema.GroupVersion
    32  
    33  	// CurrentVersion describes the natively supported config version
    34  	CurrentVersion schema.GroupVersion
    35  
    36  	// Document points to the YAML/JSON document that caused the problem
    37  	Document []byte
    38  }
    39  
    40  // Error implements the standard Golang error interface for UnsupportedConfigVersionError
    41  func (err *UnsupportedConfigVersionError) Error() string {
    42  	return fmt.Sprintf("unsupported apiVersion %q, you may have to do manual conversion to %q and run kubeadm again", err.OldVersion, err.CurrentVersion)
    43  }
    44  
    45  // UnsupportedConfigVersionsErrorMap is a cumulative version of the UnsupportedConfigVersionError type
    46  type UnsupportedConfigVersionsErrorMap map[string]*UnsupportedConfigVersionError
    47  
    48  // Error implements the standard Golang error interface for UnsupportedConfigVersionsErrorMap
    49  func (errs UnsupportedConfigVersionsErrorMap) Error() string {
    50  	// Make sure the error messages we print are predictable by sorting them by the group names involved
    51  	groups := make([]string, 0, len(errs))
    52  	for group := range errs {
    53  		groups = append(groups, group)
    54  	}
    55  	sort.Strings(groups)
    56  
    57  	msgs := make([]string, 1, 1+len(errs))
    58  	msgs[0] = "multiple unsupported config version errors encountered:"
    59  	for _, group := range groups {
    60  		msgs = append(msgs, errs[group].Error())
    61  	}
    62  
    63  	return strings.Join(msgs, "\n\t- ")
    64  }
    65  
    66  // warnDefaultComponentConfigValue prints a warning if the user modified a field in a certain
    67  // ComponentConfig from the default recommended value in kubeadm.
    68  func warnDefaultComponentConfigValue(componentConfigKind, paramName string, defaultValue, userValue interface{}) {
    69  	klog.Warningf("The recommended value for %q in %q is: %v; the provided value is: %v",
    70  		paramName, componentConfigKind, defaultValue, userValue)
    71  }
    72  

View as plain text