Skip to content

Commit 8b7ca10

Browse files
authored
Merge pull request #8606 from k8s-infra-cherrypick-robot/cherry-pick-8604-to-cluster-autoscaler-release-1.34
[cluster-autoscaler-release-1.34] cas: enable overridable node GPU config during cloud provider tests
2 parents f4bec36 + 5bf5c6f commit 8b7ca10

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cluster-autoscaler/cloudprovider/test/test_cloud_provider.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ type OnNodeGroupDeleteFunc func(string) error
4545
// HasInstance is a function called to determine if a node has been removed from the cloud provider.
4646
type HasInstance func(string) (bool, error)
4747

48+
// NodeGpuConfig is a function that returns the GPU config for a given node.
49+
type NodeGpuConfig func(node *apiv1.Node) *cloudprovider.GpuConfig
50+
4851
// TestCloudProvider is a dummy cloud provider to be used in tests.
4952
type TestCloudProvider struct {
5053
sync.Mutex
@@ -59,6 +62,7 @@ type TestCloudProvider struct {
5962
machineTemplates map[string]*framework.NodeInfo
6063
priceModel cloudprovider.PricingModel
6164
resourceLimiter *cloudprovider.ResourceLimiter
65+
nodeGpuConfig func(node *apiv1.Node) *cloudprovider.GpuConfig
6266
}
6367

6468
// TestCloudProviderBuilder is used to create CloudProvider
@@ -127,6 +131,14 @@ func (b *TestCloudProviderBuilder) WithHasInstance(hasInstance HasInstance) *Tes
127131
return b
128132
}
129133

134+
// WithNodeGpuConfig adds has custom node gpu config handler to provider
135+
func (b *TestCloudProviderBuilder) WithNodeGpuConfig(nodeGpuConfig NodeGpuConfig) *TestCloudProviderBuilder {
136+
b.builders = append(b.builders, func(p *TestCloudProvider) {
137+
p.nodeGpuConfig = nodeGpuConfig
138+
})
139+
return b
140+
}
141+
130142
// Build returns a built test cloud provider
131143
func (b *TestCloudProviderBuilder) Build() *TestCloudProvider {
132144
p := &TestCloudProvider{
@@ -163,6 +175,9 @@ func (tcp *TestCloudProvider) GetAvailableGPUTypes() map[string]struct{} {
163175
// GetNodeGpuConfig returns the label, type and resource name for the GPU added to node. If node doesn't have
164176
// any GPUs, it returns nil.
165177
func (tcp *TestCloudProvider) GetNodeGpuConfig(node *apiv1.Node) *cloudprovider.GpuConfig {
178+
if tcp.nodeGpuConfig != nil {
179+
return tcp.nodeGpuConfig(node)
180+
}
166181
return gpu.GetNodeGPUFromCloudProvider(tcp, node)
167182
}
168183

0 commit comments

Comments
 (0)