Skip to content

Commit ffb670b

Browse files
committed
kubeadm: remove kubeadm config print-defaults
Signed-off-by: Rostislav M. Georgiev <[email protected]>
1 parent eab977f commit ffb670b

File tree

3 files changed

+11
-104
lines changed

3 files changed

+11
-104
lines changed

cmd/kubeadm/app/cmd/config.go

+11-100
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ func NewCmdConfig(out io.Writer) *cobra.Command {
8585

8686
kubeConfigFile = cmdutil.FindExistingKubeConfig(kubeConfigFile)
8787
cmd.AddCommand(NewCmdConfigPrint(out))
88-
cmd.AddCommand(NewCmdConfigPrintDefault(out))
8988
cmd.AddCommand(NewCmdConfigMigrate(out))
9089
cmd.AddCommand(NewCmdConfigUpload(out, &kubeConfigFile))
9190
cmd.AddCommand(NewCmdConfigView(out, &kubeConfigFile))
@@ -142,76 +141,31 @@ func runConfigPrintActionDefaults(out io.Writer, componentConfigs []string, conf
142141

143142
allBytes := [][]byte{initialConfig}
144143
for _, componentConfig := range componentConfigs {
145-
cfgBytes, err := getDefaultComponentConfigAPIObjectBytes(componentConfig)
144+
cfgBytes, err := getDefaultComponentConfigBytes(componentConfig)
146145
kubeadmutil.CheckErr(err)
147146
allBytes = append(allBytes, cfgBytes)
148147
}
149148

150149
fmt.Fprint(out, string(bytes.Join(allBytes, []byte(constants.YAMLDocumentSeparator))))
151150
}
152151

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) {
189153
registration, ok := componentconfigs.Known[componentconfigs.RegistrationKind(apiObject)]
190154
if !ok {
191155
return []byte{}, errors.Errorf("--component-configs needs to contain some of %v", getSupportedComponentConfigAPIObjects())
192156
}
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)
200157

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+
}
206162

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")
214166
}
167+
168+
return registration.Marshal(realObj)
215169
}
216170

217171
// getSupportedComponentConfigAPIObjects returns all currently supported component config API object names
@@ -223,23 +177,6 @@ func getSupportedComponentConfigAPIObjects() []string {
223177
return objects
224178
}
225179

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-
243180
func getDefaultedInitConfig() (*kubeadmapi.InitConfiguration, error) {
244181
return configutil.ConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1beta1.InitConfiguration{
245182
// TODO: Probably move to getDefaultedClusterConfig?
@@ -260,18 +197,6 @@ func getDefaultInitConfigBytes() ([]byte, error) {
260197
return configutil.MarshalKubeadmConfigObject(internalcfg)
261198
}
262199

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-
275200
func getDefaultNodeConfigBytes() ([]byte, error) {
276201
internalcfg, err := configutil.JoinConfigFileAndDefaultsToInternalConfig("", &kubeadmapiv1beta1.JoinConfiguration{
277202
Discovery: kubeadmapiv1beta1.Discovery{
@@ -289,20 +214,6 @@ func getDefaultNodeConfigBytes() ([]byte, error) {
289214
return configutil.MarshalKubeadmConfigObject(internalcfg)
290215
}
291216

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-
306217
// NewCmdConfigMigrate returns cobra.Command for "kubeadm config migrate" command
307218
func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
308219
var oldCfgPath, newCfgPath string

docs/.generated_docs

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ docs/man/man1/kubeadm-config-images-list.1
127127
docs/man/man1/kubeadm-config-images-pull.1
128128
docs/man/man1/kubeadm-config-images.1
129129
docs/man/man1/kubeadm-config-migrate.1
130-
docs/man/man1/kubeadm-config-print-default.1
131130
docs/man/man1/kubeadm-config-print-init-defaults.1
132131
docs/man/man1/kubeadm-config-print-join-defaults.1
133132
docs/man/man1/kubeadm-config-print.1

docs/man/man1/kubeadm-config-print-default.1

-3
This file was deleted.

0 commit comments

Comments
 (0)