Skip to content

Commit

Permalink
Merge pull request #11555 from orelmisan/migration-create-wh
Browse files Browse the repository at this point in the history
Migration create mutator: Minor refactoring
  • Loading branch information
kubevirt-bot committed Mar 20, 2024
2 parents aa76cf7 + 25dbfbd commit 0152f6e
Showing 1 changed file with 14 additions and 9 deletions.
Expand Up @@ -54,15 +54,8 @@ func (mutator *MigrationCreateMutator) Mutate(ar *admissionv1.AdmissionReview) *
return webhookutils.ToAdmissionResponseError(err)
}

// Add our selector label
if migration.Labels == nil {
migration.Labels = map[string]string{v1.MigrationSelectorLabel: migration.Spec.VMIName}
} else {
migration.Labels[v1.MigrationSelectorLabel] = migration.Spec.VMIName
}

// Add a finalizer
migration.Finalizers = append(migration.Finalizers, v1.VirtualMachineInstanceMigrationFinalizer)
addMigrationSelectorLabel(&migration)
addMigrationFinalizer(&migration)

patchBytes, err := patch.GeneratePatchPayload(
patch.PatchOperation{
Expand All @@ -88,3 +81,15 @@ func (mutator *MigrationCreateMutator) Mutate(ar *admissionv1.AdmissionReview) *
PatchType: &jsonPatchType,
}
}

func addMigrationSelectorLabel(migration *v1.VirtualMachineInstanceMigration) {
if migration.Labels == nil {
migration.Labels = make(map[string]string)
}

migration.Labels[v1.MigrationSelectorLabel] = migration.Spec.VMIName
}

func addMigrationFinalizer(migration *v1.VirtualMachineInstanceMigration) {
migration.Finalizers = append(migration.Finalizers, v1.VirtualMachineInstanceMigrationFinalizer)
}

0 comments on commit 0152f6e

Please sign in to comment.