@@ -1170,69 +1170,76 @@ func TestReconcileArgoCD_reconcileDexOAuthClientSecret(t *testing.T) {
11701170 assert .True (t , tokenExists , "Dex is enabled but unable to create oauth client secret" )
11711171}
11721172
1173- func TestRetainKubernetesData (t * testing.T ) {
1173+ func TestUpdateMapValue (t * testing.T ) {
11741174 tests := []struct {
11751175 name string
11761176 source map [string ]string
1177- live map [string ]string
1177+ existing map [string ]string
11781178 expected map [string ]string
11791179 }{
11801180 {
1181- name : "Add Kubernetes -specific keys not in source" ,
1181+ name : "Retain non-operator -specific keys not in source" ,
11821182 source : map [string ]string {
1183- "custom-label" : "custom-value" ,
1183+ "node.kubernetes.io/pod" : "true" ,
1184+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
1185+ "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
11841186 },
1185- live : map [string ]string {
1187+ existing : map [string ]string {
11861188 "node.kubernetes.io/pod" : "true" ,
11871189 "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
11881190 "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
1191+ "custom-label" : "custom-value" ,
11891192 },
11901193 expected : map [string ]string {
1191- "custom-label" : "custom-value" , // unchanged
1192- "node.kubernetes.io/pod" : "true" , // added
1193- "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // added
1194- "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // added
1194+ "custom-label" : "custom-value" , // retained from existing
1195+ "node.kubernetes.io/pod" : "true" , // unchanged
1196+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // unchanged
1197+ "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // unchanged
11951198 },
11961199 },
11971200 {
1198- name : "Ignores non-Kubernetes- specific keys" ,
1201+ name : "Override operator- specific keys in live with source " ,
11991202 source : map [string ]string {
1200- "custom-label" : "custom-value" ,
1203+ "node.kubernetes.io/pod" : "source-true" ,
1204+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12011205 },
1202- live : map [string ]string {
1203- "non-k8s-key " : "non-k8s-value" ,
1204- "custom-label " : "live-value " ,
1206+ existing : map [string ]string {
1207+ "node.kubernetes.io/pod " : "live-true" , // should override
1208+ "kubectl.kubernetes.io/restartedAt " : "2024-12-05T09:46:46+05:30 " ,
12051209 },
12061210 expected : map [string ]string {
1207- "custom-label" : "custom-value" , // unchanged
1211+ "node.kubernetes.io/pod" : "source-true" ,
1212+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12081213 },
12091214 },
12101215 {
1211- name : "Do not override existing Kubernetes -specific keys in source" ,
1216+ name : "Retain existing operator -specific keys from source" ,
12121217 source : map [string ]string {
1213- "node.kubernetes.io/pod" : "source-true" ,
1218+ "node.kubernetes.io/pod" : "source-true" ,
1219+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12141220 },
1215- live : map [string ]string {
1216- "node.kubernetes.io/pod" : "live -true" , // should not override
1221+ existing : map [string ]string {
1222+ "node.kubernetes.io/pod" : "source -true" ,
12171223 },
12181224 expected : map [string ]string {
1219- "node.kubernetes.io/pod" : "source-true" , // source takes precedence
1225+ "node.kubernetes.io/pod" : "source-true" ,
1226+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12201227 },
12211228 },
12221229 {
12231230 name : "Handles empty live map" ,
12241231 source : map [string ]string {
12251232 "custom-label" : "custom-value" ,
12261233 },
1227- live : map [string ]string {},
1234+ existing : map [string ]string {},
12281235 expected : map [string ]string {
12291236 "custom-label" : "custom-value" , // unchanged
12301237 },
12311238 },
12321239 {
12331240 name : "Handles empty source map" ,
12341241 source : map [string ]string {},
1235- live : map [string ]string {
1242+ existing : map [string ]string {
12361243 "openshift.io/resource" : "value" ,
12371244 },
12381245 expected : map [string ]string {
@@ -1243,8 +1250,8 @@ func TestRetainKubernetesData(t *testing.T) {
12431250
12441251 for _ , tt := range tests {
12451252 t .Run (tt .name , func (t * testing.T ) {
1246- addKubernetesData ( tt .source , tt .live )
1247- assert .Equal (t , tt .expected , tt .source )
1253+ UpdateMapValues ( & tt .existing , tt .source )
1254+ assert .Equal (t , tt .expected , tt .existing )
12481255 })
12491256 }
12501257}
0 commit comments