Skip to content

Commit

Permalink
Merge pull request #15 from ishitasequeira/feature/integrate-openshif…
Browse files Browse the repository at this point in the history
…t-route-plugin

integrate openshift route plugin with rollouts manager
  • Loading branch information
iam-veeramalla authored Jan 5, 2024
2 parents 7bca75e + 670fb23 commit 4aa2d91
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 403 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ kubeconfig
*.swp
*.swo
*~
vendor/*
73 changes: 73 additions & 0 deletions controllers/configmap.go
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)
}
7 changes: 7 additions & 0 deletions controllers/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ const (
DefaultRolloutsNotificationSecretName = "argo-rollouts-notification-secret"
// DefaultRolloutsServiceSelectorKey is key used by selector
DefaultRolloutsSelectorKey = "app.kubernetes.io/name"

// OpenShiftRolloutPluginName is the plugin name for Openshift Route Plugin
OpenShiftRolloutPluginName = "openshift-route-plugin"
// OpenShiftRolloutPluginPath is the path on the rollout controller pod where the plugin will be mounted
OpenShiftRolloutPluginPath = "/plugin/rollouts-plugin-trafficrouter-openshift"
// DefaultRolloutsConfigMapName is the default name of the ConfigMap that contains the Rollouts controller configuration
DefaultRolloutsConfigMapName = "argo-rollouts-config"
)
7 changes: 5 additions & 2 deletions controllers/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ func (r *RolloutManagerReconciler) reconcileRolloutsDeployment(cr *rolloutsApi.R
!reflect.DeepEqual(actualDeployment.Spec.Selector, desiredDeployment.Spec.Selector) ||
!reflect.DeepEqual(actualDeployment.Spec.Template.Spec.NodeSelector, desiredDeployment.Spec.Template.Spec.NodeSelector) ||
!reflect.DeepEqual(actualDeployment.Spec.Template.Spec.Tolerations, desiredDeployment.Spec.Template.Spec.Tolerations) ||
!reflect.DeepEqual(actualPodSpec.SecurityContext, desiredPodSpec.SecurityContext)
!reflect.DeepEqual(actualPodSpec.SecurityContext, desiredPodSpec.SecurityContext) ||
!reflect.DeepEqual(actualDeployment.Spec.Template.Spec.Volumes, desiredDeployment.Spec.Template.Spec.Volumes)

if deploymentsDifferent {
actualDeployment.Spec.Template.Spec.Containers = desiredPodSpec.Containers
Expand All @@ -98,6 +99,7 @@ func (r *RolloutManagerReconciler) reconcileRolloutsDeployment(cr *rolloutsApi.R
actualDeployment.Spec.Template.Spec.NodeSelector = desiredDeployment.Spec.Template.Spec.NodeSelector
actualDeployment.Spec.Template.Spec.Tolerations = desiredDeployment.Spec.Template.Spec.Tolerations
actualDeployment.Spec.Template.Spec.SecurityContext = desiredPodSpec.SecurityContext
actualDeployment.Spec.Template.Spec.Volumes = desiredDeployment.Spec.Template.Spec.Volumes
return r.Client.Update(context.TODO(), actualDeployment)
}
return nil
Expand Down Expand Up @@ -160,10 +162,11 @@ func rolloutsContainer(cr *rolloutsApi.RolloutManager) corev1.Container {
},
},
AllowPrivilegeEscalation: boolPtr(false),
ReadOnlyRootFilesystem: boolPtr(true),
ReadOnlyRootFilesystem: boolPtr(false),
RunAsNonRoot: boolPtr(true),
},
}

}

// boolPtr returns a pointer to val
Expand Down
6 changes: 6 additions & 0 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ func (r *RolloutManagerReconciler) reconcileRolloutsController(cr *rolloutsApi.R
return err
}

// reconcile configMap for plugins
log.Info("reconciling configMap for plugins")
if err := r.reconcileConfigMap(cr); err != nil {
return err
}

log.Info("reconciling rollouts deployment")
if err := r.reconcileRolloutsDeployment(cr, sa); err != nil {
return err
Expand Down
48 changes: 25 additions & 23 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/argoproj-labs/argo-rollouts-manager
go 1.19

require (
github.com/stretchr/testify v1.8.0
github.com/argoproj/argo-rollouts v1.6.3
github.com/stretchr/testify v1.8.4
k8s.io/api v0.26.0
k8s.io/apimachinery v0.26.0
k8s.io/client-go v0.26.0
Expand All @@ -12,59 +13,60 @@ require (

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/zapr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/net v0.3.1-0.20221206200815-1e63c2f08a10 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.0 // indirect
k8s.io/component-base v0.26.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221128185143-99ec85e7a448 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 4aa2d91

Please sign in to comment.