diff --git a/pkg/tkn/compute_families_test.go b/pkg/tkn/compute_families_test.go new file mode 100644 index 000000000..7b0c7d620 --- /dev/null +++ b/pkg/tkn/compute_families_test.go @@ -0,0 +1,80 @@ +package tkn + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +// Tasks that have a compute-sizes conditional in their script and must also +// conditionally pass --compute-families in the else branch. +var tasksWithComputeFamiliesScript = map[string]struct{}{ + "infra-aws-rhel.yaml": {}, + "infra-aws-ocp-snc.yaml": {}, + "infra-aws-fedora.yaml": {}, + "infra-aws-rhel-ai.yaml": {}, + "infra-aws-eks.yaml": {}, + "infra-aws-kind.yaml": {}, + "infra-aws-windows-server.yaml": {}, +} + +// mac uses dedicated host provisioning — CLI does not accept --compute-families. +var tasksWithoutComputeFamiliesParam = map[string]struct{}{ + "infra-aws-mac.yaml": {}, +} + +func TestComputeFamiliesParamDefined(t *testing.T) { + root := moduleRoot(t) + for _, dir := range []string{"tkn", filepath.Join("tkn", "template")} { + entries, err := os.ReadDir(filepath.Join(root, dir)) + if err != nil { + t.Fatal(err) + } + for _, entry := range entries { + name := entry.Name() + if !isAWSInfraTask(name) { + continue + } + if _, skip := tasksWithoutComputeFamiliesParam[name]; skip { + continue + } + path := filepath.Join(root, dir, name) + data, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(data), "name: compute-families") { + t.Errorf("%s: missing 'compute-families' param definition", path) + } + } + } +} + +func TestComputeFamiliesPassedInScript(t *testing.T) { + root := moduleRoot(t) + for _, dir := range []string{"tkn", filepath.Join("tkn", "template")} { + entries, err := os.ReadDir(filepath.Join(root, dir)) + if err != nil { + t.Fatal(err) + } + for _, entry := range entries { + name := entry.Name() + if _, ok := tasksWithComputeFamiliesScript[name]; !ok { + continue + } + path := filepath.Join(root, dir, name) + data, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(data), "--compute-families") { + t.Errorf("%s: missing '--compute-families' flag in script", path) + } + } + } +} + +func isAWSInfraTask(name string) bool { + return strings.HasSuffix(name, ".yaml") && strings.HasPrefix(name, "infra-aws-") +} diff --git a/tkn/infra-aws-eks.yaml b/tkn/infra-aws-eks.yaml index edfa2079d..ac1845d00 100644 --- a/tkn/infra-aws-eks.yaml +++ b/tkn/infra-aws-eks.yaml @@ -102,6 +102,18 @@ spec: - name: load-balancer-controller description: Install AWS Load Balancer Controller (default false) default: 'false' + - name: compute-sizes + description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args + default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" + - name: cpus + description: Number of CPUs for the cloud instance (default 8) + default: '8' + - name: memory + description: Amount of RAM for the cloud instance in GiB (default 64) + default: '64' # Spot params - name: spot @@ -216,6 +228,13 @@ spec: cmd+="--conn-details-output /opt/cluster-info " cmd+="--version $(params.k8s-version) " cmd+="--arch $(params.arch) " + if [[ $(params.compute-sizes) != "" ]]; then + cmd+="--compute-sizes '$(params.compute-sizes)' " + else + cmd+="--cpus '$(params.cpus)' " + cmd+="--memory '$(params.memory)' " + cmd+="--compute-families '$(params.compute-families)' " + fi cmd+="--workers-desired $(params.workers-desired) " cmd+="--workers-max $(params.workers-max) " cmd+="--workers-min $(params.workers-min) " diff --git a/tkn/infra-aws-fedora.yaml b/tkn/infra-aws-fedora.yaml index df74f7d55..61cbc0b05 100644 --- a/tkn/infra-aws-fedora.yaml +++ b/tkn/infra-aws-fedora.yaml @@ -88,6 +88,9 @@ spec: - name: compute-sizes description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" - name: cpus description: Number of CPUs for the cloud instance (default 8) default: "8" @@ -255,6 +258,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " + cmd+="--compute-families '$(params.compute-families)' " fi if [[ "$(params.nested-virt)" == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/infra-aws-kind.yaml b/tkn/infra-aws-kind.yaml index c6392eb17..2d1c87f79 100644 --- a/tkn/infra-aws-kind.yaml +++ b/tkn/infra-aws-kind.yaml @@ -91,6 +91,12 @@ spec: - name: memory description: Amount of RAM for the cloud instance in GiB (default 64) default: '64' + - name: compute-sizes + description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args + default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" - name: nested-virt description: Use cloud instance that has nested virtualization support default: 'false' @@ -220,8 +226,13 @@ spec: if [[ $(params.operation) == "create" ]]; then cmd+="--conn-details-output /opt/cluster-info " cmd+="--arch $(params.arch) " - cmd+="--cpus $(params.cpus) " - cmd+="--memory $(params.memory) " + if [[ $(params.compute-sizes) != "" ]]; then + cmd+="--compute-sizes '$(params.compute-sizes)' " + else + cmd+="--cpus '$(params.cpus)' " + cmd+="--memory '$(params.memory)' " + cmd+="--compute-families '$(params.compute-families)' " + fi if [[ $(params.nested-virt) == "true" ]]; then cmd+="--nested-virt " fi diff --git a/tkn/infra-aws-ocp-snc.yaml b/tkn/infra-aws-ocp-snc.yaml index c6558eb4a..074081367 100644 --- a/tkn/infra-aws-ocp-snc.yaml +++ b/tkn/infra-aws-ocp-snc.yaml @@ -271,9 +271,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " - if [[ "$(params.compute-families)" != "" ]]; then - cmd+="--compute-families '$(params.compute-families)' " - fi + cmd+="--compute-families '$(params.compute-families)' " fi if [[ $(params.nested-virt) == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/infra-aws-rhel-ai.yaml b/tkn/infra-aws-rhel-ai.yaml index 7843786ea..3e4b82de4 100644 --- a/tkn/infra-aws-rhel-ai.yaml +++ b/tkn/infra-aws-rhel-ai.yaml @@ -100,6 +100,9 @@ spec: - name: compute-sizes description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" - name: cpus description: Number of CPUs for the cloud instance (default 8) default: "8" @@ -283,6 +286,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " + cmd+="--compute-families '$(params.compute-families)' " fi if [[ "$(params.nested-virt)" == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/infra-aws-rhel.yaml b/tkn/infra-aws-rhel.yaml index 554dfd043..81e65722e 100644 --- a/tkn/infra-aws-rhel.yaml +++ b/tkn/infra-aws-rhel.yaml @@ -280,9 +280,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " - if [[ "$(params.compute-families)" != "" ]]; then - cmd+="--compute-families '$(params.compute-families)' " - fi + cmd+="--compute-families '$(params.compute-families)' " fi if [[ "$(params.nested-virt)" == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/infra-aws-windows-server.yaml b/tkn/infra-aws-windows-server.yaml index 3ceab1faf..5cabb5728 100644 --- a/tkn/infra-aws-windows-server.yaml +++ b/tkn/infra-aws-windows-server.yaml @@ -106,6 +106,18 @@ spec: - name: disk-size description: Disk size in GB for the cloud instance default: '200' + - name: compute-sizes + description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args + default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" + - name: cpus + description: Number of CPUs for the cloud instance (default 8) + default: '8' + - name: memory + description: Amount of RAM for the cloud instance in GiB (default 200) + default: '200' - name: airgap description: | @@ -234,6 +246,13 @@ spec: cmd+="--ami-owner $(params.ami-owner) " cmd+="--ami-lang $(params.ami-lang) " cmd+="--disk-size $(params.disk-size) " + if [[ $(params.compute-sizes) != "" ]]; then + cmd+="--compute-sizes '$(params.compute-sizes)' " + else + cmd+="--cpus '$(params.cpus)' " + cmd+="--memory '$(params.memory)' " + cmd+="--compute-families '$(params.compute-families)' " + fi if [[ $(params.spot) == "true" ]]; then cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) " fi diff --git a/tkn/template/infra-aws-eks.yaml b/tkn/template/infra-aws-eks.yaml index e04cdb28b..475088703 100644 --- a/tkn/template/infra-aws-eks.yaml +++ b/tkn/template/infra-aws-eks.yaml @@ -102,6 +102,18 @@ spec: - name: load-balancer-controller description: Install AWS Load Balancer Controller (default false) default: 'false' + - name: compute-sizes + description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args + default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" + - name: cpus + description: Number of CPUs for the cloud instance (default 8) + default: '8' + - name: memory + description: Amount of RAM for the cloud instance in GiB (default 64) + default: '64' # Spot params - name: spot @@ -216,6 +228,13 @@ spec: cmd+="--conn-details-output /opt/cluster-info " cmd+="--version $(params.k8s-version) " cmd+="--arch $(params.arch) " + if [[ $(params.compute-sizes) != "" ]]; then + cmd+="--compute-sizes '$(params.compute-sizes)' " + else + cmd+="--cpus '$(params.cpus)' " + cmd+="--memory '$(params.memory)' " + cmd+="--compute-families '$(params.compute-families)' " + fi cmd+="--workers-desired $(params.workers-desired) " cmd+="--workers-max $(params.workers-max) " cmd+="--workers-min $(params.workers-min) " diff --git a/tkn/template/infra-aws-fedora.yaml b/tkn/template/infra-aws-fedora.yaml index 04a4e9e15..99069347d 100644 --- a/tkn/template/infra-aws-fedora.yaml +++ b/tkn/template/infra-aws-fedora.yaml @@ -88,6 +88,9 @@ spec: - name: compute-sizes description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" - name: cpus description: Number of CPUs for the cloud instance (default 8) default: "8" @@ -255,6 +258,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " + cmd+="--compute-families '$(params.compute-families)' " fi if [[ "$(params.nested-virt)" == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/template/infra-aws-kind.yaml b/tkn/template/infra-aws-kind.yaml index b1ae58285..3f4c67527 100644 --- a/tkn/template/infra-aws-kind.yaml +++ b/tkn/template/infra-aws-kind.yaml @@ -91,6 +91,12 @@ spec: - name: memory description: Amount of RAM for the cloud instance in GiB (default 64) default: '64' + - name: compute-sizes + description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args + default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" - name: nested-virt description: Use cloud instance that has nested virtualization support default: 'false' @@ -220,8 +226,13 @@ spec: if [[ $(params.operation) == "create" ]]; then cmd+="--conn-details-output /opt/cluster-info " cmd+="--arch $(params.arch) " - cmd+="--cpus $(params.cpus) " - cmd+="--memory $(params.memory) " + if [[ $(params.compute-sizes) != "" ]]; then + cmd+="--compute-sizes '$(params.compute-sizes)' " + else + cmd+="--cpus '$(params.cpus)' " + cmd+="--memory '$(params.memory)' " + cmd+="--compute-families '$(params.compute-families)' " + fi if [[ $(params.nested-virt) == "true" ]]; then cmd+="--nested-virt " fi diff --git a/tkn/template/infra-aws-ocp-snc.yaml b/tkn/template/infra-aws-ocp-snc.yaml index 8f6150878..7d44e4c52 100644 --- a/tkn/template/infra-aws-ocp-snc.yaml +++ b/tkn/template/infra-aws-ocp-snc.yaml @@ -271,9 +271,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " - if [[ "$(params.compute-families)" != "" ]]; then - cmd+="--compute-families '$(params.compute-families)' " - fi + cmd+="--compute-families '$(params.compute-families)' " fi if [[ $(params.nested-virt) == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/template/infra-aws-rhel-ai.yaml b/tkn/template/infra-aws-rhel-ai.yaml index db3b82ff8..fb6832992 100644 --- a/tkn/template/infra-aws-rhel-ai.yaml +++ b/tkn/template/infra-aws-rhel-ai.yaml @@ -100,6 +100,9 @@ spec: - name: compute-sizes description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" - name: cpus description: Number of CPUs for the cloud instance (default 8) default: "8" @@ -283,6 +286,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " + cmd+="--compute-families '$(params.compute-families)' " fi if [[ "$(params.nested-virt)" == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/template/infra-aws-rhel.yaml b/tkn/template/infra-aws-rhel.yaml index bad149da1..1746c543d 100644 --- a/tkn/template/infra-aws-rhel.yaml +++ b/tkn/template/infra-aws-rhel.yaml @@ -280,9 +280,7 @@ spec: cmd+="--memory '$(params.memory)' " cmd+="--gpus '$(params.gpus)' " cmd+="--gpu-manufacturer '$(params.gpu-manufacturer)' " - if [[ "$(params.compute-families)" != "" ]]; then - cmd+="--compute-families '$(params.compute-families)' " - fi + cmd+="--compute-families '$(params.compute-families)' " fi if [[ "$(params.nested-virt)" == "true" ]]; then cmd+="--nested-virt " diff --git a/tkn/template/infra-aws-windows-server.yaml b/tkn/template/infra-aws-windows-server.yaml index c1f45b788..d899c86ce 100644 --- a/tkn/template/infra-aws-windows-server.yaml +++ b/tkn/template/infra-aws-windows-server.yaml @@ -106,6 +106,18 @@ spec: - name: disk-size description: Disk size in GB for the cloud instance default: '200' + - name: compute-sizes + description: Comma seperated list of sizes for the machines to be requested. If set this takes precedence over compute by args + default: "" + - name: compute-families + description: Comma-separated allowlist of AWS instance family prefixes (e.g. m5,m6i,m7i). Empty means no restriction. Only used when compute-sizes is not set. + default: "" + - name: cpus + description: Number of CPUs for the cloud instance (default 8) + default: '8' + - name: memory + description: Amount of RAM for the cloud instance in GiB (default 200) + default: '200' - name: airgap description: | @@ -234,6 +246,13 @@ spec: cmd+="--ami-owner $(params.ami-owner) " cmd+="--ami-lang $(params.ami-lang) " cmd+="--disk-size $(params.disk-size) " + if [[ $(params.compute-sizes) != "" ]]; then + cmd+="--compute-sizes '$(params.compute-sizes)' " + else + cmd+="--cpus '$(params.cpus)' " + cmd+="--memory '$(params.memory)' " + cmd+="--compute-families '$(params.compute-families)' " + fi if [[ $(params.spot) == "true" ]]; then cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) " fi