Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node_type data source by skipping node types that aren't available from cloud provider #1534

Merged
merged 1 commit into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions clusters/data_node_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func (l *NodeTypeList) Sort() {
})
}

const (
CloudProviderNodeStatusNotEnabled = "NotEnabledOnSubscription"
CloudProviderNodeStatusNotAvailableInRegion = "NotAvailableInRegion"
)

// ClusterCloudProviderNodeInfo encapsulates the existing quota available from the cloud service provider.
type ClusterCloudProviderNodeInfo struct {
Status []string `json:"status,omitempty"`
Expand Down Expand Up @@ -89,6 +94,19 @@ type NodeType struct {
Graviton bool `json:"is_graviton,omitempty"`
}

func (nt NodeType) shouldBeSkipped() bool {
if nt.NodeInfo == nil {
return false
}
for _, st := range nt.NodeInfo.Status {
switch st {
case CloudProviderNodeStatusNotAvailableInRegion, CloudProviderNodeStatusNotEnabled:
return true
}
}
return false
}

func (a ClustersAPI) defaultSmallestNodeType() string {
if a.client.IsAzure() {
return "Standard_D3_v2"
Expand Down Expand Up @@ -117,6 +135,9 @@ func (a ClustersAPI) GetSmallestNodeType(r NodeTypeRequest) string {
}
list.Sort()
for _, nt := range list.NodeTypes {
if nt.shouldBeSkipped() {
continue
}
gbs := (nt.MemoryMB / 1024)
if r.VCPU && !strings.HasPrefix(nt.NodeTypeID, "vcpu") {
continue
Expand Down
80 changes: 80 additions & 0 deletions clusters/data_node_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,83 @@ func TestSmallestNodeTypeClouds(t *testing.T) {
},
}.defaultSmallestNodeType())
}

func TestNodeTypeCategoryNotAvailable(t *testing.T) {
d, err := qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
ReuseRequest: true,
Resource: "/api/2.0/clusters/list-node-types",
Response: NodeTypeList{
[]NodeType{
{
NodeTypeID: "Random_05",
InstanceTypeID: "Random_05",
MemoryMB: 1024,
NumCores: 32,
NodeInstanceType: &NodeInstanceType{
LocalDisks: 3,
LocalDiskSizeGB: 100,
},
},
{
NodeTypeID: "Random_01",
InstanceTypeID: "Random_01",
MemoryMB: 8192,
NumCores: 8,
NodeInstanceType: &NodeInstanceType{
InstanceTypeID: "_",
},
Category: "Memory Optimized",
},
{
NodeTypeID: "Random_02",
InstanceTypeID: "Random_02",
MemoryMB: 8192,
NumCores: 8,
NumGPUs: 2,
Category: "Storage Optimized",
NodeInfo: &ClusterCloudProviderNodeInfo{
Status: []string{CloudProviderNodeStatusNotAvailableInRegion, CloudProviderNodeStatusNotEnabled},
},
},
{
NodeTypeID: "Random_03",
InstanceTypeID: "Random_03",
MemoryMB: 8192,
NumCores: 8,
NumGPUs: 2,
Category: "Storage Optimized",
},
},
},
},
},
Read: true,
Resource: DataSourceNodeType(),
NonWritable: true,
State: map[string]any{
"category": "Storage optimized",
},
ID: ".",
}.Apply(t)
assert.NoError(t, err)
assert.Equal(t, "Random_03", d.Id())
}

func TestNodeTypeShouldBeSkipped(t *testing.T) {
toBeSkipped := NodeType{
NodeTypeID: "Random_02",
InstanceTypeID: "Random_02",
MemoryMB: 8192,
NumCores: 8,
NumGPUs: 2,
Category: "Storage Optimized",
NodeInfo: &ClusterCloudProviderNodeInfo{
Status: []string{CloudProviderNodeStatusNotAvailableInRegion, CloudProviderNodeStatusNotEnabled},
},
}
assert.Equal(t, true, toBeSkipped.shouldBeSkipped())
assert.Equal(t, false, NodeType{}.shouldBeSkipped())
}