Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update latest value of OpenShiftRolloutPlugin in ConfigMap #51

Merged
merged 1 commit into from
Apr 10, 2024
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"))

})
})
Loading