mirror of
https://github.com/dsx-ai-factory/nvke.git
synced 2026-12-07 04:35:58 +08:00
* chore: replace customer site names ytl and az61 with site-2 and site-1 Signed-off-by: Byron McAdams <bmcadams@nvidia.com> * revert: keep fleet release names matching nke-site-deploy verbatim Signed-off-by: Byron McAdams <bmcadams@nvidia.com> * fix(e2e): match GB200 fleet release exclusions by prefix, not customer name Signed-off-by: Byron McAdams <bmcadams@nvidia.com> * fix: match release exclusions exactly unless prefix ends in a dash Signed-off-by: Byron McAdams <bmcadams@nvidia.com> --------- Signed-off-by: Byron McAdams <bmcadams@nvidia.com>
75 lines
2.4 KiB
Go
75 lines
2.4 KiB
Go
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package naming
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestValidateNodeNamePrefix(t *testing.T) {
|
|
clusterName := "runtime-dgxc-k8s-forge-site-2-dev1"
|
|
maxPrefix := strings.Repeat("a", MaxNodeNamePrefixLen(clusterName))
|
|
|
|
t.Run("accepts prefix at limit", func(t *testing.T) {
|
|
require.NoError(t, ValidateNodeNamePrefix(clusterName, maxPrefix))
|
|
})
|
|
|
|
t.Run("rejects prefix over limit", func(t *testing.T) {
|
|
err := ValidateNodeNamePrefix(clusterName, maxPrefix+"x")
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "nodeNamePrefix")
|
|
require.Contains(t, err.Error(), "too long")
|
|
})
|
|
|
|
t.Run("rejects empty prefix", func(t *testing.T) {
|
|
err := ValidateNodeNamePrefix(clusterName, " ")
|
|
require.EqualError(t, err, "nodeNamePrefix must not be empty")
|
|
})
|
|
|
|
t.Run("rejects cluster name that leaves no room for prefix", func(t *testing.T) {
|
|
err := ValidateNodeNamePrefix(strings.Repeat("a", MaxGeneratedNodeNameLength), "cp")
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "cluster name")
|
|
require.Contains(t, err.Error(), "too long")
|
|
})
|
|
}
|
|
|
|
func TestValidateClusterNameForNodeNaming(t *testing.T) {
|
|
t.Run("accepts cluster name with room for prefix", func(t *testing.T) {
|
|
require.NoError(t, ValidateClusterNameForNodeNaming("my-cluster"))
|
|
})
|
|
|
|
t.Run("rejects cluster name that leaves no room for prefix", func(t *testing.T) {
|
|
err := ValidateClusterNameForNodeNaming(strings.Repeat("a", MaxGeneratedNodeNameLength))
|
|
require.Error(t, err)
|
|
require.Contains(t, err.Error(), "cluster name")
|
|
require.Contains(t, err.Error(), "too long")
|
|
})
|
|
}
|
|
|
|
func TestGenerateNodeName(t *testing.T) {
|
|
t.Run("retries on collision", func(t *testing.T) {
|
|
// Simulate node_set_controller naming without real randomness:
|
|
// real-use: GenerateNodeName(existingNodeNames, cluster.Name, pool.NodeNamePrefix, seededRand.Intn)
|
|
// test: existingNames holds one taken node; randIntn returns suffix 0 then 1 in order.
|
|
attempts := 0
|
|
name := GenerateNodeName(
|
|
[]string{"mycluster-cp-0000"}, // existingNames — suffix 0000 already provisioned
|
|
"mycluster",
|
|
"cp",
|
|
func(int) int { // randIntn stub — 1st pick collides, 2nd is returned
|
|
attempts++
|
|
if attempts == 1 {
|
|
return 0
|
|
}
|
|
return 1
|
|
},
|
|
)
|
|
require.Equal(t, "mycluster-cp-0001", name)
|
|
})
|
|
}
|