Skip to content
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

Update validation for the cluster name length #8046

Merged
merged 1 commit into from
Apr 26, 2024
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
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 {
Copy link
Member

@rahulbabu95 rahulbabu95 Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If Kind does limit the length only after 50 characters and we append "-eks-a-cluster" which is 14 characters in length shouldn't we check for > 36 here.? did you want to have a buffer just in case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the cluster name length is exactly 36 characters, then kubeadm init fails with a 404 Not Found error when making a GET request to the control plane node. I am not exactly sure why that happens but one possible reason could be that the node might be having a label name which exceeds 63 characters as labels have a limit of 63 characters.

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