Skip to content

Commit

Permalink
moved deprecated label to annotations
Browse files Browse the repository at this point in the history
Signed-off-by: Karel Šimon <[email protected]>
  • Loading branch information
ksimon1 authored and kubevirt-bot committed Apr 1, 2021
1 parent c3c392e commit 0a0a99f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
12 changes: 6 additions & 6 deletions internal/operands/common-templates/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const (
GoldenImagesNSname = "kubevirt-os-images"
BundleDir = "data/common-templates-bundle/"

TemplateVersionLabel = "template.kubevirt.io/version"
TemplateTypeLabel = "template.kubevirt.io/type"
TemplateOsLabelPrefix = "os.template.kubevirt.io/"
TemplateFlavorLabelPrefix = "flavor.template.kubevirt.io/"
TemplateWorkloadLabelPrefix = "workload.template.kubevirt.io/"
TemplateDeprecatedLabel = "template.kubevirt.io/deprecated"
TemplateVersionLabel = "template.kubevirt.io/version"
TemplateTypeLabel = "template.kubevirt.io/type"
TemplateOsLabelPrefix = "os.template.kubevirt.io/"
TemplateFlavorLabelPrefix = "flavor.template.kubevirt.io/"
TemplateWorkloadLabelPrefix = "workload.template.kubevirt.io/"
TemplateDeprecatedAnnotation = "template.kubevirt.io/deprecated"
)
5 changes: 4 additions & 1 deletion internal/operands/common-templates/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ func reconcileOlderTemplates(request *common.Request) ([]common.ReconcileFunc, e
funcs := make([]common.ReconcileFunc, 0, len(existingTemplates.Items))
for i := range existingTemplates.Items {
template := &existingTemplates.Items[i]
template.Labels[TemplateDeprecatedLabel] = "true"
if template.Annotations == nil {
template.Annotations = make(map[string]string)
}
template.Annotations[TemplateDeprecatedAnnotation] = "true"
funcs = append(funcs, func(*common.Request) (common.ResourceStatus, error) {
return common.CreateOrUpdate(request).
ClusterResource(template).
Expand Down
2 changes: 1 addition & 1 deletion internal/operands/common-templates/reconcile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var _ = Describe("Common-Templates operand", func() {
Expect(updatedTpl.Labels[testWorkflowLabel]).To(Equal(""), TemplateWorkloadLabelPrefix+" should be empty")
Expect(updatedTpl.Labels[TemplateTypeLabel]).To(Equal("base"), TemplateTypeLabel+" should equal base")
Expect(updatedTpl.Labels[TemplateVersionLabel]).To(Equal("not-latest"), TemplateVersionLabel+" should equal not-latest")
Expect(updatedTpl.Labels[TemplateDeprecatedLabel]).To(Equal("true"), TemplateDeprecatedLabel+" should not be empty")
Expect(updatedTpl.Annotations[TemplateDeprecatedAnnotation]).To(Equal("true"), TemplateDeprecatedAnnotation+" should not be empty")
})
It("should not remove labels from latest templates", func() {
_, err := operand.Reconcile(&request)
Expand Down
11 changes: 11 additions & 0 deletions tests/commonTemplates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,17 @@ var _ = Describe("Common templates", func() {
updatedTpl.Labels[commonTemplates.TemplateVersionLabel] == "not-latest"
}, shortTimeout).Should(BeTrue(), "labels were not removed from older templates")
})
It("[test_id:5969]: should add deprecated annotation to old templates", func() {
triggerReconciliation()

Eventually(func() bool {
updatedTpl := &templatev1.Template{}
key := client.ObjectKey{Name: oldTemplate.Name, Namespace: oldTemplate.Namespace}
err := apiClient.Get(ctx, key, updatedTpl)
return err == nil &&
updatedTpl.Annotations[commonTemplates.TemplateDeprecatedAnnotation] == "true"
}, shortTimeout).Should(BeTrue(), "deprecated annotation should be added to old template")
})
It("should continue to have labels on latest templates", func() {
triggerReconciliation()

Expand Down

0 comments on commit 0a0a99f

Please sign in to comment.