Skip to content

Commit

Permalink
virt-controller, template: extract pod labels func
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Duarte Barroso <[email protected]>
  • Loading branch information
maiqueb committed Jul 29, 2022
1 parent ad05283 commit f39a98c
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions pkg/virt-controller/services/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,6 @@ func (t *templateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i
nodeSelector[k] = v
}

hostName := dns.SanitizeHostname(vmi)

podLabels := map[string]string{}

for k, v := range vmi.Labels {
podLabels[k] = v
}
podLabels[v1.AppLabel] = "virt-launcher"
podLabels[v1.CreatedByLabel] = string(vmi.UID)
podLabels[v1.VirtualMachineNameLabel] = hostName

for i, requestedHookSidecar := range requestedHookSidecarList {
containers = append(
containers,
Expand Down Expand Up @@ -630,11 +619,11 @@ func (t *templateService) renderLaunchManifest(vmi *v1.VirtualMachineInstance, i
},
}

// TODO use constants for podLabels
hostName := dns.SanitizeHostname(vmi)
pod := k8sv1.Pod{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "virt-launcher-" + domain + "-",
Labels: podLabels,
Labels: podLabels(vmi, hostName),
Annotations: podAnnotations,
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(vmi, v1.VirtualMachineInstanceGroupVersionKind),
Expand Down Expand Up @@ -1395,3 +1384,15 @@ func (p VMIResourcePredicates) Apply() []ResourceRendererOption {
}
return options
}

func podLabels(vmi *v1.VirtualMachineInstance, hostName string) map[string]string {
labels := map[string]string{}

for k, v := range vmi.Labels {
labels[k] = v
}
labels[v1.AppLabel] = "virt-launcher"
labels[v1.CreatedByLabel] = string(vmi.UID)
labels[v1.VirtualMachineNameLabel] = hostName
return labels
}

0 comments on commit f39a98c

Please sign in to comment.