Skip to content

🐛 clusterctl: accept upper case version #12237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/clusterctl/client/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *clusterctlClient) getComponentsByName(ctx context.Context, provider str

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

name = t[0]
name = strings.ToLower(t[0])
if err := validateDNS1123Label(name); err != nil {
return "", "", errors.Wrapf(err, "invalid provider name %q. Provider name should be in the form name[:version] and the name should be valid", provider)
}
Expand Down
22 changes: 20 additions & 2 deletions cmd/clusterctl/client/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ func Test_parseProviderName(t *testing.T) {
wantVersion: "version",
wantErr: false,
},
{
name: "name & upper case version",
args: args{
provider: "provider:1.0.0-VERSION",
},
wantName: "provider",
wantVersion: "1.0.0-VERSION",
wantErr: false,
},
{
name: "upper name & version",
args: args{
provider: "PROVIDER:VERSION",
},
wantName: "provider",
wantVersion: "VERSION",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -59,9 +77,9 @@ func Test_parseProviderName(t *testing.T) {
gotName, gotVersion, err := parseProviderName(tt.args.provider)
if tt.wantErr {
g.Expect(err).To(HaveOccurred())
} else {
g.Expect(err).ToNot(HaveOccurred())
return
}
g.Expect(err).ToNot(HaveOccurred())
g.Expect(gotName).To(Equal(tt.wantName))

g.Expect(gotVersion).To(Equal(tt.wantVersion))
Expand Down
4 changes: 4 additions & 0 deletions cmd/clusterctl/client/config/providers_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,10 @@ func validateProvider(r Provider) error {
return errors.New("name value cannot be empty")
}

if r.Name() != strings.ToLower(r.Name()) {
return errors.Errorf("provider name %s must be in lower case", r.Name())
}

if (r.Name() == ClusterAPIProviderName) != (r.Type() == clusterctlv1.CoreProviderType) {
return errors.Errorf("name %s must be used with the %s type (name: %s, type: %s)", ClusterAPIProviderName, clusterctlv1.CoreProviderType, r.Name(), r.Type())
}
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/developer/providers/contracts/clusterctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ This is the process to add a new provider to the pre-defined list of providers s
- 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;
each provider must have a unique name & type in the pre-defined list of providers shipped with `clusterctl`; the provider's name
must be declared in the issue above and abide to the following naming convention:
- The name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character.
- 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.
- The name length should not exceed 63 characters.
- For providers not in the kubernetes-sigs org, in order to prevent conflicts the `clusterctl` name must be prefixed with
the provider's GitHub org name followed by `-` (see note below).
Expand Down
Loading