Skip to content

Commit 5daa7ee

Browse files
author
Ayush Rangwala
committed
Rename ListVariableOnly flag in TemplateInput
- As the part of adding --raw flag to clusterctl, the requirements to rename these flags which allows skipping the processing of template using variables - renamed the variable ListVariableOnly to SkipTemplateProcess in all the files using it including test files and comments Signed-off-by: Ayush Rangwala <[email protected]>
1 parent 45a0abb commit 5daa7ee

10 files changed

+76
-67
lines changed

cmd/clusterctl/client/client_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"k8s.io/apimachinery/pkg/runtime"
2626
"k8s.io/apimachinery/pkg/runtime/serializer"
2727
"k8s.io/apimachinery/pkg/util/wait"
28+
2829
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
2930
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
3031
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
@@ -477,7 +478,7 @@ type fakeTemplateClient struct {
477478
processor yaml.Processor
478479
}
479480

480-
func (f *fakeTemplateClient) Get(flavor, targetNamespace string, listVariablesOnly bool) (repository.Template, error) {
481+
func (f *fakeTemplateClient) Get(flavor, targetNamespace string, skipTemplateProcess bool) (repository.Template, error) {
481482
name := "cluster-template"
482483
if flavor != "" {
483484
name = fmt.Sprintf("%s-%s", name, flavor)
@@ -493,7 +494,7 @@ func (f *fakeTemplateClient) Get(flavor, targetNamespace string, listVariablesOn
493494
ConfigVariablesClient: f.configVariablesClient,
494495
Processor: f.processor,
495496
TargetNamespace: targetNamespace,
496-
ListVariablesOnly: listVariablesOnly,
497+
SkipTemplateProcess: skipTemplateProcess,
497498
})
498499
}
499500

cmd/clusterctl/client/cluster/template.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ import (
3737
// TemplateClient has methods to work with templates stored in the cluster/out of the provider repository.
3838
type TemplateClient interface {
3939
// GetFromConfigMap returns a workload cluster template from the given ConfigMap.
40-
GetFromConfigMap(namespace, name, dataKey, targetNamespace string, listVariablesOnly bool) (repository.Template, error)
40+
GetFromConfigMap(namespace, name, dataKey, targetNamespace string, skipTemplateProcess bool) (repository.Template, error)
4141

4242
// GetFromURL returns a workload cluster template from the given URL.
43-
GetFromURL(templateURL, targetNamespace string, listVariablesOnly bool) (repository.Template, error)
43+
GetFromURL(templateURL, targetNamespace string, skipTemplateProcess bool) (repository.Template, error)
4444
}
4545

4646
// templateClient implements TemplateClient.
@@ -71,7 +71,7 @@ func newTemplateClient(input TemplateClientInput) *templateClient {
7171
}
7272
}
7373

74-
func (t *templateClient) GetFromConfigMap(configMapNamespace, configMapName, configMapDataKey, targetNamespace string, listVariablesOnly bool) (repository.Template, error) {
74+
func (t *templateClient) GetFromConfigMap(configMapNamespace, configMapName, configMapDataKey, targetNamespace string, skipTemplateProcess bool) (repository.Template, error) {
7575
if configMapNamespace == "" {
7676
return nil, errors.New("invalid GetFromConfigMap operation: missing configMapNamespace value")
7777
}
@@ -104,11 +104,11 @@ func (t *templateClient) GetFromConfigMap(configMapNamespace, configMapName, con
104104
ConfigVariablesClient: t.configClient.Variables(),
105105
Processor: t.processor,
106106
TargetNamespace: targetNamespace,
107-
ListVariablesOnly: listVariablesOnly,
107+
SkipTemplateProcess: skipTemplateProcess,
108108
})
109109
}
110110

111-
func (t *templateClient) GetFromURL(templateURL, targetNamespace string, listVariablesOnly bool) (repository.Template, error) {
111+
func (t *templateClient) GetFromURL(templateURL, targetNamespace string, skipTemplateProcess bool) (repository.Template, error) {
112112
if templateURL == "" {
113113
return nil, errors.New("invalid GetFromURL operation: missing templateURL value")
114114
}
@@ -123,7 +123,7 @@ func (t *templateClient) GetFromURL(templateURL, targetNamespace string, listVar
123123
ConfigVariablesClient: t.configClient.Variables(),
124124
Processor: t.processor,
125125
TargetNamespace: targetNamespace,
126-
ListVariablesOnly: listVariablesOnly,
126+
SkipTemplateProcess: skipTemplateProcess,
127127
})
128128
}
129129

cmd/clusterctl/client/cluster/template_test.go

+33-33
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func Test_templateClient_GetFromConfigMap(t *testing.T) {
6767
configClient config.Client
6868
}
6969
type args struct {
70-
configMapNamespace string
71-
configMapName string
72-
configMapDataKey string
73-
targetNamespace string
74-
listVariablesOnly bool
70+
configMapNamespace string
71+
configMapName string
72+
configMapDataKey string
73+
targetNamespace string
74+
skipTemplateProcess bool
7575
}
7676
tests := []struct {
7777
name string
@@ -87,11 +87,11 @@ func Test_templateClient_GetFromConfigMap(t *testing.T) {
8787
configClient: configClient,
8888
},
8989
args: args{
90-
configMapNamespace: "ns1",
91-
configMapName: "my-template",
92-
configMapDataKey: "prod",
93-
targetNamespace: "",
94-
listVariablesOnly: false,
90+
configMapNamespace: "ns1",
91+
configMapName: "my-template",
92+
configMapDataKey: "prod",
93+
targetNamespace: "",
94+
skipTemplateProcess: false,
9595
},
9696
want: template,
9797
wantErr: false,
@@ -103,11 +103,11 @@ func Test_templateClient_GetFromConfigMap(t *testing.T) {
103103
configClient: configClient,
104104
},
105105
args: args{
106-
configMapNamespace: "ns1",
107-
configMapName: "something-else",
108-
configMapDataKey: "prod",
109-
targetNamespace: "",
110-
listVariablesOnly: false,
106+
configMapNamespace: "ns1",
107+
configMapName: "something-else",
108+
configMapDataKey: "prod",
109+
targetNamespace: "",
110+
skipTemplateProcess: false,
111111
},
112112
want: "",
113113
wantErr: true,
@@ -119,11 +119,11 @@ func Test_templateClient_GetFromConfigMap(t *testing.T) {
119119
configClient: configClient,
120120
},
121121
args: args{
122-
configMapNamespace: "ns1",
123-
configMapName: "my-template",
124-
configMapDataKey: "something-else",
125-
targetNamespace: "",
126-
listVariablesOnly: false,
122+
configMapNamespace: "ns1",
123+
configMapName: "my-template",
124+
configMapDataKey: "something-else",
125+
targetNamespace: "",
126+
skipTemplateProcess: false,
127127
},
128128
want: "",
129129
wantErr: true,
@@ -135,7 +135,7 @@ func Test_templateClient_GetFromConfigMap(t *testing.T) {
135135

136136
processor := yaml.NewSimpleProcessor()
137137
tc := newTemplateClient(TemplateClientInput{tt.fields.proxy, tt.fields.configClient, processor})
138-
got, err := tc.GetFromConfigMap(tt.args.configMapNamespace, tt.args.configMapName, tt.args.configMapDataKey, tt.args.targetNamespace, tt.args.listVariablesOnly)
138+
got, err := tc.GetFromConfigMap(tt.args.configMapNamespace, tt.args.configMapName, tt.args.configMapDataKey, tt.args.targetNamespace, tt.args.skipTemplateProcess)
139139
if tt.wantErr {
140140
g.Expect(err).To(HaveOccurred())
141141
return
@@ -147,7 +147,7 @@ func Test_templateClient_GetFromConfigMap(t *testing.T) {
147147
ConfigVariablesClient: configClient.Variables(),
148148
Processor: processor,
149149
TargetNamespace: tt.args.targetNamespace,
150-
ListVariablesOnly: tt.args.listVariablesOnly,
150+
SkipTemplateProcess: tt.args.skipTemplateProcess,
151151
})
152152
g.Expect(err).NotTo(HaveOccurred())
153153
g.Expect(got).To(Equal(wantTemplate))
@@ -308,9 +308,9 @@ func Test_templateClient_GetFromURL(t *testing.T) {
308308
g.Expect(os.WriteFile(path, []byte(template), 0600)).To(Succeed())
309309

310310
type args struct {
311-
templateURL string
312-
targetNamespace string
313-
listVariablesOnly bool
311+
templateURL string
312+
targetNamespace string
313+
skipTemplateProcess bool
314314
}
315315
tests := []struct {
316316
name string
@@ -321,19 +321,19 @@ func Test_templateClient_GetFromURL(t *testing.T) {
321321
{
322322
name: "Get from local file system",
323323
args: args{
324-
templateURL: path,
325-
targetNamespace: "",
326-
listVariablesOnly: false,
324+
templateURL: path,
325+
targetNamespace: "",
326+
skipTemplateProcess: false,
327327
},
328328
want: template,
329329
wantErr: false,
330330
},
331331
{
332332
name: "Get from GitHub",
333333
args: args{
334-
templateURL: "https://github.com/kubernetes-sigs/cluster-api/blob/master/config/default/cluster-template.yaml",
335-
targetNamespace: "",
336-
listVariablesOnly: false,
334+
templateURL: "https://github.com/kubernetes-sigs/cluster-api/blob/master/config/default/cluster-template.yaml",
335+
targetNamespace: "",
336+
skipTemplateProcess: false,
337337
},
338338
want: template,
339339
wantErr: false,
@@ -351,7 +351,7 @@ func Test_templateClient_GetFromURL(t *testing.T) {
351351
// override the github client factory
352352
c.gitHubClientFactory = gitHubClientFactory
353353

354-
got, err := c.GetFromURL(tt.args.templateURL, tt.args.targetNamespace, tt.args.listVariablesOnly)
354+
got, err := c.GetFromURL(tt.args.templateURL, tt.args.targetNamespace, tt.args.skipTemplateProcess)
355355
if tt.wantErr {
356356
g.Expect(err).To(HaveOccurred())
357357
return
@@ -364,7 +364,7 @@ func Test_templateClient_GetFromURL(t *testing.T) {
364364
ConfigVariablesClient: configClient.Variables(),
365365
Processor: processor,
366366
TargetNamespace: tt.args.targetNamespace,
367-
ListVariablesOnly: tt.args.listVariablesOnly,
367+
SkipTemplateProcess: tt.args.skipTemplateProcess,
368368
})
369369
g.Expect(err).NotTo(HaveOccurred())
370370
g.Expect(got).To(Equal(wantTemplate))

cmd/clusterctl/client/config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import (
2020
"io"
2121
"strconv"
2222

23-
"k8s.io/utils/pointer"
24-
2523
"github.com/pkg/errors"
2624
"k8s.io/apimachinery/pkg/util/version"
25+
"k8s.io/utils/pointer"
26+
2727
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
2828
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
2929
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/repository"
@@ -66,9 +66,9 @@ type ProcessYAMLOptions struct {
6666
// URLSource to be used for reading the template
6767
URLSource *URLSourceOptions
6868

69-
// ListVariablesOnly return the list of variables expected by the template
69+
// SkipTemplateProcess return the list of variables expected by the template
7070
// without executing any further processing.
71-
ListVariablesOnly bool
71+
SkipTemplateProcess bool
7272
}
7373

7474
func (c *clusterctlClient) ProcessYAML(options ProcessYAMLOptions) (YamlPrinter, error) {
@@ -84,15 +84,15 @@ func (c *clusterctlClient) ProcessYAML(options ProcessYAMLOptions) (YamlPrinter,
8484
ConfigVariablesClient: c.configClient.Variables(),
8585
Processor: yaml.NewSimpleProcessor(),
8686
TargetNamespace: "",
87-
ListVariablesOnly: options.ListVariablesOnly,
87+
SkipTemplateProcess: options.SkipTemplateProcess,
8888
})
8989
}
9090

9191
// Technically we do not need to connect to the cluster. However, we are
9292
// leveraging the template client which exposes GetFromURL() is available
9393
// on the cluster client so we create a cluster client with default
9494
// configs to access it.
95-
cluster, err := c.clusterClientFactory(
95+
clstr, err := c.clusterClientFactory(
9696
ClusterClientFactoryInput{
9797
// use the default kubeconfig
9898
Kubeconfig: Kubeconfig{},
@@ -103,7 +103,7 @@ func (c *clusterctlClient) ProcessYAML(options ProcessYAMLOptions) (YamlPrinter,
103103
}
104104

105105
if options.URLSource != nil {
106-
return c.getTemplateFromURL(cluster, *options.URLSource, "", options.ListVariablesOnly)
106+
return c.getTemplateFromURL(clstr, *options.URLSource, "", options.SkipTemplateProcess)
107107
}
108108

109109
return nil, errors.New("unable to read custom template. Please specify a template source")

cmd/clusterctl/client/config_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
corev1 "k8s.io/api/core/v1"
2929
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3030
"k8s.io/utils/pointer"
31+
3132
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3233
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/cluster"
3334
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
@@ -904,7 +905,7 @@ v3: ${VAR3:-default3}`
904905
URLSource: &URLSourceOptions{
905906
URL: templateFile,
906907
},
907-
ListVariablesOnly: false,
908+
SkipTemplateProcess: false,
908909
},
909910
expectErr: false,
910911
expectedYaml: `v1: default1
@@ -913,12 +914,12 @@ v3: default3`,
913914
expectedVars: []string{"VAR1", "VAR2", "VAR3"},
914915
},
915916
{
916-
name: "returns the expected variables only if ListVariablesOnly is set",
917+
name: "returns the expected variables only if SkipTemplateProcess is set",
917918
options: ProcessYAMLOptions{
918919
URLSource: &URLSourceOptions{
919920
URL: templateFile,
920921
},
921-
ListVariablesOnly: true,
922+
SkipTemplateProcess: true,
922923
},
923924
expectErr: false,
924925
expectedYaml: ``,
@@ -935,7 +936,7 @@ v3: default3`,
935936
ReaderSource: &ReaderSourceOptions{
936937
Reader: inputReader,
937938
},
938-
ListVariablesOnly: false,
939+
SkipTemplateProcess: false,
939940
},
940941
expectErr: false,
941942
expectedYaml: `v1: default1
@@ -949,7 +950,7 @@ v3: default3`,
949950
ReaderSource: &ReaderSourceOptions{
950951
Reader: &errReader{},
951952
},
952-
ListVariablesOnly: false,
953+
SkipTemplateProcess: false,
953954
},
954955
expectErr: true,
955956
},

cmd/clusterctl/client/repository/template.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package repository
1919
import (
2020
"github.com/pkg/errors"
2121
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
22+
2223
"sigs.k8s.io/cluster-api/cmd/clusterctl/client/config"
2324
yaml "sigs.k8s.io/cluster-api/cmd/clusterctl/client/yamlprocessor"
2425
utilyaml "sigs.k8s.io/cluster-api/util/yaml"
@@ -34,7 +35,7 @@ type Template interface {
3435
// This value is derived from the template YAML.
3536
Variables() []string
3637

37-
// Variables used by the template with their default values. If the value is `nil`, there is no
38+
// VariableMap used by the template with their default values. If the value is `nil`, there is no
3839
// default and the variable is required.
3940
// This value is derived from the template YAML.
4041
VariableMap() map[string]*string
@@ -86,7 +87,7 @@ type TemplateInput struct {
8687
ConfigVariablesClient config.VariablesClient
8788
Processor yaml.Processor
8889
TargetNamespace string
89-
ListVariablesOnly bool
90+
SkipTemplateProcess bool
9091
}
9192

9293
// NewTemplate returns a new objects embedding a cluster template YAML file.
@@ -101,7 +102,7 @@ func NewTemplate(input TemplateInput) (Template, error) {
101102
return nil, err
102103
}
103104

104-
if input.ListVariablesOnly {
105+
if input.SkipTemplateProcess {
105106
return &template{
106107
variables: variables,
107108
variableMap: variableMap,

cmd/clusterctl/client/repository/template_client.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func newTemplateClient(input TemplateClientInput) *templateClient {
6565
// Get return the template for the flavor specified.
6666
// In case the template does not exists, an error is returned.
6767
// Get assumes the following naming convention for templates: cluster-template[-<flavor_name>].yaml.
68-
func (c *templateClient) Get(flavor, targetNamespace string, listVariablesOnly bool) (Template, error) {
68+
func (c *templateClient) Get(flavor, targetNamespace string, skipTemplateProcess bool) (Template, error) {
6969
log := logf.Log
7070

7171
if targetNamespace == "" {
@@ -96,5 +96,11 @@ func (c *templateClient) Get(flavor, targetNamespace string, listVariablesOnly b
9696
log.V(1).Info("Using", "Override", name, "Provider", c.provider.ManifestLabel(), "Version", version)
9797
}
9898

99-
return NewTemplate(TemplateInput{rawArtifact, c.configVariablesClient, c.processor, targetNamespace, listVariablesOnly})
99+
return NewTemplate(TemplateInput{
100+
rawArtifact,
101+
c.configVariablesClient,
102+
c.processor,
103+
targetNamespace,
104+
skipTemplateProcess,
105+
})
100106
}

cmd/clusterctl/client/repository/template_client_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func Test_templates_Get(t *testing.T) {
139139
wantErr: true,
140140
},
141141
{
142-
name: "pass if variables does not exists but listVariablesOnly flag is set",
142+
name: "pass if variables does not exists but skipTemplateProcess flag is set",
143143
fields: fields{
144144
version: "v1.0",
145145
provider: p1,

0 commit comments

Comments
 (0)