Skip to content

Commit

Permalink
fix(agent): missing path for pod without labels
Browse files Browse the repository at this point in the history
  • Loading branch information
brandtkeller committed May 17, 2024
1 parent f6fe020 commit a0d56b3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/internal/agent/hooks/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ func mutatePod(r *v1.AdmissionRequest) (*operations.Result, error) {
}

// Add a label noting the zarf mutation
patchOperations = append(patchOperations, operations.ReplacePatchOperation("/metadata/labels/zarf-agent", "patched"))
if pod.Labels == nil {
// If the labels path does not exist - create with nap[string]string value
patchOperations = append(patchOperations, operations.AddPatchOperation("/metadata/labels",
map[string]string{
"zarf-agent": "patched",
}))
} else {
patchOperations = append(patchOperations, operations.ReplacePatchOperation("/metadata/labels/zarf-agent", "patched"))
}

return &operations.Result{
Allowed: true,
Expand Down

0 comments on commit a0d56b3

Please sign in to comment.