Skip to content

Commit

Permalink
Update latest value of OpenShiftRolloutPlugin in ConfigMap
Browse files Browse the repository at this point in the history
Signed-off-by: Rizwana777 <[email protected]>
  • Loading branch information
Rizwana777 authored and jgwest committed Apr 10, 2024
1 parent 1c3ea3e commit ec88ea4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
21 changes: 18 additions & 3 deletions controllers/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,25 @@ func (r *RolloutManagerReconciler) reconcileConfigMap(ctx context.Context, cr *r
return fmt.Errorf("failed to unmarshal traffic router plugins from ConfigMap: %s", err)
}

for _, plugin := range actualTrafficRouterPlugins {
// Check if the plugin already exists and if the URL is different, update the ConfigMap
for i, plugin := range actualTrafficRouterPlugins {
if plugin.Name == OpenShiftRolloutPluginName {
// Openshift Route Plugin already present, nothing to do
return nil
if plugin.Location != r.OpenShiftRoutePluginLocation {
actualTrafficRouterPlugins[i].Location = r.OpenShiftRoutePluginLocation
pluginBytes, err := yaml.Marshal(actualTrafficRouterPlugins)
if err != nil {
return fmt.Errorf("error marshalling trafficRouterPlugin to string %s", err)
}

actualConfigMap.Data = map[string]string{
TrafficRouterPluginConfigMapKey: string(pluginBytes),
}

return r.Client.Update(ctx, actualConfigMap)
} else {
// Plugin URL is the same, nothing to do
return nil
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions controllers/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,16 @@ var _ = Describe("ConfigMap Test", func() {
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring(OpenShiftRolloutPluginName))
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring(r.OpenShiftRoutePluginLocation))

// overriding this value with new test url to verify whether it updated the existing configMap with the new url
r.OpenShiftRoutePluginLocation = "test-updated-url"

By("calling reconcileConfigMap")
Expect(r.reconcileConfigMap(ctx, a)).To(Succeed())

Expect(fetchObject(ctx, r.Client, a.Namespace, expectedConfigMap.Name, fetchedConfigMap)).To(Succeed())
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring("test/plugin"))
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring(OpenShiftRolloutPluginName))
Expect(fetchedConfigMap.Data[TrafficRouterPluginConfigMapKey]).To(ContainSubstring("test-updated-url"))

})
})

0 comments on commit ec88ea4

Please sign in to comment.