@@ -85,7 +85,6 @@ func NewCmdConfig(out io.Writer) *cobra.Command {
85
85
86
86
kubeConfigFile = cmdutil .FindExistingKubeConfig (kubeConfigFile )
87
87
cmd .AddCommand (NewCmdConfigPrint (out ))
88
- cmd .AddCommand (NewCmdConfigPrintDefault (out ))
89
88
cmd .AddCommand (NewCmdConfigMigrate (out ))
90
89
cmd .AddCommand (NewCmdConfigUpload (out , & kubeConfigFile ))
91
90
cmd .AddCommand (NewCmdConfigView (out , & kubeConfigFile ))
@@ -142,76 +141,31 @@ func runConfigPrintActionDefaults(out io.Writer, componentConfigs []string, conf
142
141
143
142
allBytes := [][]byte {initialConfig }
144
143
for _ , componentConfig := range componentConfigs {
145
- cfgBytes , err := getDefaultComponentConfigAPIObjectBytes (componentConfig )
144
+ cfgBytes , err := getDefaultComponentConfigBytes (componentConfig )
146
145
kubeadmutil .CheckErr (err )
147
146
allBytes = append (allBytes , cfgBytes )
148
147
}
149
148
150
149
fmt .Fprint (out , string (bytes .Join (allBytes , []byte (constants .YAMLDocumentSeparator ))))
151
150
}
152
151
153
- // NewCmdConfigPrintDefault returns cobra.Command for "kubeadm config print-default" command
154
- func NewCmdConfigPrintDefault (out io.Writer ) * cobra.Command {
155
- apiObjects := []string {}
156
- cmd := & cobra.Command {
157
- Use : "print-default" ,
158
- Aliases : []string {"print-defaults" },
159
- Short : "Print the default values for a kubeadm configuration object." ,
160
- Long : fmt .Sprintf (dedent .Dedent (`
161
- This command prints objects such as the default InitConfiguration that is used for 'kubeadm init' and 'kubeadm upgrade',
162
- and the default JoinConfiguration object that is used for 'kubeadm join'.
163
-
164
- For documentation visit: https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3
165
-
166
- Note that sensitive values like the Bootstrap Token fields are replaced with placeholder values like %q in order to pass validation but
167
- not perform the real computation for creating a token.
168
- ` ), placeholderToken ),
169
- Deprecated : "Please, use `kubeadm config print` instead." ,
170
- Run : func (cmd * cobra.Command , args []string ) {
171
- if len (apiObjects ) == 0 {
172
- apiObjects = getSupportedAPIObjects ()
173
- }
174
- allBytes := [][]byte {}
175
- for _ , apiObject := range apiObjects {
176
- cfgBytes , err := getDefaultAPIObjectBytes (apiObject )
177
- kubeadmutil .CheckErr (err )
178
- allBytes = append (allBytes , cfgBytes )
179
- }
180
- fmt .Fprint (out , string (bytes .Join (allBytes , []byte (constants .YAMLDocumentSeparator ))))
181
- },
182
- }
183
- cmd .Flags ().StringSliceVar (& apiObjects , "api-objects" , apiObjects ,
184
- fmt .Sprintf ("A comma-separated list for API objects to print the default values for. Available values: %v. This flag unset means 'print all known objects'" , getAllAPIObjectNames ()))
185
- return cmd
186
- }
187
-
188
- func getDefaultComponentConfigAPIObjectBytes (apiObject string ) ([]byte , error ) {
152
+ func getDefaultComponentConfigBytes (apiObject string ) ([]byte , error ) {
189
153
registration , ok := componentconfigs .Known [componentconfigs .RegistrationKind (apiObject )]
190
154
if ! ok {
191
155
return []byte {}, errors .Errorf ("--component-configs needs to contain some of %v" , getSupportedComponentConfigAPIObjects ())
192
156
}
193
- return getDefaultComponentConfigBytes (registration )
194
- }
195
-
196
- func getDefaultAPIObjectBytes (apiObject string ) ([]byte , error ) {
197
- switch apiObject {
198
- case constants .InitConfigurationKind :
199
- return getDefaultInitConfigBytesByKind (constants .InitConfigurationKind )
200
157
201
- case constants .ClusterConfigurationKind :
202
- return getDefaultInitConfigBytesByKind (constants .ClusterConfigurationKind )
203
-
204
- case constants .JoinConfigurationKind :
205
- return getDefaultNodeConfigBytes ()
158
+ defaultedInitConfig , err := getDefaultedInitConfig ()
159
+ if err != nil {
160
+ return []byte {}, err
161
+ }
206
162
207
- default :
208
- // Is this a component config?
209
- registration , ok := componentconfigs .Known [componentconfigs .RegistrationKind (apiObject )]
210
- if ! ok {
211
- return []byte {}, errors .Errorf ("--api-object needs to be one of %v" , getAllAPIObjectNames ())
212
- }
213
- return getDefaultComponentConfigBytes (registration )
163
+ realObj , ok := registration .GetFromInternalConfig (& defaultedInitConfig .ClusterConfiguration )
164
+ if ! ok {
165
+ return []byte {}, errors .New ("GetFromInternalConfig failed" )
214
166
}
167
+
168
+ return registration .Marshal (realObj )
215
169
}
216
170
217
171
// getSupportedComponentConfigAPIObjects returns all currently supported component config API object names
@@ -223,23 +177,6 @@ func getSupportedComponentConfigAPIObjects() []string {
223
177
return objects
224
178
}
225
179
226
- // getSupportedAPIObjects returns all currently supported API object names
227
- func getSupportedAPIObjects () []string {
228
- baseObjects := []string {constants .InitConfigurationKind , constants .ClusterConfigurationKind , constants .JoinConfigurationKind }
229
- objects := getSupportedComponentConfigAPIObjects ()
230
- objects = append (objects , baseObjects ... )
231
- return objects
232
- }
233
-
234
- // getAllAPIObjectNames returns currently supported API object names and their historical aliases
235
- // NB. currently there is no historical supported API objects, but we keep this function for future changes
236
- func getAllAPIObjectNames () []string {
237
- historicAPIObjectAliases := []string {}
238
- objects := getSupportedAPIObjects ()
239
- objects = append (objects , historicAPIObjectAliases ... )
240
- return objects
241
- }
242
-
243
180
func getDefaultedInitConfig () (* kubeadmapi.InitConfiguration , error ) {
244
181
return configutil .ConfigFileAndDefaultsToInternalConfig ("" , & kubeadmapiv1beta1.InitConfiguration {
245
182
// TODO: Probably move to getDefaultedClusterConfig?
@@ -260,18 +197,6 @@ func getDefaultInitConfigBytes() ([]byte, error) {
260
197
return configutil .MarshalKubeadmConfigObject (internalcfg )
261
198
}
262
199
263
- func getDefaultInitConfigBytesByKind (kind string ) ([]byte , error ) {
264
- b , err := getDefaultInitConfigBytes ()
265
- if err != nil {
266
- return []byte {}, err
267
- }
268
- gvkmap , err := kubeadmutil .SplitYAMLDocuments (b )
269
- if err != nil {
270
- return []byte {}, err
271
- }
272
- return gvkmap [kubeadmapiv1beta1 .SchemeGroupVersion .WithKind (kind )], nil
273
- }
274
-
275
200
func getDefaultNodeConfigBytes () ([]byte , error ) {
276
201
internalcfg , err := configutil .JoinConfigFileAndDefaultsToInternalConfig ("" , & kubeadmapiv1beta1.JoinConfiguration {
277
202
Discovery : kubeadmapiv1beta1.Discovery {
@@ -289,20 +214,6 @@ func getDefaultNodeConfigBytes() ([]byte, error) {
289
214
return configutil .MarshalKubeadmConfigObject (internalcfg )
290
215
}
291
216
292
- func getDefaultComponentConfigBytes (registration componentconfigs.Registration ) ([]byte , error ) {
293
- defaultedInitConfig , err := getDefaultedInitConfig ()
294
- if err != nil {
295
- return []byte {}, err
296
- }
297
-
298
- realobj , ok := registration .GetFromInternalConfig (& defaultedInitConfig .ClusterConfiguration )
299
- if ! ok {
300
- return []byte {}, errors .New ("GetFromInternalConfig failed" )
301
- }
302
-
303
- return registration .Marshal (realobj )
304
- }
305
-
306
217
// NewCmdConfigMigrate returns cobra.Command for "kubeadm config migrate" command
307
218
func NewCmdConfigMigrate (out io.Writer ) * cobra.Command {
308
219
var oldCfgPath , newCfgPath string
0 commit comments