Skip to content

Commit

Permalink
Implement Verify Weight (#37)
Browse files Browse the repository at this point in the history
Signed-off-by: Mario Bezerra <[email protected]>
  • Loading branch information
mvgmb authored Sep 7, 2023
1 parent fb0d913 commit e610db1
Show file tree
Hide file tree
Showing 4 changed files with 305 additions and 119 deletions.
102 changes: 85 additions & 17 deletions pkg/mocks/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,101 @@ package mocks
import (
contourv1 "github.com/projectcontour/contour/apis/projectcontour/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

const (
Namespace = "default"
StableServiceName = "argo-rollouts-stable-service"
CanaryServiceName = "argo-rollouts-canary-service"
HTTPProxyName = "argo-rollouts-httpproxy"
StableServiceName = "argo-rollouts-stable"
CanaryServiceName = "argo-rollouts-canary"

HTTPProxyName = "argo-rollouts"
ValidHTTPProxyName = "argo-rollouts-valid"
OutdatedHTTPProxyName = "argo-rollouts-outdated"
InvalidHTTPProxyName = "argo-rollouts-invalid"
FalseConditionHTTPProxyName = "argo-rollouts-false-condition"

HTTPProxyGeneration = 1
HTTPProxyDesiredWeight = 20
)

var HTTPProxyObj = contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: HTTPProxyName,
Namespace: Namespace,
},
Spec: contourv1.HTTPProxySpec{
Routes: []contourv1.Route{
func MakeObjects() []runtime.Object {
httpProxy := newHTTPProxy(HTTPProxyName)

validHttpProxy := newHTTPProxy(ValidHTTPProxyName)

invalidHttpProxy := newHTTPProxy(InvalidHTTPProxyName)
invalidHttpProxy.Status = contourv1.HTTPProxyStatus{
Conditions: []contourv1.DetailedCondition{
{
Condition: contourv1.Condition{
Type: contourv1.ConditionTypeServiceError,
Status: contourv1.ConditionTrue,
ObservedGeneration: HTTPProxyGeneration,
},
},
},
}

outdatedHttpProxy := newHTTPProxy(OutdatedHTTPProxyName)
outdatedHttpProxy.Generation = HTTPProxyGeneration + 1

falseConditionHttpProxy := newHTTPProxy(FalseConditionHTTPProxyName)
falseConditionHttpProxy.Status = contourv1.HTTPProxyStatus{
Conditions: []contourv1.DetailedCondition{
{
Services: []contourv1.Service{
{
Name: StableServiceName,
Weight: 100,
Condition: contourv1.Condition{
Type: contourv1.ValidConditionType,
Status: contourv1.ConditionFalse,
ObservedGeneration: HTTPProxyGeneration,
},
},
},
}

objs := []runtime.Object{
httpProxy,
validHttpProxy,
invalidHttpProxy,
outdatedHttpProxy,
falseConditionHttpProxy,
}
return objs
}

func newHTTPProxy(name string) *contourv1.HTTPProxy {
return &contourv1.HTTPProxy{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: Namespace,
Generation: HTTPProxyGeneration,
},
Spec: contourv1.HTTPProxySpec{
Routes: []contourv1.Route{
{
Services: []contourv1.Service{
{
Name: StableServiceName,
Weight: 100 - HTTPProxyDesiredWeight,
},
{
Name: CanaryServiceName,
Weight: HTTPProxyDesiredWeight,
},
},
{
Name: CanaryServiceName,
},
},
},
Status: contourv1.HTTPProxyStatus{
Conditions: []contourv1.DetailedCondition{
{
Condition: contourv1.Condition{
Type: contourv1.ValidConditionType,
Status: contourv1.ConditionTrue,
ObservedGeneration: HTTPProxyGeneration,
},
},
},
},
},
}
}
Loading

0 comments on commit e610db1

Please sign in to comment.