Skip to content

Backup Job and its pod template share one label map #1743

Open

Description

@rohanKanojia

Description

internally discussed with @btjd

createBackupJob in controllers/backupcronjob/backupcronjob_controller.go builds one jobLabels map and assigns that same map to both job.ObjectMeta.Labels and job.Spec.Template.ObjectMeta.Labels.

In Go a map is a reference, so a later write to either field changes the other. Nothing in createBackupJob writes to the map after it is assigned, and client.Create only serializes it, so this does not mislabel Jobs today. The two label sets are meant to carry the same keys (controller.devfile.io/devworkspace_id, controller.devfile.io/devworkspace_name, controller.devfile.io/backup-job, and controller.devfile.io/creator).

This was noted in review of #1741. The previous code used two independent map literals. Giving the pod template its own map, with maps.Clone or a second literal, keeps a future pod-only label from also landing on the Job.

pkg/provision/storage/cleanup.go uses the same shared-map pattern for the PVC cleanup Job. There the restricted-access label is written into jobLabels before both fields are set, so both objects receive it. That call site has the same aliasing.

How To Reproduce

Not reproducible as a failure with the current code. The alias is visible in createBackupJob: both label fields are set to jobLabels.

Expected behavior

The Job metadata labels and the pod template labels are separate maps, initialized with the same entries. Editing one after construction does not change the other.

Additional context

Raised while reviewing #1741. No current caller depends on the two fields diverging.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions