@@ -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.
4646type 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.
4952type 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
131143func (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.
165177func (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