Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhatip committed Jun 21, 2021
1 parent 8385a49 commit dcc2dc4
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 169 deletions.
47 changes: 30 additions & 17 deletions rollout/trafficrouting/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,19 @@ import (

routev1 "github.com/openshift/api/route/v1"
openshiftclientset "github.com/openshift/client-go/route/clientset/versioned"
k8serrors "k8s.io/apimachinery/pkg/api/errors"

"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
logutil "github.com/argoproj/argo-rollouts/utils/log"
"github.com/argoproj/argo-rollouts/utils/record"
)

// Type defines the Openshift traffic routing type.
const (
Type = "Openshift"
)
//Openshift reconciler type
const Type = "Openshift"

// ReconcilerConfig describes static configuration data
type ReconcilerConfig struct {
Expand All @@ -46,12 +44,9 @@ func NewReconciler(cfg ReconcilerConfig) *Reconciler {
}
}

// SetWeight will change the route to either...
// include a canary alternate backend with desired weight
// change an existing canary backend to desired weight
// delete a canary alternate backend
// SetWeight changes the route configuration according to desiredWeight
func (r *Reconciler) SetWeight(desiredWeight int32) error {
r.sendNormalEvent("AlternateBackendWeightUpdate", fmt.Sprintf("Set alternateBackends weight to %d", desiredWeight))
r.sendNormalEvent("WeightUpdate", fmt.Sprintf("Set weight to %d", desiredWeight))
ctx := context.TODO()
routeNameList := r.Cfg.Rollout.Spec.Strategy.Canary.TrafficRouting.Openshift.Routes
doneChan := make(chan struct{})
Expand Down Expand Up @@ -101,14 +96,16 @@ func formatErrors(errs []error) error {
return errors.New(errMsg.String())
}

// update Route according to following:
// update default backend weight
// remove alternateBackends if weight is 0
// otherwise update alternateBackends
func (r *Reconciler) getRoute(ctx context.Context, routeName string) (*routev1.Route, error) {
return r.Cfg.Client.RouteV1().Routes(r.Cfg.Rollout.GetNamespace()).Get(ctx, routeName, metav1.GetOptions{})
}

//Update default backend weight,
//remove alternateBackends if weight is 0,
//otherwise update alternateBackends
func (r *Reconciler) updateRoute(ctx context.Context, routeName string, desiredWeight int32) error {
routes := r.Cfg.Client.RouteV1().Routes(r.Cfg.Rollout.GetNamespace())
// get the route
route, err := routes.Get(ctx, routeName, metav1.GetOptions{})
route, err := r.getRoute(ctx, routeName)
if err != nil {
if k8serrors.IsNotFound(err) {
msg := fmt.Sprintf("Route %q not found", routeName)
Expand All @@ -133,15 +130,31 @@ func (r *Reconciler) updateRoute(ctx context.Context, routeName string, desiredW
}}
}

_, err = routes.Update(ctx, route, metav1.UpdateOptions{})
_, err = r.Cfg.Client.RouteV1().Routes(r.Cfg.Rollout.GetNamespace()).Update(ctx, route, metav1.UpdateOptions{})

return err
}

// Verifies weight of routes given by rollout
func (r *Reconciler) VerifyWeight(desiredWeight int32) (bool, error) {
r.sendNormalEvent("VerifyWeight", fmt.Sprintf("Verify weight is %d", desiredWeight))
for _, routeName := range r.Cfg.Rollout.Spec.Strategy.Canary.TrafficRouting.Openshift.Routes {
route, err := r.getRoute(context.TODO(), routeName)
if err != nil {
return false, err
}
if route.Spec.AlternateBackends == nil {
if desiredWeight != 0 {
return false, nil
}
} else if *route.Spec.To.Weight != 100-desiredWeight || *route.Spec.AlternateBackends[0].Weight != desiredWeight {
return false, nil
}
}
return true, nil
}

// Openshift reconciler type
func (r *Reconciler) Type() string {
return Type
}
Expand Down
Loading

0 comments on commit dcc2dc4

Please sign in to comment.