@@ -116,7 +116,7 @@ func NewCmdConfigPrintJoinDefaults(out io.Writer) *cobra.Command {
116
116
}
117
117
118
118
func newCmdConfigPrintActionDefaults (out io.Writer , action string , configBytesProc func () ([]byte , error )) * cobra.Command {
119
- componentConfigs := []string {}
119
+ kinds := []string {}
120
120
cmd := & cobra.Command {
121
121
Use : fmt .Sprintf ("%s-defaults" , action ),
122
122
Short : fmt .Sprintf ("Print default %s configuration, that can be used for 'kubeadm %s'" , action , action ),
@@ -127,11 +127,15 @@ func newCmdConfigPrintActionDefaults(out io.Writer, action string, configBytesPr
127
127
not perform the real computation for creating a token.
128
128
` ), action , action , placeholderToken ),
129
129
RunE : func (cmd * cobra.Command , args []string ) error {
130
- return runConfigPrintActionDefaults (out , componentConfigs , configBytesProc )
130
+ groups , err := mapLegacyKindsToGroups (kinds )
131
+ if err != nil {
132
+ return err
133
+ }
134
+ return runConfigPrintActionDefaults (out , groups , configBytesProc )
131
135
},
132
136
}
133
- cmd .Flags ().StringSliceVar (& componentConfigs , "component-configs" , componentConfigs ,
134
- fmt .Sprintf ("A comma-separated list for component config API objects to print the default values for. Available values: %v. If this flag is not set, no component configs will be printed." , getSupportedComponentConfigAPIObjects ()))
137
+ cmd .Flags ().StringSliceVar (& kinds , "component-configs" , kinds ,
138
+ fmt .Sprintf ("A comma-separated list for component config API objects to print the default values for. Available values: %v. If this flag is not set, no component configs will be printed." , getSupportedComponentConfigKinds ()))
135
139
return cmd
136
140
}
137
141
@@ -154,35 +158,49 @@ func runConfigPrintActionDefaults(out io.Writer, componentConfigs []string, conf
154
158
return nil
155
159
}
156
160
157
- func getDefaultComponentConfigBytes (apiObject string ) ([]byte , error ) {
158
- registration , ok := componentconfigs .Known [componentconfigs .RegistrationKind (apiObject )]
159
- if ! ok {
160
- return []byte {}, errors .Errorf ("--component-configs needs to contain some of %v" , getSupportedComponentConfigAPIObjects ())
161
- }
162
-
161
+ func getDefaultComponentConfigBytes (group string ) ([]byte , error ) {
163
162
defaultedInitConfig , err := getDefaultedInitConfig ()
164
163
if err != nil {
165
164
return []byte {}, err
166
165
}
167
166
168
- realObj , ok := registration . GetFromInternalConfig ( & defaultedInitConfig .ClusterConfiguration )
167
+ componentCfg , ok := defaultedInitConfig .ComponentConfigs [ group ]
169
168
if ! ok {
170
- return []byte {}, errors .New ( "GetFromInternalConfig failed" )
169
+ return []byte {}, errors .Errorf ( "cannot get defaulted config for component group %q" , group )
171
170
}
172
171
173
- return registration .Marshal (realObj )
172
+ return componentCfg .Marshal ()
174
173
}
175
174
176
- // getSupportedComponentConfigAPIObjects returns all currently supported component config API object names
177
- func getSupportedComponentConfigAPIObjects () []string {
175
+ // legacyKindToGroupMap maps between the old API object types and the new way of specifying component configs (by group)
176
+ var legacyKindToGroupMap = map [string ]string {
177
+ "KubeletConfiguration" : componentconfigs .KubeletGroup ,
178
+ "KubeProxyConfiguration" : componentconfigs .KubeProxyGroup ,
179
+ }
180
+
181
+ // getSupportedComponentConfigKinds returns all currently supported component config API object names
182
+ func getSupportedComponentConfigKinds () []string {
178
183
objects := []string {}
179
- for componentType := range componentconfigs . Known {
184
+ for componentType := range legacyKindToGroupMap {
180
185
objects = append (objects , string (componentType ))
181
186
}
182
187
sort .Strings (objects )
183
188
return objects
184
189
}
185
190
191
+ func mapLegacyKindsToGroups (kinds []string ) ([]string , error ) {
192
+ groups := []string {}
193
+ for _ , kind := range kinds {
194
+ group , ok := legacyKindToGroupMap [kind ]
195
+ if ok {
196
+ groups = append (groups , group )
197
+ } else {
198
+ return nil , errors .Errorf ("--component-configs needs to contain some of %v" , getSupportedComponentConfigKinds ())
199
+ }
200
+ }
201
+ return groups , nil
202
+ }
203
+
186
204
func getDefaultedInitConfig () (* kubeadmapi.InitConfiguration , error ) {
187
205
initCfg := & kubeadmapiv1beta2.InitConfiguration {
188
206
LocalAPIEndpoint : kubeadmapiv1beta2.APIEndpoint {AdvertiseAddress : "1.2.3.4" },
0 commit comments