Currently, kubeadm would refuse to perfom an upgrade (or even planing for one) if it detects a user supplied unsupported component config version. Hence, users are required to manually upgrade their component configs and store them in the config maps prior to executing `kubeadm upgrade plan` or `kubeadm upgrade apply`. This change introduces the ability to use the `--config` option of the `kubeadm upgrade plan` and `kubeadm upgrade apply` commands to supply a YAML file containing component configs to be used in place of the existing ones in the cluster upon upgrade. The old behavior where `--config` is used to reconfigure a cluster is still supported. kubeadm automatically detects which behavior to use based on the presence (or absense) of kubeadm config types (API group `kubeadm.kubernetes.io`). Signed-off-by: Rostislav M. Georgiev <rostislavg@vmware.com>
72 lines
2.6 KiB
Go
72 lines
2.6 KiB
Go
/*
|
|
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 componentconfigs
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/klog/v2"
|
|
)
|
|
|
|
// UnsupportedConfigVersionError is a special error type returned whenever we encounter too old config version
|
|
type UnsupportedConfigVersionError struct {
|
|
// OldVersion is the config version that is causing the problem
|
|
OldVersion schema.GroupVersion
|
|
|
|
// CurrentVersion describes the natively supported config version
|
|
CurrentVersion schema.GroupVersion
|
|
|
|
// Document points to the YAML/JSON document that caused the problem
|
|
Document []byte
|
|
}
|
|
|
|
// Error implements the standard Golang error interface for UnsupportedConfigVersionError
|
|
func (err *UnsupportedConfigVersionError) Error() string {
|
|
return fmt.Sprintf("unsupported apiVersion %q, you may have to do manual conversion to %q and run kubeadm again", err.OldVersion, err.CurrentVersion)
|
|
}
|
|
|
|
// UnsupportedConfigVersionsErrorMap is a cumulative version of the UnsupportedConfigVersionError type
|
|
type UnsupportedConfigVersionsErrorMap map[string]*UnsupportedConfigVersionError
|
|
|
|
// Error implements the standard Golang error interface for UnsupportedConfigVersionsErrorMap
|
|
func (errs UnsupportedConfigVersionsErrorMap) Error() string {
|
|
// Make sure the error messages we print are predictable by sorting them by the group names involved
|
|
groups := make([]string, 0, len(errs))
|
|
for group := range errs {
|
|
groups = append(groups, group)
|
|
}
|
|
sort.Strings(groups)
|
|
|
|
msgs := make([]string, 1, 1+len(errs))
|
|
msgs[0] = "multiple unsupported config version errors encountered:"
|
|
for _, group := range groups {
|
|
msgs = append(msgs, errs[group].Error())
|
|
}
|
|
|
|
return strings.Join(msgs, "\n\t- ")
|
|
}
|
|
|
|
// warnDefaultComponentConfigValue prints a warning if the user modified a field in a certain
|
|
// CompomentConfig from the default recommended value in kubeadm.
|
|
func warnDefaultComponentConfigValue(componentConfigKind, paramName string, defaultValue, userValue interface{}) {
|
|
klog.Warningf("The recommended value for %q in %q is: %v; the provided value is: %v",
|
|
paramName, componentConfigKind, defaultValue, userValue)
|
|
}
|