-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from ishitasequeira/feature/integrate-openshif…
…t-route-plugin integrate openshift route plugin with rollouts manager
- Loading branch information
Showing
7 changed files
with
199 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ kubeconfig | |
*.swp | ||
*.swo | ||
*~ | ||
vendor/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package rollouts | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
rolloutsApi "github.com/argoproj-labs/argo-rollouts-manager/api/v1alpha1" | ||
"github.com/argoproj/argo-rollouts/utils/plugin/types" | ||
"gopkg.in/yaml.v2" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// Reconcile the Rollouts Default Config Map. | ||
func (r *RolloutManagerReconciler) reconcileConfigMap(cr *rolloutsApi.RolloutManager) error { | ||
|
||
desiredConfigMap := &corev1.ConfigMap{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: DefaultRolloutsConfigMapName, | ||
Namespace: cr.Namespace, | ||
Labels: map[string]string{ | ||
"app.kubernetes.io/name": DefaultRolloutsConfigMapName, | ||
}, | ||
}, | ||
} | ||
trafficRouterPlugins := []types.PluginItem{ | ||
{ | ||
Name: OpenShiftRolloutPluginName, | ||
Location: "file://" + OpenShiftRolloutPluginPath, | ||
}, | ||
} | ||
pluginString, err := yaml.Marshal(trafficRouterPlugins) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling trafficRouterPlugin to string %s", err) | ||
} | ||
desiredConfigMap.Data = make(map[string]string, 0) | ||
desiredConfigMap.Data["trafficRouterPlugins"] = string(pluginString) | ||
|
||
actualConfigMap := &corev1.ConfigMap{} | ||
|
||
if err := fetchObject(r.Client, cr.Namespace, desiredConfigMap.Name, actualConfigMap); err != nil { | ||
if errors.IsNotFound(err) { | ||
// ConfigMap is not present, create default config map | ||
log.Info("configMap not found, creating default configmap with openshift route plugin information") | ||
return r.Client.Create(context.TODO(), desiredConfigMap) | ||
} | ||
return fmt.Errorf("failed to get the serviceAccount associated with %s : %s", desiredConfigMap.Name, err) | ||
} | ||
|
||
var actualTrafficRouterPlugins []types.PluginItem | ||
if err = yaml.Unmarshal([]byte(actualConfigMap.Data["trafficRouterPlugins"]), &actualTrafficRouterPlugins); err != nil { | ||
return fmt.Errorf("failed to unmarshal traffic router plugins from ConfigMap: %s", err) | ||
} | ||
|
||
for _, plugin := range actualTrafficRouterPlugins { | ||
if plugin.Name == OpenShiftRolloutPluginName { | ||
// Openshift Route Plugin already present, nothing to do | ||
return nil | ||
} | ||
} | ||
|
||
updatedTrafficRouterPlugins := append(actualTrafficRouterPlugins, trafficRouterPlugins...) | ||
|
||
pluginString, err = yaml.Marshal(updatedTrafficRouterPlugins) | ||
if err != nil { | ||
return fmt.Errorf("error marshalling trafficRouterPlugin to string %s", err) | ||
} | ||
|
||
actualConfigMap.Data["trafficRouterPlugins"] = string(pluginString) | ||
|
||
return r.Client.Update(context.TODO(), actualConfigMap) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.