Skip to content

Commit f5b4666

Browse files
authored
Merge pull request #2221 from fabriziopandini/clusterctl-simplify-template-naming
🐛clusterctl: simplify cluster template naming
2 parents 5cfd0f1 + d6e8d57 commit f5b4666

File tree

10 files changed

+15
-75
lines changed

10 files changed

+15
-75
lines changed

cmd/clusterctl/cmd/config_cluster.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
type configClusterOptions struct {
2828
kubeconfig string
2929
flavor string
30-
bootstrapProvider string
3130
infrastructureProvider string
3231

3332
targetNamespace string
@@ -53,10 +52,6 @@ var configClusterClusterCmd = &cobra.Command{
5352
# default infrastructure provider and default bootstrap provider installed in the cluster.
5453
clusterctl config cluster my-cluster
5554
56-
# Generates a yaml file for creating a Cluster API workload cluster using
57-
# specified infrastructure and bootstrap provider
58-
clusterctl config cluster my-cluster --infrastructure=aws --bootstrap=kubeadm
59-
6055
# Generates a yaml file for creating a Cluster API workload cluster using
6156
# specified version of the AWS infrastructure provider
6257
clusterctl config cluster my-cluster --infrastructure=aws:v0.4.1
@@ -82,7 +77,6 @@ func init() {
8277
configClusterClusterCmd.Flags().StringVarP(&cc.kubeconfig, "kubeconfig", "", "", "Path to the kubeconfig file to use for accessing the management cluster. If empty, default rules for kubeconfig discovery will be used")
8378

8479
configClusterClusterCmd.Flags().StringVarP(&cc.infrastructureProvider, "infrastructure", "i", "", "The infrastructure provider that should be used for creating the workload cluster")
85-
configClusterClusterCmd.Flags().StringVarP(&cc.bootstrapProvider, "bootstrap", "b", "kubeadm", "The provider that should be used for bootstrapping Kubernetes nodes in the workload cluster")
8680

8781
configClusterClusterCmd.Flags().StringVarP(&cc.flavor, "flavor", "f", "", "The template variant to be used for creating the workload cluster")
8882
configClusterClusterCmd.Flags().StringVarP(&cc.targetNamespace, "target-namespace", "n", "", "The namespace where the objects describing the workload cluster should be deployed. If not specified, the current namespace will be used")
@@ -103,7 +97,6 @@ func runGenerateCluster(name string) error {
10397
Kubeconfig: cc.kubeconfig,
10498
InfrastructureProvider: cc.infrastructureProvider,
10599
Flavor: cc.flavor,
106-
BootstrapProvider: cc.bootstrapProvider,
107100
ClusterName: name,
108101
TargetNamespace: cc.targetNamespace,
109102
KubernetesVersion: cc.kubernetesVersion,

cmd/clusterctl/pkg/client/client.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ type GetClusterTemplateOptions struct {
6161
// InfrastructureProvider that should be used for creating the workload cluster.
6262
InfrastructureProvider string
6363

64-
// BootstrapProvider that should be used for bootstrapping Kubernetes nodes in the workload cluster.
65-
BootstrapProvider string
66-
6764
// Flavor defines the template variant to be used for creating the workload cluster.
6865
Flavor string
6966

cmd/clusterctl/pkg/client/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (c *clusterctlClient) GetClusterTemplate(options GetClusterTemplateOptions)
116116
return nil, err
117117
}
118118

119-
template, err := repo.Templates(version).Get(options.Flavor, options.BootstrapProvider, options.TargetNamespace)
119+
template, err := repo.Templates(version).Get(options.Flavor, options.TargetNamespace)
120120
if err != nil {
121121
return nil, err
122122
}

cmd/clusterctl/pkg/client/config_test.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
308308
repository1 := newFakeRepository(infraProviderConfig, config1.Variables()).
309309
WithPaths("root", "components").
310310
WithDefaultVersion("v3.0.0").
311-
WithFile("v3.0.0", "config-kubeadm.yaml", templateYAML("ns3", "${ CLUSTER_NAME }"))
311+
WithFile("v3.0.0", "cluster-template.yaml", templateYAML("ns3", "${ CLUSTER_NAME }"))
312312

313313
cluster1 := newFakeCluster("kubeconfig").
314314
WithProviderInventory(infraProviderConfig.Name(), infraProviderConfig.Type(), "v3.0.0", "foo", "bar")
@@ -327,8 +327,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
327327
providerType clusterctlv1.ProviderType
328328
version string
329329
flavor string
330-
bootstrap string
331-
path string
332330
variables []string
333331
targetNamespace string
334332
yaml []byte
@@ -347,7 +345,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
347345
Kubeconfig: "kubeconfig",
348346
InfrastructureProvider: "infra:v3.0.0",
349347
Flavor: "",
350-
BootstrapProvider: "kubeadm",
351348
ClusterName: "test",
352349
TargetNamespace: "ns1",
353350
ControlPlaneMachineCount: 1,
@@ -359,8 +356,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
359356
providerType: clusterctlv1.InfrastructureProviderType,
360357
version: "v3.0.0",
361358
flavor: "",
362-
bootstrap: "kubeadm",
363-
path: "config-kubeadm.yaml",
364359
variables: []string{"CLUSTER_NAME"}, // variable detected
365360
targetNamespace: "ns1",
366361
yaml: templateYAML("ns1", "test"), // original template modified with target namespace and variable replacement
@@ -373,7 +368,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
373368
Kubeconfig: "kubeconfig",
374369
InfrastructureProvider: "", // empty triggers auto-detection of the provider name/version
375370
Flavor: "",
376-
BootstrapProvider: "kubeadm",
377371
ClusterName: "test",
378372
TargetNamespace: "ns1",
379373
ControlPlaneMachineCount: 1,
@@ -385,8 +379,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
385379
providerType: clusterctlv1.InfrastructureProviderType,
386380
version: "v3.0.0",
387381
flavor: "",
388-
bootstrap: "kubeadm",
389-
path: "config-kubeadm.yaml",
390382
variables: []string{"CLUSTER_NAME"}, // variable detected
391383
targetNamespace: "ns1",
392384
yaml: templateYAML("ns1", "test"), // original template modified with target namespace and variable replacement
@@ -399,7 +391,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
399391
Kubeconfig: "kubeconfig",
400392
InfrastructureProvider: "infra:v3.0.0",
401393
Flavor: "",
402-
BootstrapProvider: "kubeadm",
403394
ClusterName: "test",
404395
TargetNamespace: "", // empty triggers usage of the current namespace
405396
ControlPlaneMachineCount: 1,
@@ -411,8 +402,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
411402
providerType: clusterctlv1.InfrastructureProviderType,
412403
version: "v3.0.0",
413404
flavor: "",
414-
bootstrap: "kubeadm",
415-
path: "config-kubeadm.yaml",
416405
variables: []string{"CLUSTER_NAME"}, // variable detected
417406
targetNamespace: "default",
418407
yaml: templateYAML("default", "test"), // original template modified with target namespace and variable replacement
@@ -444,9 +433,6 @@ func Test_clusterctlClient_GetClusterTemplate(t *testing.T) {
444433
if got.Flavor() != tt.want.flavor {
445434
t.Errorf("Flavor() got = %v, want %v", got.Flavor(), tt.want.flavor)
446435
}
447-
if got.Bootstrap() != tt.want.bootstrap {
448-
t.Errorf("Bootstrap() got = %v, want %v", got.Bootstrap(), tt.want.bootstrap)
449-
}
450436
if !reflect.DeepEqual(got.Variables(), tt.want.variables) {
451437
t.Errorf("Variables() got = %v, want %v", got.Variables(), tt.want.variables)
452438
}

cmd/clusterctl/pkg/client/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ func fakeEmptyCluster() *fakeClient {
413413
WithDefaultVersion("v3.0.0").
414414
WithFile("v3.0.0", "components.yaml", componentsYAML("ns4")).
415415
WithFile("v3.1.0", "components.yaml", componentsYAML("ns4")).
416-
WithFile("v3.0.0", "config-kubeadm.yaml", templateYAML("ns4", "test"))
416+
WithFile("v3.0.0", "cluster-template.yaml", templateYAML("ns4", "test"))
417417

418418
cluster1 := newFakeCluster("kubeconfig")
419419

cmd/clusterctl/pkg/client/repository/template.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ type Template interface {
3939
// A flavor is a variant of cluster template supported by the provider, like e.g. Prod, Test.
4040
Flavor() string
4141

42-
// Bootstrap provider used by the cluster template.
43-
Bootstrap() string
44-
4542
// Variables required by the template.
4643
// This value is derived by the template YAML.
4744
Variables() []string
@@ -61,7 +58,6 @@ type template struct {
6158
config.Provider
6259
version string
6360
flavor string
64-
bootstrap string
6561
variables []string
6662
targetNamespace string
6763
objs []unstructured.Unstructured
@@ -78,10 +74,6 @@ func (t *template) Flavor() string {
7874
return t.flavor
7975
}
8076

81-
func (t *template) Bootstrap() string {
82-
return t.bootstrap
83-
}
84-
8577
func (t *template) Variables() []string {
8678
return t.variables
8779
}
@@ -103,7 +95,6 @@ type newTemplateOptions struct {
10395
provider config.Provider
10496
version string
10597
flavor string
106-
bootstrap string
10798
rawYaml []byte
10899
configVariablesClient config.VariablesClient
109100
targetNamespace string
@@ -134,7 +125,6 @@ func newTemplate(options newTemplateOptions) (*template, error) {
134125
Provider: options.provider,
135126
version: options.version,
136127
flavor: options.flavor,
137-
bootstrap: options.bootstrap,
138128
variables: variables,
139129
targetNamespace: options.targetNamespace,
140130
objs: objs,

cmd/clusterctl/pkg/client/repository/template_client.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type TemplateOptions struct {
3838
// TemplateClient has methods to work with cluster templates hosted on a provider repository.
3939
// Templates are yaml files to be used for creating a guest cluster.
4040
type TemplateClient interface {
41-
Get(flavor, bootstrap, targetNamespace string) (Template, error)
41+
Get(flavor, targetNamespace string) (Template, error)
4242
}
4343

4444
// templateClient implements TemplateClient.
@@ -62,14 +62,10 @@ func newTemplateClient(provider config.Provider, version string, repository Repo
6262
}
6363
}
6464

65-
// Get return the template for the flavor/bootstrap provider specified.
65+
// Get return the template for the flavor specified.
6666
// In case the template does not exists, an error is returned.
67-
// Get assumes the following naming convention for templates: config[-<flavor_name>]-<bootstrap_provider_name>.yaml
68-
func (c *templateClient) Get(flavor, bootstrap, targetNamespace string) (Template, error) {
69-
if bootstrap == "" {
70-
return nil, errors.New("invalid arguments: please provide a bootstrap provider name")
71-
}
72-
67+
// Get assumes the following naming convention for templates: cluster-template[-<flavor_name>].yaml
68+
func (c *templateClient) Get(flavor, targetNamespace string) (Template, error) {
7369
if targetNamespace == "" {
7470
return nil, errors.New("invalid arguments: please provide a targetNamespace")
7571
}
@@ -79,11 +75,11 @@ func (c *templateClient) Get(flavor, bootstrap, targetNamespace string) (Templat
7975
version := c.version
8076

8177
// building template name according with the naming convention
82-
name := "config"
78+
name := "cluster-template"
8379
if flavor != "" {
8480
name = fmt.Sprintf("%s-%s", name, flavor)
8581
}
86-
name = fmt.Sprintf("%s-%s.yaml", name, bootstrap)
82+
name = fmt.Sprintf("%s.yaml", name)
8783

8884
// read the component YAML, reading the local override file if it exists, otherwise read from the provider repository
8985
rawYaml, err := getLocalOverride(c.provider, version, name)
@@ -102,7 +98,6 @@ func (c *templateClient) Get(flavor, bootstrap, targetNamespace string) (Templat
10298
provider: c.provider,
10399
version: version,
104100
flavor: flavor,
105-
bootstrap: bootstrap,
106101
rawYaml: rawYaml,
107102
configVariablesClient: c.configVariablesClient,
108103
targetNamespace: targetNamespace,

cmd/clusterctl/pkg/client/repository/template_client_test.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ func Test_templates_Get(t *testing.T) {
3838
}
3939
type args struct {
4040
flavor string
41-
bootstrap string
4241
targetNamespace string
4342
}
4443
type want struct {
4544
provider config.Provider
4645
version string
4746
flavor string
48-
bootstrap string
4947
variables []string
5048
targetNamespace string
5149
}
@@ -64,19 +62,17 @@ func Test_templates_Get(t *testing.T) {
6462
repository: test.NewFakeRepository().
6563
WithPaths("root", "").
6664
WithDefaultVersion("v1.0").
67-
WithFile("v1.0", "config-kubeadm.yaml", templateMapYaml),
65+
WithFile("v1.0", "cluster-template.yaml", templateMapYaml),
6866
configVariablesClient: test.NewFakeVariableClient().WithVar(variableName, variableValue),
6967
},
7068
args: args{
7169
flavor: "",
72-
bootstrap: "kubeadm",
7370
targetNamespace: "ns1",
7471
},
7572
want: want{
7673
provider: p1,
7774
version: "v1.0",
7875
flavor: "",
79-
bootstrap: "kubeadm",
8076
variables: []string{variableName},
8177
targetNamespace: "ns1",
8278
},
@@ -90,19 +86,17 @@ func Test_templates_Get(t *testing.T) {
9086
repository: test.NewFakeRepository().
9187
WithPaths("root", "").
9288
WithDefaultVersion("v1.0").
93-
WithFile("v1.0", "config-prod-kubeadm.yaml", templateMapYaml),
89+
WithFile("v1.0", "cluster-template-prod.yaml", templateMapYaml),
9490
configVariablesClient: test.NewFakeVariableClient().WithVar(variableName, variableValue),
9591
},
9692
args: args{
9793
flavor: "prod",
98-
bootstrap: "kubeadm",
9994
targetNamespace: "ns1",
10095
},
10196
want: want{
10297
provider: p1,
10398
version: "v1.0",
10499
flavor: "prod",
105-
bootstrap: "kubeadm",
106100
variables: []string{variableName},
107101
targetNamespace: "ns1",
108102
},
@@ -120,7 +114,6 @@ func Test_templates_Get(t *testing.T) {
120114
},
121115
args: args{
122116
flavor: "",
123-
bootstrap: "kubeadm",
124117
targetNamespace: "ns1",
125118
},
126119
wantErr: true,
@@ -129,7 +122,7 @@ func Test_templates_Get(t *testing.T) {
129122
for _, tt := range tests {
130123
t.Run(tt.name, func(t *testing.T) {
131124
f := newTemplateClient(tt.fields.provider, tt.fields.version, tt.fields.repository, tt.fields.configVariablesClient)
132-
got, err := f.Get(tt.args.flavor, tt.args.bootstrap, tt.args.targetNamespace)
125+
got, err := f.Get(tt.args.flavor, tt.args.targetNamespace)
133126
if (err != nil) != tt.wantErr {
134127
t.Fatalf("error = %v, wantErr %v", err, tt.wantErr)
135128
}
@@ -149,10 +142,6 @@ func Test_templates_Get(t *testing.T) {
149142
t.Errorf("got.Version() = %v, want = %v ", got.Version(), tt.want.version)
150143
}
151144

152-
if got.Bootstrap() != tt.want.bootstrap {
153-
t.Errorf("got.Bootstrap() = %v, want = %v ", got.Bootstrap(), tt.want.bootstrap)
154-
}
155-
156145
if !reflect.DeepEqual(got.Variables(), tt.want.variables) {
157146
t.Errorf("got.Variables() = %v, want = %v ", got.Variables(), tt.want.variables)
158147
}

cmd/clusterctl/pkg/client/repository/template_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func Test_newTemplate(t *testing.T) {
4343
provider config.Provider
4444
version string
4545
flavor string
46-
bootstrap string
4746
rawYaml []byte
4847
configVariablesClient config.VariablesClient
4948
targetNamespace string
@@ -52,7 +51,6 @@ func Test_newTemplate(t *testing.T) {
5251
provider config.Provider
5352
version string
5453
flavor string
55-
bootstrap string
5654
variables []string
5755
targetNamespace string
5856
}
@@ -68,7 +66,6 @@ func Test_newTemplate(t *testing.T) {
6866
provider: p1,
6967
version: "v1.2.3",
7068
flavor: "flavor",
71-
bootstrap: "bootstrap",
7269
rawYaml: templateMapYaml,
7370
configVariablesClient: test.NewFakeVariableClient().WithVar(variableName, variableValue),
7471
targetNamespace: "ns1",
@@ -77,7 +74,6 @@ func Test_newTemplate(t *testing.T) {
7774
provider: p1,
7875
version: "v1.2.3",
7976
flavor: "flavor",
80-
bootstrap: "bootstrap",
8177
variables: []string{variableName},
8278
targetNamespace: "ns1",
8379
},
@@ -90,7 +86,6 @@ func Test_newTemplate(t *testing.T) {
9086
provider: tt.args.provider,
9187
version: tt.args.version,
9288
flavor: tt.args.flavor,
93-
bootstrap: tt.args.bootstrap,
9489
rawYaml: tt.args.rawYaml,
9590
configVariablesClient: tt.args.configVariablesClient,
9691
targetNamespace: tt.args.targetNamespace,
@@ -114,10 +109,6 @@ func Test_newTemplate(t *testing.T) {
114109
t.Errorf("got.Version() = %v, want = %v ", got.Version(), tt.want.version)
115110
}
116111

117-
if got.Bootstrap() != tt.want.bootstrap {
118-
t.Errorf("got.Bootstrap() = %v, want = %v ", got.Bootstrap(), tt.want.bootstrap)
119-
}
120-
121112
if !reflect.DeepEqual(got.Variables(), tt.want.variables) {
122113
t.Errorf("got.Variables() = %v, want = %v ", got.Variables(), tt.want.variables)
123114
}

docs/book/src/clusterctl/provider-contract.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,10 @@ The following rules apply:
142142
#### Naming conventions
143143

144144
Cluster templates MUST be stored in the same folder as the component YAML and follow this naming convention:
145-
1. The default cluster template should be named `config-{bootstrap}.yaml`. e.g `config-kubeadm.yaml`
146-
2. Additional cluster template should be named `config-{flavor}-{bootstrap}.yaml`. e.g `config-production-kubeadm.yaml`
145+
1. The default cluster template should be named `cluster-template.yaml`.
146+
2. Additional cluster template should be named `cluster-template-{flavor}.yaml`. e.g `cluster-template-prod.yaml`
147147

148-
`{bootstrap}` is the name of the bootstrap provider used in the template; `{flavor}` is the name the user can pass to the
149-
`clusterctl config cluster --flavor` flag to identify the specific template to use.
148+
`{flavor}` is the name the user can pass to the `clusterctl config cluster --flavor` flag to identify the specific template to use.
150149

151150
Each provider SHOULD create user facing documentation with the list of available cluster templates.
152151

0 commit comments

Comments
 (0)