Skip to content

Commit

Permalink
Add ["ff:metadata"] check in kubernetes_labels to prevent crash w…
Browse files Browse the repository at this point in the history
…ith `kubernetes_node_taints` (#2246)

* use read function for labels to grab exact Object fields

* remove apply logic fixes

* add changelog-entry

* Update .changelog/2246.txt

Co-authored-by: John Houston <jrhouston@users.noreply.github.com>

---------

Co-authored-by: John Houston <jrhouston@users.noreply.github.com>
  • Loading branch information
BBBmau and jrhouston authored Aug 28, 2023
1 parent 0e04111 commit 23cdb54
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/2246.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
`resource/kubernetes_labels`: Add ["f:metadata"] check in kubernetes_labels to prevent crash with kubernetes_node_taints
```
9 changes: 6 additions & 3 deletions kubernetes/resource_kubernetes_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,12 @@ func getManagedLabels(managedFields []v1.ManagedFieldsEntry, manager string) (ma
if err != nil {
return nil, err
}
metadata := mm["f:metadata"].(map[string]interface{})
if l, ok := metadata["f:labels"].(map[string]interface{}); ok {
labels = l
if fm, ok := mm["f:metadata"].(map[string]interface{}); ok {
if l, ok := fm["f:labels"].(map[string]interface{}); ok {
labels = l
}
}

}
return labels, nil
}
Expand Down Expand Up @@ -249,6 +251,7 @@ func resourceKubernetesLabelsUpdate(ctx context.Context, d *schema.ResourceData,
// with an empty labels map
labels = map[string]interface{}{}
}

patchmeta := map[string]interface{}{
"name": name,
"labels": labels,
Expand Down
1 change: 1 addition & 0 deletions kubernetes/resource_kubernetes_node_taint.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func resourceKubernetesNodeTaintUpdate(ctx context.Context, d *schema.ResourceDa
"taints": taints,
},
}

patch := unstructured.Unstructured{
Object: patchObj,
}
Expand Down

0 comments on commit 23cdb54

Please sign in to comment.