From d6b913384f3fd16662ad22a1d8f187b76c2c9f84 Mon Sep 17 00:00:00 2001 From: linkas45 Date: Tue, 24 Oct 2023 12:31:02 +0000 Subject: [PATCH 1/3] handle empty instance_families in node template --- Makefile | 4 ++-- castai/resource_node_template.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7780869e..55518194 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ default: build init-examples: @echo "==> Creating symlinks for example/ projects to terraform-provider-castai binary"; \ TF_PROVIDER_FILENAME=terraform-provider-castai; \ - GOOS=`go tool dist env | awk -F'=' '/^GOOS/ { print $$2}' | tr -d '"'`; \ - GOARCH=`go tool dist env | awk -F'=' '/^GOARCH/ { print $$2}' | tr -d '"'`; \ + GOOS=`go tool dist env | awk -F'=' '/^GOOS/ { print $$2}' | tr -d '";'`; \ + GOARCH=`go tool dist env | awk -F'=' '/^GOARCH/ { print $$2}' | tr -d '";'`; \ for examples in examples/eks examples/gke examples/aks ; do \ for tfproject in $$examples/* ; do \ TF_PROJECT_PLUGIN_PATH="$${tfproject}/terraform.d/plugins/registry.terraform.io/castai/castai/0.0.0-local/$${GOOS}_$${GOARCH}"; \ diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index fe7e997e..69650e0f 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -954,7 +954,7 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst if v, ok := obj[FieldNodeTemplateGpu].([]any); ok && len(v) > 0 { out.Gpu = toTemplateConstraintsGpuConstraints(v[0].(map[string]any)) } - if v, ok := obj[FieldNodeTemplateInstanceFamilies].([]any); ok && len(v) > 0 { + if v, ok := obj[FieldNodeTemplateInstanceFamilies].([]any); ok && len(v) > 0 && v[0] != nil { out.InstanceFamilies = toTemplateConstraintsInstanceFamilies(v[0].(map[string]any)) } if v, ok := obj[FieldNodeTemplateMaxCpu].(int); ok && v != 0 { From d6e255683e26041b95fb3125556e3318570ea282 Mon Sep 17 00:00:00 2001 From: linkas45 Date: Tue, 24 Oct 2023 12:37:47 +0000 Subject: [PATCH 2/3] add check for gpu too --- castai/resource_node_template.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index 69650e0f..d4ff59cf 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -951,7 +951,7 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst if v, ok := obj[FieldNodeTemplateFallbackRestoreRateSeconds].(int); ok { out.FallbackRestoreRateSeconds = toPtr(int32(v)) } - if v, ok := obj[FieldNodeTemplateGpu].([]any); ok && len(v) > 0 { + if v, ok := obj[FieldNodeTemplateGpu].([]any); ok && len(v) > 0 && v[0] != nil { out.Gpu = toTemplateConstraintsGpuConstraints(v[0].(map[string]any)) } if v, ok := obj[FieldNodeTemplateInstanceFamilies].([]any); ok && len(v) > 0 && v[0] != nil { From 8c506ad0342b70bb3b76bd611ea73c00c2894a2f Mon Sep 17 00:00:00 2001 From: linkas45 Date: Tue, 24 Oct 2023 13:02:26 +0000 Subject: [PATCH 3/3] PR review --- castai/resource_node_template.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/castai/resource_node_template.go b/castai/resource_node_template.go index d4ff59cf..522c1351 100644 --- a/castai/resource_node_template.go +++ b/castai/resource_node_template.go @@ -951,11 +951,17 @@ func toTemplateConstraints(obj map[string]any) *sdk.NodetemplatesV1TemplateConst if v, ok := obj[FieldNodeTemplateFallbackRestoreRateSeconds].(int); ok { out.FallbackRestoreRateSeconds = toPtr(int32(v)) } - if v, ok := obj[FieldNodeTemplateGpu].([]any); ok && len(v) > 0 && v[0] != nil { - out.Gpu = toTemplateConstraintsGpuConstraints(v[0].(map[string]any)) + if v, ok := obj[FieldNodeTemplateGpu].([]any); ok && len(v) > 0 { + val, ok := v[0].(map[string]any) + if ok { + out.Gpu = toTemplateConstraintsGpuConstraints(val) + } } - if v, ok := obj[FieldNodeTemplateInstanceFamilies].([]any); ok && len(v) > 0 && v[0] != nil { - out.InstanceFamilies = toTemplateConstraintsInstanceFamilies(v[0].(map[string]any)) + if v, ok := obj[FieldNodeTemplateInstanceFamilies].([]any); ok && len(v) > 0 { + val, ok := v[0].(map[string]any) + if ok { + out.InstanceFamilies = toTemplateConstraintsInstanceFamilies(val) + } } if v, ok := obj[FieldNodeTemplateMaxCpu].(int); ok && v != 0 { out.MaxCpu = toPtr(int32(v))