Skip to content

Commit f26e7c9

Browse files
committed
Update latest value of OpenShiftRolloutPlugin in ConfigMap
Signed-off-by: Rizwana777 <[email protected]>
1 parent 1f89f7a commit f26e7c9

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

controllers/configmap.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,25 @@ func (r *RolloutManagerReconciler) reconcileConfigMap(ctx context.Context, cr *r
6161
return fmt.Errorf("failed to unmarshal traffic router plugins from ConfigMap: %s", err)
6262
}
6363

64-
for _, plugin := range actualTrafficRouterPlugins {
64+
// Check if the plugin already exists and if the URL is different, update the ConfigMap
65+
for i, plugin := range actualTrafficRouterPlugins {
6566
if plugin.Name == OpenShiftRolloutPluginName {
66-
// Openshift Route Plugin already present, nothing to do
67-
return nil
67+
if plugin.Location != r.OpenShiftRoutePluginLocation {
68+
actualTrafficRouterPlugins[i].Location = r.OpenShiftRoutePluginLocation
69+
pluginBytes, err := yaml.Marshal(actualTrafficRouterPlugins)
70+
if err != nil {
71+
return fmt.Errorf("error marshalling trafficRouterPlugin to string %s", err)
72+
}
73+
74+
actualConfigMap.Data = map[string]string{
75+
TrafficRouterPluginConfigMapKey: string(pluginBytes),
76+
}
77+
78+
return r.Client.Update(ctx, actualConfigMap)
79+
} else {
80+
// Plugin URL is the same, nothing to do
81+
return nil
82+
}
6883
}
6984
}
7085

controllers/configmap_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,16 @@ var _ = Describe("ConfigMap Test", func() {
115115
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring(OpenShiftRolloutPluginName))
116116
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring(r.OpenShiftRoutePluginLocation))
117117

118+
// overriding this value with new test url to verify whether it updated the existing configMap with the new url
119+
r.OpenShiftRoutePluginLocation = "test-updated-url"
120+
121+
By("calling reconcileConfigMap")
122+
Expect(r.reconcileConfigMap(ctx, a)).To(Succeed())
123+
124+
Expect(fetchObject(ctx, r.Client, a.Namespace, expectedConfigMap.Name, fetchedConfigMap)).To(Succeed())
125+
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring("test/plugin"))
126+
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring(OpenShiftRolloutPluginName))
127+
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring("test-updated-url"))
128+
118129
})
119130
})

0 commit comments

Comments
 (0)