|
| 1 | +//go:build integration |
| 2 | + |
| 3 | +/* |
| 4 | + * Copyright 2023 nebuly.com |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package gpupartitioner_test |
| 20 | + |
| 21 | +import ( |
| 22 | + "fmt" |
| 23 | + "github.com/nebuly-ai/nos/pkg/api/nos.nebuly.com/v1alpha1" |
| 24 | + "github.com/nebuly-ai/nos/pkg/constant" |
| 25 | + "github.com/nebuly-ai/nos/pkg/gpu" |
| 26 | + "github.com/nebuly-ai/nos/pkg/test/factory" |
| 27 | + . "github.com/onsi/ginkgo/v2" |
| 28 | + . "github.com/onsi/gomega" |
| 29 | + "github.com/stretchr/testify/mock" |
| 30 | + "time" |
| 31 | +) |
| 32 | + |
| 33 | +var _ = Describe("Node Controller", func() { |
| 34 | + const ( |
| 35 | + timeout = time.Second * 10 |
| 36 | + interval = time.Second * 1 |
| 37 | + ) |
| 38 | + |
| 39 | + BeforeEach(func() { |
| 40 | + }) |
| 41 | + |
| 42 | + AfterEach(func() { |
| 43 | + }) |
| 44 | + |
| 45 | + When("A node does not have GPU Count label", func() { |
| 46 | + It("Should not be added to the Cluster State", func() { |
| 47 | + By("By creating a node without GPU Count label") |
| 48 | + nodeName := "node-without-gpu-count-label" |
| 49 | + node := factory.BuildNode(nodeName).WithLabels(map[string]string{ |
| 50 | + constant.LabelNvidiaProduct: gpu.GPUModel_A100_PCIe_80GB.String(), |
| 51 | + v1alpha1.LabelGpuPartitioning: gpu.PartitioningKindMps.String(), |
| 52 | + }).Get() |
| 53 | + Expect(k8sClient.Create(ctx, &node)).To(Succeed()) |
| 54 | + |
| 55 | + By("Checking that the node is not added to the Cluster State") |
| 56 | + Consistently(func() bool { |
| 57 | + _, ok := clusterState.GetNode(nodeName) |
| 58 | + return ok |
| 59 | + }, 3, interval).Should(BeFalse()) |
| 60 | + }) |
| 61 | + }) |
| 62 | + |
| 63 | + When("A node does not have GPU Model label", func() { |
| 64 | + It("Should not be added to the Cluster State", func() { |
| 65 | + |
| 66 | + By("By creating a node without GPU Model label") |
| 67 | + nodeName := "node-without-gpu-model-label" |
| 68 | + node := factory.BuildNode(nodeName).WithLabels(map[string]string{ |
| 69 | + constant.LabelNvidiaCount: "1", |
| 70 | + v1alpha1.LabelGpuPartitioning: gpu.PartitioningKindMps.String(), |
| 71 | + }).Get() |
| 72 | + Expect(k8sClient.Create(ctx, &node)).To(Succeed()) |
| 73 | + |
| 74 | + By("Checking that the node is not added to the Cluster State") |
| 75 | + Consistently(func() bool { |
| 76 | + _, ok := clusterState.GetNode(nodeName) |
| 77 | + return ok |
| 78 | + }, 3, interval).Should(BeFalse()) |
| 79 | + }) |
| 80 | + }) |
| 81 | + |
| 82 | + When("A node with GPU labels has MPS partitioning enabled", func() { |
| 83 | + It("Should always be added to the Cluster State", func() { |
| 84 | + By("By creating a node with MPS partitioning enabled") |
| 85 | + nodeName := "node-mps" |
| 86 | + node := factory.BuildNode(nodeName).WithLabels(map[string]string{ |
| 87 | + constant.LabelNvidiaProduct: gpu.GPUModel_A100_PCIe_80GB.String(), |
| 88 | + constant.LabelNvidiaCount: "1", |
| 89 | + v1alpha1.LabelGpuPartitioning: gpu.PartitioningKindMps.String(), |
| 90 | + }).Get() |
| 91 | + Expect(k8sClient.Create(ctx, &node)).To(Succeed()) |
| 92 | + |
| 93 | + By("Checking that the node is added to the Cluster State") |
| 94 | + Eventually(func() bool { |
| 95 | + _, ok := clusterState.GetNode(nodeName) |
| 96 | + return ok |
| 97 | + }, timeout, interval).Should(BeTrue()) |
| 98 | + }) |
| 99 | + }) |
| 100 | + |
| 101 | + When("A node with GPU labels has MIG partitioning enabled", func() { |
| 102 | + It("Should *not* be added to the Cluster State it is not initialized", func() { |
| 103 | + By("By creating a node with MIG partitioning enabled, but not initialized") |
| 104 | + nodeName := "node-mig-not-initialized" |
| 105 | + node := factory.BuildNode(nodeName).WithLabels(map[string]string{ |
| 106 | + constant.LabelNvidiaProduct: gpu.GPUModel_A100_PCIe_80GB.String(), |
| 107 | + constant.LabelNvidiaCount: "1", |
| 108 | + v1alpha1.LabelGpuPartitioning: gpu.PartitioningKindMig.String(), |
| 109 | + }).Get() |
| 110 | + Expect(k8sClient.Create(ctx, &node)).To(Succeed()) |
| 111 | + |
| 112 | + By("Checking that the controller triggers Node initialization") |
| 113 | + migNodeInitializer.On("InitNodePartitioning", mock.Anything, mock.Anything). |
| 114 | + Return(nil). |
| 115 | + Once() |
| 116 | + |
| 117 | + By("Checking that the node is *not* added to the Cluster State") |
| 118 | + Consistently(func() bool { |
| 119 | + _, ok := clusterState.GetNode(nodeName) |
| 120 | + return ok |
| 121 | + }, 5, interval).Should(BeFalse()) |
| 122 | + }) |
| 123 | + |
| 124 | + It("Should be added to the Cluster State it is initialized", func() { |
| 125 | + By("By creating an initialized node with MIG partitioning enabled") |
| 126 | + nodeName := "node-mig-initialized" |
| 127 | + node := factory.BuildNode(nodeName). |
| 128 | + WithLabels(map[string]string{ |
| 129 | + constant.LabelNvidiaProduct: gpu.GPUModel_A100_PCIe_80GB.String(), |
| 130 | + constant.LabelNvidiaCount: "1", |
| 131 | + v1alpha1.LabelGpuPartitioning: gpu.PartitioningKindMig.String(), |
| 132 | + }). |
| 133 | + WithAnnotations(map[string]string{ |
| 134 | + fmt.Sprintf(v1alpha1.AnnotationGpuSpecFormat, 0, "10gb"): "1", |
| 135 | + }). |
| 136 | + Get() |
| 137 | + Expect(k8sClient.Create(ctx, &node)).To(Succeed()) |
| 138 | + |
| 139 | + migNodeInitializer.On("InitNodePartitioning", mock.Anything, mock.Anything). |
| 140 | + Return(nil). |
| 141 | + Maybe() |
| 142 | + |
| 143 | + By("Checking that the node is added to the Cluster State") |
| 144 | + Eventually(func() bool { |
| 145 | + _, ok := clusterState.GetNode(nodeName) |
| 146 | + return ok |
| 147 | + }, timeout, interval).Should(BeTrue()) |
| 148 | + }) |
| 149 | + }) |
| 150 | +}) |
0 commit comments