From 235a1195f624baf6930724514a53c0a182f4e4fa Mon Sep 17 00:00:00 2001 From: Matt Wilder <41255671+partcyborg@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:47:49 -0700 Subject: [PATCH] kubernetes_node_taint: fix warning when node is missing (#2402) --- .changelog/2402.txt | 3 +++ kubernetes/resource_kubernetes_node_taint.go | 12 ++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 .changelog/2402.txt diff --git a/.changelog/2402.txt b/.changelog/2402.txt new file mode 100644 index 0000000000..0189f8a56b --- /dev/null +++ b/.changelog/2402.txt @@ -0,0 +1,3 @@ +```release-note:bug +`resource/kubernetes_node_taint`: Fix the error check for nonexistant nodes so that terraform does not fail if there is a taint in the state file for a node that has been deleted. +``` diff --git a/kubernetes/resource_kubernetes_node_taint.go b/kubernetes/resource_kubernetes_node_taint.go index 887d80ae08..aec0c89fcf 100644 --- a/kubernetes/resource_kubernetes_node_taint.go +++ b/kubernetes/resource_kubernetes_node_taint.go @@ -100,6 +100,12 @@ func resourceKubernetesNodeTaintRead(ctx context.Context, d *schema.ResourceData nodeName := meta.Name conn, err := m.(KubeClientsets).MainClientset() + if err != nil { + return diag.FromErr(err) + } + nodeApi := conn.CoreV1().Nodes() + + node, err := nodeApi.Get(ctx, nodeName, metav1.GetOptions{}) if err != nil { if statusErr, ok := err.(*errors.StatusError); ok && errors.IsNotFound(statusErr) { // The node is gone so the resource should be deleted. @@ -111,12 +117,6 @@ func resourceKubernetesNodeTaintRead(ctx context.Context, d *schema.ResourceData } return diag.FromErr(err) } - nodeApi := conn.CoreV1().Nodes() - - node, err := nodeApi.Get(ctx, nodeName, metav1.GetOptions{}) - if err != nil { - return diag.FromErr(err) - } nodeTaints := node.Spec.Taints if len(nodeTaints) == 0 { d.SetId("")