Skip to content

Commit

Permalink
kubernetes_node_taint: don't fail if node is missing (#2099)
Browse files Browse the repository at this point in the history
Show a warning instead of an error if a tainted node is missing. 
Otherwise, taints for deleted nodes can only be removed via `terraform state rm`.
  • Loading branch information
partcyborg authored May 24, 2023
1 parent 7196986 commit 80e8520
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .changelog/2099.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
`resource/kubernetes_node_taint`: Don't fail when there is a taint in the state file for a node that no longer exists.

```
8 changes: 8 additions & 0 deletions kubernetes/resource_kubernetes_node_taint.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ func resourceKubernetesNodeTaintRead(ctx context.Context, d *schema.ResourceData

conn, err := m.(KubeClientsets).MainClientset()
if err != nil {
if statusErr, ok := err.(*errors.StatusError); ok && errors.IsNotFound(statusErr) {
// The node is gone so the resource should be deleted.
return diag.Diagnostics{{
Severity: diag.Warning,
Summary: "Node has been deleted",
Detail: fmt.Sprintf("The underlying node %q has been deleted. You should remove it from your configuration.", nodeName),
}}
}
return diag.FromErr(err)
}
nodeApi := conn.CoreV1().Nodes()
Expand Down

0 comments on commit 80e8520

Please sign in to comment.