Skip to content

Commit

Permalink
add found variable to indicate if cluster name label is found
Browse files Browse the repository at this point in the history
  • Loading branch information
mluffman committed Jan 5, 2024
1 parent fc196ed commit 9755157
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions internal/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ func messageToInstanceCreationEvent(m *gcppubsub.Message) (instanceCreationEvent
return instanceCreationEvent{}, fmt.Errorf("expected labels not found on instance creation request, operation ID: %s", entry.Operation.Id)
}

clusterName := "unknown"
var clusterName string
var found bool
for _, v := range labels.GetListValue().Values {
label := v.GetStructValue().AsMap()
labelKey := label["key"].(string)
if strings.EqualFold(labelKey, compute.ClusterNameLabelKey) {
clusterName = label["value"].(string)
found = true
break
}
}

if clusterName == "unknown" {
if !found {
return instanceCreationEvent{}, fmt.Errorf("expected cluster label %s not found on instance creation request, operation ID: %s", compute.ClusterNameLabelKey, entry.Operation.Id)
}

Expand Down

0 comments on commit 9755157

Please sign in to comment.