Skip to content

Commit e19b605

Browse files
authored
🐛 clusterctl: accept upper case version (#12237)
* fix: parseProviderName Signed-off-by: sivchari <shibuuuu5@gmail.com> * update the doc Signed-off-by: sivchari <shibuuuu5@gmail.com> * add condition for validateProvider Signed-off-by: sivchari <shibuuuu5@gmail.com> * fix review findings Signed-off-by: sivchari <shibuuuu5@gmail.com> --------- Signed-off-by: sivchari <shibuuuu5@gmail.com>
1 parent 71e01be commit e19b605

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

cmd/clusterctl/client/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *clusterctlClient) getComponentsByName(ctx context.Context, provider str
6262

6363
// parseProviderName defines a utility function that parses the abbreviated syntax for name[:version].
6464
func parseProviderName(provider string) (name string, version string, err error) {
65-
t := strings.Split(strings.ToLower(provider), ":")
65+
t := strings.Split(provider, ":")
6666
if len(t) > 2 {
6767
return "", "", errors.Errorf("invalid provider name %q. Provider name should be in the form name[:version]", provider)
6868
}
@@ -71,7 +71,7 @@ func parseProviderName(provider string) (name string, version string, err error)
7171
return "", "", errors.Errorf("invalid provider name %q. Provider name should be in the form name[:version] and name cannot be empty", provider)
7272
}
7373

74-
name = t[0]
74+
name = strings.ToLower(t[0])
7575
if err := validateDNS1123Label(name); err != nil {
7676
return "", "", errors.Wrapf(err, "invalid provider name %q. Provider name should be in the form name[:version] and the name should be valid", provider)
7777
}

cmd/clusterctl/client/common_test.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ func Test_parseProviderName(t *testing.T) {
5151
wantVersion: "version",
5252
wantErr: false,
5353
},
54+
{
55+
name: "name & upper case version",
56+
args: args{
57+
provider: "provider:1.0.0-VERSION",
58+
},
59+
wantName: "provider",
60+
wantVersion: "1.0.0-VERSION",
61+
wantErr: false,
62+
},
63+
{
64+
name: "upper name & version",
65+
args: args{
66+
provider: "PROVIDER:VERSION",
67+
},
68+
wantName: "provider",
69+
wantVersion: "VERSION",
70+
wantErr: false,
71+
},
5472
}
5573
for _, tt := range tests {
5674
t.Run(tt.name, func(t *testing.T) {
@@ -59,9 +77,9 @@ func Test_parseProviderName(t *testing.T) {
5977
gotName, gotVersion, err := parseProviderName(tt.args.provider)
6078
if tt.wantErr {
6179
g.Expect(err).To(HaveOccurred())
62-
} else {
63-
g.Expect(err).ToNot(HaveOccurred())
80+
return
6481
}
82+
g.Expect(err).ToNot(HaveOccurred())
6583
g.Expect(gotName).To(Equal(tt.wantName))
6684

6785
g.Expect(gotVersion).To(Equal(tt.wantVersion))

cmd/clusterctl/client/config/providers_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,10 @@ func validateProvider(r Provider) error {
526526
return errors.New("name value cannot be empty")
527527
}
528528

529+
if r.Name() != strings.ToLower(r.Name()) {
530+
return errors.Errorf("provider name %s must be in lower case", r.Name())
531+
}
532+
529533
if (r.Name() == ClusterAPIProviderName) != (r.Type() == clusterctlv1.CoreProviderType) {
530534
return errors.Errorf("name %s must be used with the %s type (name: %s, type: %s)", ClusterAPIProviderName, clusterctlv1.CoreProviderType, r.Name(), r.Type())
531535
}

docs/book/src/developer/providers/contracts/clusterctl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This is the process to add a new provider to the pre-defined list of providers s
5757
- As soon as possible, create an issue to the [Cluster API repository](https://sigs.k8s.io/cluster-api) declaring the intent to add a new provider;
5858
each provider must have a unique name & type in the pre-defined list of providers shipped with `clusterctl`; the provider's name
5959
must be declared in the issue above and abide to the following naming convention:
60-
- The name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character.
60+
- The name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character. If the name includes upper case alphanumeric characters, clusterctl enforces it lower case it.
6161
- The name length should not exceed 63 characters.
6262
- For providers not in the kubernetes-sigs org, in order to prevent conflicts the `clusterctl` name must be prefixed with
6363
the provider's GitHub org name followed by `-` (see note below).

0 commit comments

Comments
 (0)