Skip to content

Commit 931d30f

Browse files
committed
fix
1 parent 83d735c commit 931d30f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/k8s/environment/environment.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,34 @@ var requiredChainLinkWorkloadAndPodLabels = append([]string{}, append(requiredCh
246246
// validateRequiredChainLinkLabels validates whether the namespace, workloads ands pods have the required chain.link labels
247247
// and returns an error with a list of missing labels if any
248248
func (m *Environment) validateRequiredChainLinkLabels() error {
249+
if m.root == nil {
250+
return fmt.Errorf("m.root is nil, cannot validate namespace labels")
251+
}
252+
249253
if m.root.Labels() == nil {
250-
return fmt.Errorf("namespace labels are nil, but it should contain at least '%s' labels. Please add them to your environment config under 'Labels' key", strings.Join(requiredChainLinkNsLabels, ", "))
254+
return fmt.Errorf("namespace labels are nil, but it should contain at least '%s' labels. Please add them to your environment config under 'Labels' key",
255+
strings.Join(requiredChainLinkNsLabels, ", "))
251256
}
252257

253258
var missingNsLabels []string
259+
// Safely access the map
254260
for _, l := range requiredChainLinkNsLabels {
255-
if _, ok := (*m.root.Labels())[l]; !ok {
261+
labels := m.root.Labels()
262+
if labels == nil {
263+
// This additional check is defensive; can be omitted if Labels() is guaranteed non-nil
264+
return fmt.Errorf("unexpected nil labels while iterating")
265+
}
266+
if _, ok := (*labels)[l]; !ok {
256267
missingNsLabels = append(missingNsLabels, l)
257268
}
258269
}
259270

271+
// Report missing labels if any
272+
if len(missingNsLabels) > 0 {
273+
return fmt.Errorf("missing required namespace labels: %s",
274+
strings.Join(missingNsLabels, ", "))
275+
}
276+
260277
children := m.root.Node().Children()
261278
// map[workflow name][missing labels]
262279
missingWorkloadLabels := make(map[string][]string)

0 commit comments

Comments
 (0)