Skip to content

Commit 4c79ec3

Browse files
authored
Fix the issue when provider crashes after introducing new fields on the provider level (#1764)
* Fix the issue when provider crashes after introducing new fields on the provider level
1 parent ed92538 commit 4c79ec3

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

kubernetes/provider.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ type kubeClientsets struct {
360360
dynamicClient dynamic.Interface
361361
discoveryClient discovery.DiscoveryInterface
362362

363-
configData *schema.ResourceData
363+
IgnoreAnnotations []string
364+
IgnoreLabels []string
364365
}
365366

366367
func (k kubeClientsets) MainClientset() (*kubernetes.Clientset, error) {
@@ -445,11 +446,22 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, terraformVer
445446
}
446447
}
447448

449+
ignoreAnnotations := []string{}
450+
ignoreLabels := []string{}
451+
452+
if v, ok := d.Get("ignore_annotations").([]interface{}); ok {
453+
ignoreAnnotations = expandStringSlice(v)
454+
}
455+
if v, ok := d.Get("ignore_labels").([]interface{}); ok {
456+
ignoreLabels = expandStringSlice(v)
457+
}
458+
448459
m := kubeClientsets{
449460
config: cfg,
450461
mainClientset: nil,
451462
aggregatorClientset: nil,
452-
configData: d,
463+
IgnoreAnnotations: ignoreAnnotations,
464+
IgnoreLabels: ignoreLabels,
453465
}
454466
return m, diag.Diagnostics{}
455467
}

kubernetes/structures.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,17 @@ func flattenMetadata(meta metav1.ObjectMeta, d *schema.ResourceData, providerMet
125125
if len(metaPrefix) > 0 {
126126
prefix = metaPrefix[0]
127127
}
128-
configAnnotations := d.Get(prefix + "metadata.0.annotations").(map[string]interface{})
129-
130-
var ignoreAnnotations []string
131-
if v, ok := providerMetadata.(kubeClientsets).configData.Get("ignore_annotations").([]interface{}); ok {
132-
ignoreAnnotations = expandStringSlice(v)
133-
}
134128

129+
configAnnotations := d.Get(prefix + "metadata.0.annotations").(map[string]interface{})
130+
ignoreAnnotations := providerMetadata.(kubeClientsets).IgnoreAnnotations
135131
annotations := removeInternalKeys(meta.Annotations, configAnnotations)
136132
m["annotations"] = removeKeys(annotations, configAnnotations, ignoreAnnotations)
137133
if meta.GenerateName != "" {
138134
m["generate_name"] = meta.GenerateName
139135
}
140-
configLabels := d.Get(prefix + "metadata.0.labels").(map[string]interface{})
141-
142-
var ignoreLabels []string
143-
if v, ok := providerMetadata.(kubeClientsets).configData.Get("ignore_labels").([]interface{}); ok {
144-
ignoreLabels = expandStringSlice(v)
145-
}
146136

137+
configLabels := d.Get(prefix + "metadata.0.labels").(map[string]interface{})
138+
ignoreLabels := providerMetadata.(kubeClientsets).IgnoreLabels
147139
labels := removeInternalKeys(meta.Labels, configLabels)
148140
m["labels"] = removeKeys(labels, configLabels, ignoreLabels)
149141
m["name"] = meta.Name

0 commit comments

Comments
 (0)