Skip to content

Commit

Permalink
Merge pull request #8762 from caseydavenport/casey-maintain-pc
Browse files Browse the repository at this point in the history
Maintain projectcalico labels on v1 API
  • Loading branch information
caseydavenport committed Apr 26, 2024
2 parents 05d3e2d + e02091a commit 905156a
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 905156a

Please sign in to comment.