@@ -22,28 +22,34 @@ import (
22
22
"github.com/pkg/errors"
23
23
24
24
"k8s.io/apimachinery/pkg/runtime"
25
- "k8s.io/apimachinery/pkg/util/sets"
26
25
"k8s.io/klog/v2"
27
- kubeproxyconfig "k8s.io/kube-proxy/config/v1alpha1"
28
- kubeletconfig "k8s.io/kubelet/config/v1beta1"
29
26
30
27
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
31
28
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
32
29
kubeadmapiv1 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta4"
33
30
"k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation"
34
31
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
32
+ "k8s.io/kubernetes/cmd/kubeadm/app/constants"
35
33
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
36
34
"k8s.io/kubernetes/cmd/kubeadm/app/util/config/strict"
37
35
)
38
36
39
- var componentCfgGV = sets .New (kubeproxyconfig .GroupName , kubeletconfig .GroupName )
40
-
41
37
// documentMapToUpgradeConfiguration takes a map between GVKs and YAML documents (as returned by SplitYAMLDocuments),
42
38
// finds a UpgradeConfiguration, decodes it, dynamically defaults it and then validates it prior to return.
43
39
func documentMapToUpgradeConfiguration (gvkmap kubeadmapi.DocumentMap , allowDeprecated bool ) (* kubeadmapi.UpgradeConfiguration , error ) {
44
- var internalcfg * kubeadmapi. UpgradeConfiguration
40
+ upgradeBytes := [] byte {}
45
41
46
42
for gvk , bytes := range gvkmap {
43
+ if kubeadmutil .GroupVersionKindsHasInitConfiguration (gvk ) || kubeadmutil .GroupVersionKindsHasClusterConfiguration (gvk ) || componentconfigs .Scheme .IsGroupRegistered (gvk .Group ) {
44
+ klog .Warningf ("[config] WARNING: YAML document with GroupVersionKind %v is deprecated for upgrade, please use config file with kind of UpgradeConfiguration instead \n " , gvk )
45
+ continue
46
+ }
47
+
48
+ if gvk .Kind != constants .UpgradeConfigurationKind {
49
+ klog .Warningf ("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n " , gvk )
50
+ continue
51
+ }
52
+
47
53
// check if this version is supported and possibly not deprecated
48
54
if err := validateSupportedVersion (gvk , allowDeprecated , true ); err != nil {
49
55
return nil , err
@@ -54,37 +60,19 @@ func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepre
54
60
klog .Warning (err .Error ())
55
61
}
56
62
57
- if kubeadmutil .GroupVersionKindsHasInitConfiguration (gvk ) || kubeadmutil .GroupVersionKindsHasClusterConfiguration (gvk ) {
58
- klog .Warningf ("[config] WARNING: YAML document with GroupVersionKind %v is deprecated for upgrade, please use config file with kind of UpgradeConfiguration instead \n " , gvk )
59
- continue
60
- }
61
-
62
- if kubeadmutil .GroupVersionKindsHasUpgradeConfiguration (gvk ) {
63
- // Set internalcfg to an empty struct value the deserializer will populate
64
- internalcfg = & kubeadmapi.UpgradeConfiguration {}
65
- // Decode the bytes into the internal struct. Under the hood, the bytes will be unmarshalled into the
66
- // right external version, defaulted, and converted into the internal version.
67
- if err := runtime .DecodeInto (kubeadmscheme .Codecs .UniversalDecoder (), bytes , internalcfg ); err != nil {
68
- return nil , err
69
- }
70
- continue
71
- }
63
+ upgradeBytes = bytes
64
+ }
72
65
73
- // If the group is neither a kubeadm core type or of a supported component config group, we dump a warning about it being ignored
74
- if ! componentconfigs .Scheme .IsGroupRegistered (gvk .Group ) {
75
- klog .Warningf ("[config] WARNING: Ignored YAML document with GroupVersionKind %v\n " , gvk )
76
- }
66
+ if len (upgradeBytes ) == 0 {
67
+ return nil , errors .Errorf ("no %s found in the supplied config" , constants .UpgradeConfigurationKind )
77
68
}
78
69
79
- // If UpgradeConfiguration wasn't given, default it by creating an external struct instance, default it and convert into the internal type
80
- if internalcfg == nil {
81
- extinitcfg := & kubeadmapiv1.UpgradeConfiguration {}
82
- kubeadmscheme .Scheme .Default (extinitcfg )
83
- // Set upgradeCfg to an empty struct value the deserializer will populate
84
- internalcfg = & kubeadmapi.UpgradeConfiguration {}
85
- if err := kubeadmscheme .Scheme .Convert (extinitcfg , internalcfg , nil ); err != nil {
86
- return nil , err
87
- }
70
+ // Set internalcfg to an empty struct value the deserializer will populate
71
+ internalcfg := & kubeadmapi.UpgradeConfiguration {}
72
+ // Decode the bytes into the internal struct. Under the hood, the bytes will be unmarshalled into the
73
+ // right external version, defaulted, and converted into the internal version.
74
+ if err := runtime .DecodeInto (kubeadmscheme .Codecs .UniversalDecoder (), upgradeBytes , internalcfg ); err != nil {
75
+ return nil , err
88
76
}
89
77
90
78
// Validates cfg
@@ -96,9 +84,6 @@ func documentMapToUpgradeConfiguration(gvkmap kubeadmapi.DocumentMap, allowDepre
96
84
}
97
85
98
86
// DocMapToUpgradeConfiguration converts documentMap to an internal, defaulted and validated UpgradeConfiguration object.
99
- // The map may contain many different YAML documents. These YAML documents are parsed one-by-one
100
- // and well-known ComponentConfig GroupVersionKinds are stored inside of the internal UpgradeConfiguration struct.
101
- // The resulting UpgradeConfiguration is then dynamically defaulted and validated prior to return.
102
87
func DocMapToUpgradeConfiguration (gvkmap kubeadmapi.DocumentMap ) (* kubeadmapi.UpgradeConfiguration , error ) {
103
88
return documentMapToUpgradeConfiguration (gvkmap , false )
104
89
}
@@ -123,18 +108,8 @@ func LoadUpgradeConfigurationFromFile(cfgPath string, _ LoadOrDefaultConfigurati
123
108
// Convert documentMap to internal UpgradeConfiguration, InitConfiguration and ClusterConfiguration from config file will be ignored.
124
109
// Upgrade should respect the cluster configuration from the existing cluster, re-configure the cluster with a InitConfiguration and
125
110
// ClusterConfiguration from the config file is not allowed for upgrade.
126
- if isKubeadmConfigPresent (docmap ) {
127
- if upgradeCfg , err = DocMapToUpgradeConfiguration (docmap ); err != nil {
128
- return nil , err
129
- }
130
- }
131
-
132
- // Check is there any component configs defined in the config file.
133
- for gvk := range docmap {
134
- if componentCfgGV .Has (gvk .Group ) {
135
- klog .Warningf ("[config] WARNING: YAML document with Component Configs %v is deprecated for upgrade and will be ignored \n " , gvk .Group )
136
- continue
137
- }
111
+ if upgradeCfg , err = DocMapToUpgradeConfiguration (docmap ); err != nil {
112
+ return nil , err
138
113
}
139
114
140
115
return upgradeCfg , nil
0 commit comments