@@ -1169,69 +1169,76 @@ func TestReconcileArgoCD_reconcileDexOAuthClientSecret(t *testing.T) {
11691169 assert .True (t , tokenExists , "Dex is enabled but unable to create oauth client secret" )
11701170}
11711171
1172- func TestRetainKubernetesData (t * testing.T ) {
1172+ func TestUpdateMapValue (t * testing.T ) {
11731173 tests := []struct {
11741174 name string
11751175 source map [string ]string
1176- live map [string ]string
1176+ existing map [string ]string
11771177 expected map [string ]string
11781178 }{
11791179 {
1180- name : "Add Kubernetes -specific keys not in source" ,
1180+ name : "Retain non-operator -specific keys not in source" ,
11811181 source : map [string ]string {
1182- "custom-label" : "custom-value" ,
1182+ "node.kubernetes.io/pod" : "true" ,
1183+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
1184+ "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
11831185 },
1184- live : map [string ]string {
1186+ existing : map [string ]string {
11851187 "node.kubernetes.io/pod" : "true" ,
11861188 "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
11871189 "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
1190+ "custom-label" : "custom-value" ,
11881191 },
11891192 expected : map [string ]string {
1190- "custom-label" : "custom-value" , // unchanged
1191- "node.kubernetes.io/pod" : "true" , // added
1192- "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // added
1193- "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // added
1193+ "custom-label" : "custom-value" , // retained from existing
1194+ "node.kubernetes.io/pod" : "true" , // unchanged
1195+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // unchanged
1196+ "openshift.openshift.io/restartedAt" : "2024-12-05T09:46:46+05:30" , // unchanged
11941197 },
11951198 },
11961199 {
1197- name : "Ignores non-Kubernetes- specific keys" ,
1200+ name : "Override operator- specific keys in live with source " ,
11981201 source : map [string ]string {
1199- "custom-label" : "custom-value" ,
1202+ "node.kubernetes.io/pod" : "source-true" ,
1203+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12001204 },
1201- live : map [string ]string {
1202- "non-k8s-key " : "non-k8s-value" ,
1203- "custom-label " : "live-value " ,
1205+ existing : map [string ]string {
1206+ "node.kubernetes.io/pod " : "live-true" , // should override
1207+ "kubectl.kubernetes.io/restartedAt " : "2024-12-05T09:46:46+05:30 " ,
12041208 },
12051209 expected : map [string ]string {
1206- "custom-label" : "custom-value" , // unchanged
1210+ "node.kubernetes.io/pod" : "source-true" ,
1211+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12071212 },
12081213 },
12091214 {
1210- name : "Do not override existing Kubernetes -specific keys in source" ,
1215+ name : "Retain existing operator -specific keys from source" ,
12111216 source : map [string ]string {
1212- "node.kubernetes.io/pod" : "source-true" ,
1217+ "node.kubernetes.io/pod" : "source-true" ,
1218+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12131219 },
1214- live : map [string ]string {
1215- "node.kubernetes.io/pod" : "live -true" , // should not override
1220+ existing : map [string ]string {
1221+ "node.kubernetes.io/pod" : "source -true" ,
12161222 },
12171223 expected : map [string ]string {
1218- "node.kubernetes.io/pod" : "source-true" , // source takes precedence
1224+ "node.kubernetes.io/pod" : "source-true" ,
1225+ "kubectl.kubernetes.io/restartedAt" : "2024-12-05T09:46:46+05:30" ,
12191226 },
12201227 },
12211228 {
12221229 name : "Handles empty live map" ,
12231230 source : map [string ]string {
12241231 "custom-label" : "custom-value" ,
12251232 },
1226- live : map [string ]string {},
1233+ existing : map [string ]string {},
12271234 expected : map [string ]string {
12281235 "custom-label" : "custom-value" , // unchanged
12291236 },
12301237 },
12311238 {
12321239 name : "Handles empty source map" ,
12331240 source : map [string ]string {},
1234- live : map [string ]string {
1241+ existing : map [string ]string {
12351242 "openshift.io/resource" : "value" ,
12361243 },
12371244 expected : map [string ]string {
@@ -1242,8 +1249,8 @@ func TestRetainKubernetesData(t *testing.T) {
12421249
12431250 for _ , tt := range tests {
12441251 t .Run (tt .name , func (t * testing.T ) {
1245- addKubernetesData ( tt .source , tt .live )
1246- assert .Equal (t , tt .expected , tt .source )
1252+ UpdateMapValues ( & tt .existing , tt .source )
1253+ assert .Equal (t , tt .expected , tt .existing )
12471254 })
12481255 }
12491256}
0 commit comments