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

Add ["f:metadata"] check in kubernetes_labels to prevent crash with kubernetes_node_taints #2246

Merged
merged 5 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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 ["ff:metadata"] check in kubernetes_labels to prevent crash with kubernetes_node_taints
BBBmau marked this conversation as resolved.
Show resolved Hide resolved
```
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