Skip to content

Commit

Permalink
Update validation for the cluster name length (#8046)
Browse files Browse the repository at this point in the history
  • Loading branch information
sp1999 authored Apr 26, 2024
1 parent 882ad80 commit 1f3de75
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
9 changes: 6 additions & 3 deletions pkg/api/v1alpha1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,12 @@ func ValidateClusterName(clusterName string) error {
}

func ValidateClusterNameLength(clusterName string) error {
// vSphere has the maximum length for clusters to be 80 chars
if len(clusterName) > 80 {
return fmt.Errorf("number of characters in %v should be less than 81", clusterName)
// docker container hostname can have a maximum length of 64 characters. we append "-eks-a-cluster"
// to get the KinD cluster's name and on top of this, KinD also adds a "-control-plane suffix" to
// the cluster name to arrive at the name for the control plane node (container), which makes the
// control plane node name 64 characters in length.
if len(clusterName) > 35 {
return fmt.Errorf("number of characters in %v should be less than 36", clusterName)
}
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/v1alpha1/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func TestClusterNameLength(t *testing.T) {
}{
{
name: "SuccessClusterNameLength",
clusterName: "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm",
clusterName: "cluster-name-less-than-36-chars",
wantErr: nil,
},
{
name: "FailureClusterNameLength",
clusterName: "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm12345",
wantErr: errors.New("number of characters in qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm12345 should be less than 81"),
clusterName: "cluster-name-equals-to-36-characters",
wantErr: errors.New("number of characters in cluster-name-equals-to-36-characters should be less than 36"),
},
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/validations/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func TestValidateClusterNameArg(t *testing.T) {
},
{
name: "Failure Cluster Length",
args: []string{"qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm12345"},
expectedError: errors.New("number of characters in qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm12345 should be less than 81"),
expectedArg: "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnm12345",
args: []string{"cluster-name-equals-to-36-characters"},
expectedError: errors.New("number of characters in cluster-name-equals-to-36-characters should be less than 36"),
expectedArg: "cluster-name-equals-to-36-characters",
},
}

Expand Down

0 comments on commit 1f3de75

Please sign in to comment.