Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))

})
})