Skip to content

Commit 0823623

Browse files
committed
update IsTrackedByOperator func to take in runtime.Object
Signed-off-by: Anand Kumar Singh <anandrkskd@gmail.com>
1 parent 8f09b59 commit 0823623

File tree

3 files changed

+238
-184
lines changed

3 files changed

+238
-184
lines changed

pkg/cacheutils/utils.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package cacheutils
22

33
import (
44
v1 "k8s.io/api/core/v1"
5+
"k8s.io/apimachinery/pkg/api/meta"
6+
"k8s.io/apimachinery/pkg/runtime"
57
clientgotools "k8s.io/client-go/tools/cache"
68

79
"github.com/argoproj-labs/argocd-operator/common"
@@ -16,7 +18,7 @@ func StripDataFromSecretOrConfigMapTransform() clientgotools.TransformFunc {
1618

1719
if s, ok := in.(*v1.Secret); ok {
1820
// Keep full secret for operator-managed resources
19-
if IsTrackedByOperator(s.Labels) {
21+
if IsTrackedByOperator(s) {
2022
return in, nil
2123
}
2224

@@ -30,7 +32,7 @@ func StripDataFromSecretOrConfigMapTransform() clientgotools.TransformFunc {
3032
}
3133
if cm, ok := in.(*v1.ConfigMap); ok {
3234
// Keep full configmap for operator-managed resources
33-
if IsTrackedByOperator(cm.Labels) {
35+
if IsTrackedByOperator(cm) {
3436
return in, nil
3537
}
3638

@@ -50,13 +52,22 @@ func StripDataFromSecretOrConfigMapTransform() clientgotools.TransformFunc {
5052
// A resource is considered tracked if it has any of the following labels:
5153
// - ArgoCDTrackedByOperatorLabel: indicates the resource is managed by the operator
5254
// - ArgoCDSecretTypeLabel: indicates the resource is an ArgoCD-specific secret type
53-
func IsTrackedByOperator(labels map[string]string) bool {
55+
func IsTrackedByOperator(obj runtime.Object) bool {
5456
// List of labels that indicate operator tracking
5557
trackedLabels := []string{
5658
common.ArgoCDTrackedByOperatorLabel,
5759
common.ArgoCDSecretTypeLabel,
5860
}
5961

62+
// Get labels from the object's metadata
63+
var labels map[string]string
64+
if obj != nil {
65+
// Use meta.Accessor to get object labels (if obj implements metav1.Object)
66+
if accessor, err := meta.Accessor(obj); err == nil {
67+
labels = accessor.GetLabels()
68+
}
69+
}
70+
6071
// Check if any tracking label exists
6172
for _, l := range trackedLabels {
6273
if _, exists := labels[l]; exists {

0 commit comments

Comments
 (0)