Skip to content

Commit f0470cf

Browse files
authored
Fixed databricks_node_type by skipping nodes that aren't available in subscription/region (#1534)
1 parent f760241 commit f0470cf

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

clusters/data_node_type.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ func (l *NodeTypeList) Sort() {
5050
})
5151
}
5252

53+
const (
54+
CloudProviderNodeStatusNotEnabled = "NotEnabledOnSubscription"
55+
CloudProviderNodeStatusNotAvailableInRegion = "NotAvailableInRegion"
56+
)
57+
5358
// ClusterCloudProviderNodeInfo encapsulates the existing quota available from the cloud service provider.
5459
type ClusterCloudProviderNodeInfo struct {
5560
Status []string `json:"status,omitempty"`
@@ -89,6 +94,19 @@ type NodeType struct {
8994
Graviton bool `json:"is_graviton,omitempty"`
9095
}
9196

97+
func (nt NodeType) shouldBeSkipped() bool {
98+
if nt.NodeInfo == nil {
99+
return false
100+
}
101+
for _, st := range nt.NodeInfo.Status {
102+
switch st {
103+
case CloudProviderNodeStatusNotAvailableInRegion, CloudProviderNodeStatusNotEnabled:
104+
return true
105+
}
106+
}
107+
return false
108+
}
109+
92110
func (a ClustersAPI) defaultSmallestNodeType() string {
93111
if a.client.IsAzure() {
94112
return "Standard_D3_v2"
@@ -117,6 +135,9 @@ func (a ClustersAPI) GetSmallestNodeType(r NodeTypeRequest) string {
117135
}
118136
list.Sort()
119137
for _, nt := range list.NodeTypes {
138+
if nt.shouldBeSkipped() {
139+
continue
140+
}
120141
gbs := (nt.MemoryMB / 1024)
121142
if r.VCPU && !strings.HasPrefix(nt.NodeTypeID, "vcpu") {
122143
continue

clusters/data_node_type_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,83 @@ func TestSmallestNodeTypeClouds(t *testing.T) {
224224
},
225225
}.defaultSmallestNodeType())
226226
}
227+
228+
func TestNodeTypeCategoryNotAvailable(t *testing.T) {
229+
d, err := qa.ResourceFixture{
230+
Fixtures: []qa.HTTPFixture{
231+
{
232+
Method: "GET",
233+
ReuseRequest: true,
234+
Resource: "/api/2.0/clusters/list-node-types",
235+
Response: NodeTypeList{
236+
[]NodeType{
237+
{
238+
NodeTypeID: "Random_05",
239+
InstanceTypeID: "Random_05",
240+
MemoryMB: 1024,
241+
NumCores: 32,
242+
NodeInstanceType: &NodeInstanceType{
243+
LocalDisks: 3,
244+
LocalDiskSizeGB: 100,
245+
},
246+
},
247+
{
248+
NodeTypeID: "Random_01",
249+
InstanceTypeID: "Random_01",
250+
MemoryMB: 8192,
251+
NumCores: 8,
252+
NodeInstanceType: &NodeInstanceType{
253+
InstanceTypeID: "_",
254+
},
255+
Category: "Memory Optimized",
256+
},
257+
{
258+
NodeTypeID: "Random_02",
259+
InstanceTypeID: "Random_02",
260+
MemoryMB: 8192,
261+
NumCores: 8,
262+
NumGPUs: 2,
263+
Category: "Storage Optimized",
264+
NodeInfo: &ClusterCloudProviderNodeInfo{
265+
Status: []string{CloudProviderNodeStatusNotAvailableInRegion, CloudProviderNodeStatusNotEnabled},
266+
},
267+
},
268+
{
269+
NodeTypeID: "Random_03",
270+
InstanceTypeID: "Random_03",
271+
MemoryMB: 8192,
272+
NumCores: 8,
273+
NumGPUs: 2,
274+
Category: "Storage Optimized",
275+
},
276+
},
277+
},
278+
},
279+
},
280+
Read: true,
281+
Resource: DataSourceNodeType(),
282+
NonWritable: true,
283+
State: map[string]any{
284+
"category": "Storage optimized",
285+
},
286+
ID: ".",
287+
}.Apply(t)
288+
assert.NoError(t, err)
289+
assert.Equal(t, "Random_03", d.Id())
290+
}
291+
292+
func TestNodeTypeShouldBeSkipped(t *testing.T) {
293+
toBeSkipped := NodeType{
294+
NodeTypeID: "Random_02",
295+
InstanceTypeID: "Random_02",
296+
MemoryMB: 8192,
297+
NumCores: 8,
298+
NumGPUs: 2,
299+
Category: "Storage Optimized",
300+
NodeInfo: &ClusterCloudProviderNodeInfo{
301+
Status: []string{CloudProviderNodeStatusNotAvailableInRegion, CloudProviderNodeStatusNotEnabled},
302+
},
303+
}
304+
assert.Equal(t, true, toBeSkipped.shouldBeSkipped())
305+
assert.Equal(t, false, NodeType{}.shouldBeSkipped())
306+
}

0 commit comments

Comments
 (0)