Skip to content

Commit fc668a4

Browse files
authored
Merge pull request #6934 from oscr/add-init-list-images-cmd
✨ Add `clusterctl init list-images` command
2 parents 7e772e2 + 6e08475 commit fc668a4

File tree

5 files changed

+109
-33
lines changed

5 files changed

+109
-33
lines changed

cmd/clusterctl/cmd/init.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,30 +78,25 @@ var initCmd = &cobra.Command{
7878
clusterctl init --infrastructure=aws,vsphere
7979
8080
# Initialize a management cluster with a custom target namespace for the provider resources.
81-
clusterctl init --infrastructure aws --target-namespace foo
82-
83-
# Lists the container images required for initializing the management cluster.
84-
#
85-
# Note: This command is a dry-run; it won't perform any action other than printing to screen.
86-
clusterctl init --infrastructure aws --list-images`),
81+
clusterctl init --infrastructure aws --target-namespace foo`),
8782
Args: cobra.NoArgs,
8883
RunE: func(cmd *cobra.Command, args []string) error {
8984
return runInit()
9085
},
9186
}
9287

9388
func init() {
94-
initCmd.Flags().StringVar(&initOpts.kubeconfig, "kubeconfig", "",
89+
initCmd.PersistentFlags().StringVar(&initOpts.kubeconfig, "kubeconfig", "",
9590
"Path to the kubeconfig for the management cluster. If unspecified, default discovery rules apply.")
96-
initCmd.Flags().StringVar(&initOpts.kubeconfigContext, "kubeconfig-context", "",
91+
initCmd.PersistentFlags().StringVar(&initOpts.kubeconfigContext, "kubeconfig-context", "",
9792
"Context to be used within the kubeconfig file. If empty, current context will be used.")
98-
initCmd.Flags().StringVar(&initOpts.coreProvider, "core", "",
93+
initCmd.PersistentFlags().StringVar(&initOpts.coreProvider, "core", "",
9994
"Core provider version (e.g. cluster-api:v1.1.5) to add to the management cluster. If unspecified, Cluster API's latest release is used.")
100-
initCmd.Flags().StringSliceVarP(&initOpts.infrastructureProviders, "infrastructure", "i", nil,
95+
initCmd.PersistentFlags().StringSliceVarP(&initOpts.infrastructureProviders, "infrastructure", "i", nil,
10196
"Infrastructure providers and versions (e.g. aws:v0.5.0) to add to the management cluster.")
102-
initCmd.Flags().StringSliceVarP(&initOpts.bootstrapProviders, "bootstrap", "b", nil,
97+
initCmd.PersistentFlags().StringSliceVarP(&initOpts.bootstrapProviders, "bootstrap", "b", nil,
10398
"Bootstrap providers and versions (e.g. kubeadm:v1.1.5) to add to the management cluster. If unspecified, Kubeadm bootstrap provider's latest release is used.")
104-
initCmd.Flags().StringSliceVarP(&initOpts.controlPlaneProviders, "control-plane", "c", nil,
99+
initCmd.PersistentFlags().StringSliceVarP(&initOpts.controlPlaneProviders, "control-plane", "c", nil,
105100
"Control plane providers and versions (e.g. kubeadm:v1.1.5) to add to the management cluster. If unspecified, the Kubeadm control plane provider's latest release is used.")
106101
initCmd.Flags().StringVarP(&initOpts.targetNamespace, "target-namespace", "n", "",
107102
"The target namespace where the providers should be deployed. If unspecified, the provider components' default namespace is used.")
@@ -112,10 +107,11 @@ func init() {
112107
initCmd.Flags().BoolVar(&initOpts.validate, "validate", true,
113108
"If true, clusterctl will validate that the deployments will succeed on the management cluster.")
114109

115-
// TODO: Move this to a sub-command or similar, it shouldn't really be a flag.
116110
initCmd.Flags().BoolVar(&initOpts.listImages, "list-images", false,
117111
"Lists the container images required for initializing the management cluster (without actually installing the providers)")
112+
_ = initCmd.Flags().MarkDeprecated("list-images", "use 'clusterctl init list-images' instead.")
118113

114+
initCmd.AddCommand(initListImagesCmd)
119115
RootCmd.AddCommand(initCmd)
120116
}
121117

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
Copyright 2022 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package cmd
18+
19+
import (
20+
"fmt"
21+
22+
"github.com/spf13/cobra"
23+
24+
"sigs.k8s.io/cluster-api/cmd/clusterctl/client"
25+
)
26+
27+
var initListImagesCmd = &cobra.Command{
28+
Use: "list-images",
29+
Short: "Lists the container images required for initializing the management cluster",
30+
Long: LongDesc(`
31+
Lists the container images required for initializing the management cluster.
32+
33+
See https://cluster-api.sigs.k8s.io for more details.`),
34+
35+
Example: Examples(`
36+
# Lists the container images required for initializing the management cluster.
37+
#
38+
# Note: This command is a dry-run; it won't perform any action other than printing to screen.
39+
clusterctl init list-images --infrastructure aws
40+
41+
# List infrastructure, bootstrap, control-plane and core images
42+
clusterctl init list-images --infrastructure vcd --bootstrap kubeadm --control-plane nested --core cluster-api:v1.2.0
43+
`),
44+
Args: cobra.NoArgs,
45+
RunE: func(cmd *cobra.Command, args []string) error {
46+
return runInitListImages()
47+
},
48+
}
49+
50+
func runInitListImages() error {
51+
c, err := client.New(cfgFile)
52+
if err != nil {
53+
return err
54+
}
55+
56+
options := client.InitOptions{
57+
Kubeconfig: client.Kubeconfig{Path: initOpts.kubeconfig, Context: initOpts.kubeconfigContext},
58+
CoreProvider: initOpts.coreProvider,
59+
BootstrapProviders: initOpts.bootstrapProviders,
60+
ControlPlaneProviders: initOpts.controlPlaneProviders,
61+
InfrastructureProviders: initOpts.infrastructureProviders,
62+
LogUsageInstructions: false,
63+
}
64+
65+
images, err := c.InitImages(options)
66+
if err != nil {
67+
return err
68+
}
69+
70+
for _, i := range images {
71+
fmt.Println(i)
72+
}
73+
return nil
74+
}

docs/book/src/clusterctl/commands/additional-commands.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ or in the provided directory.
2222
# clusterctl version
2323

2424
Print clusterctl version.
25+
26+
# clusterctl init list-images
27+
28+
Lists the container images required for initializing the management cluster.
Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
# clusterctl commands
22

3-
| Command | Description |
4-
|------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
5-
| [`clusterctl alpha rollout`](alpha-rollout.md) | Manages the rollout of Cluster API resources. For example: MachineDeployments. |
6-
| [`clusterctl alpha topology plan`](alpha-topology-plan.md) | Describes the changes to a cluster topology for a given input. |
7-
| [`clusterctl backup`](additional-commands.md#clusterctl-backup) | Backup Cluster API objects and all their dependencies from a management cluster. |
8-
| [`clusterctl completion`](completion.md) | Output shell completion code for the specified shell (bash or zsh). |
9-
| [`clusterctl config`](additional-commands.md#clusterctl-config-repositories) | Display clusterctl configuration. |
10-
| [`clusterctl delete`](delete.md) | Delete one or more providers from the management cluster. |
11-
| [`clusterctl describe cluster`](describe-cluster.md) | Describe workload clusters. |
12-
| [`clusterctl generate cluster`](generate-cluster.md) | Generate templates for creating workload clusters. |
13-
| [`clusterctl generate provider`](generate-provider.md) | Generate templates for provider components. |
14-
| [`clusterctl generate yaml`](generate-yaml.md) | Process yaml using clusterctl's yaml processor. |
15-
| [`clusterctl get kubeconfig`](get-kubeconfig.md) | Gets the kubeconfig file for accessing a workload cluster. |
16-
| [`clusterctl help`](additional-commands.md#clusterctl-help) | Help about any command. |
17-
| [`clusterctl init`](init.md) | Initialize a management cluster. |
18-
| [`clusterctl move`](move.md) | Move Cluster API objects and all their dependencies between management clusters. |
19-
| [`clusterctl restore`](additional-commands.md#clusterctl-restore) | Restore Cluster API objects from file by glob. |
20-
| [`clusterctl upgrade plan`](upgrade.md#upgrade-plan) | Provide a list of recommended target versions for upgrading Cluster API providers in a management cluster. |
21-
| [`clusterctl upgrade apply`](upgrade.md#upgrade-apply) | Apply new versions of Cluster API core and providers in a management cluster. |
22-
| [`clusterctl version`](additional-commands.md#clusterctl-version) | Print clusterctl version. |
3+
| Command | Description |
4+
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
5+
| [`clusterctl alpha rollout`](alpha-rollout.md) | Manages the rollout of Cluster API resources. For example: MachineDeployments. |
6+
| [`clusterctl alpha topology plan`](alpha-topology-plan.md) | Describes the changes to a cluster topology for a given input. |
7+
| [`clusterctl backup`](additional-commands.md#clusterctl-backup) | Backup Cluster API objects and all their dependencies from a management cluster. |
8+
| [`clusterctl completion`](completion.md) | Output shell completion code for the specified shell (bash or zsh). |
9+
| [`clusterctl config`](additional-commands.md#clusterctl-config-repositories) | Display clusterctl configuration. |
10+
| [`clusterctl delete`](delete.md) | Delete one or more providers from the management cluster. |
11+
| [`clusterctl describe cluster`](describe-cluster.md) | Describe workload clusters. |
12+
| [`clusterctl generate cluster`](generate-cluster.md) | Generate templates for creating workload clusters. |
13+
| [`clusterctl generate provider`](generate-provider.md) | Generate templates for provider components. |
14+
| [`clusterctl generate yaml`](generate-yaml.md) | Process yaml using clusterctl's yaml processor. |
15+
| [`clusterctl get kubeconfig`](get-kubeconfig.md) | Gets the kubeconfig file for accessing a workload cluster. |
16+
| [`clusterctl help`](additional-commands.md#clusterctl-help) | Help about any command. |
17+
| [`clusterctl init`](init.md) | Initialize a management cluster. |
18+
| [`clusterctl init list-images`](additional-commands.md#clusterctl-init-list-images) | Lists the container images required for initializing the management cluster. |
19+
| [`clusterctl move`](move.md) | Move Cluster API objects and all their dependencies between management clusters. |
20+
| [`clusterctl restore`](additional-commands.md#clusterctl-restore) | Restore Cluster API objects from file by glob. |
21+
| [`clusterctl upgrade plan`](upgrade.md#upgrade-plan) | Provide a list of recommended target versions for upgrading Cluster API providers in a management cluster. |
22+
| [`clusterctl upgrade apply`](upgrade.md#upgrade-apply) | Apply new versions of Cluster API core and providers in a management cluster. |
23+
| [`clusterctl version`](additional-commands.md#clusterctl-version) | Print clusterctl version. |

docs/book/src/developer/providers/v1.2-to-v1.3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ in Cluster API are kept in sync with the versions used by `sigs.k8s.io/controlle
1919
### Deprecation
2020

2121
- `sigs.k8s.io/cluster-api/controllers/external.CloneTemplate` has been deprecated and will be removed in a future release. Please use `sigs.k8s.io/cluster-api/controllers/external.CreateFromTemplate` instead.
22+
- `clusterctl init --list-images` has been deprecated and will be removed in a future release. Please use `clusterctl init list-images` instead.
2223

2324
### Removals
2425

0 commit comments

Comments
 (0)