Skip to content

Commit

Permalink
Merge pull request #8763 from caseydavenport/auto-pick-of-#8762-origi…
Browse files Browse the repository at this point in the history
…n-release-v3.28

[release-v3.28] Auto pick #8762: Maintain projectcalico labels on v1 API
  • Loading branch information
caseydavenport committed Apr 26, 2024
2 parents 56ccaac + 149bb39 commit 168494c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion libcalico-go/lib/backend/k8s/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package resources

import (
"strings"

log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -177,7 +179,17 @@ func ConvertCalicoResourceToK8sResource(resIn Resource) (Resource, error) {
meta.ResourceVersion = rom.GetResourceVersion()

// Explicitly nil out the labels on the underlying object so that they are not duplicated.
meta.Labels = nil
// We make an exception for projectcalico.org/ labels, which we own and may use on the v1 API.
var v1Labels map[string]string
for k, v := range rom.GetLabels() {
if strings.Contains(k, "projectcalico.org/") {
if v1Labels == nil {
v1Labels = map[string]string{}
}
v1Labels[k] = v
}
}
meta.Labels = v1Labels

if rom.GetUID() != "" {
uid, err := conversion.ConvertUID(rom.GetUID())
Expand Down

0 comments on commit 168494c

Please sign in to comment.