Skip to content

Commit

Permalink
Fix annotation sync for RouteGroups; end-2-end tests for synchronized…
Browse files Browse the repository at this point in the history
… annotations.

Signed-off-by: Rodrigo Reis <[email protected]>
  • Loading branch information
gargravarr committed Jan 15, 2024
1 parent 5587150 commit d3304c6
Show file tree
Hide file tree
Showing 2 changed files with 200 additions and 13 deletions.
207 changes: 195 additions & 12 deletions cmd/e2e/annotations_sync_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,200 @@
package main

// import (
// "testing"
// )
import (
"fmt"
"reflect"
"testing"
"time"

// func TestSyncAnnotationsPropagateToSegments(t *testing.T) {
// t.Parallel()
"github.com/stretchr/testify/require"
"github.com/zalando-incubator/stackset-controller/controller"
"github.com/zalando-incubator/stackset-controller/pkg/core"
)

// stacksetName := "stackset-annotations-sync"
// specFactory := NewTestStacksetSpecFactory(
// stacksetName,
// ).Ingress().RouteGroup()
func TestSyncAnnotationsPropagateToSegments(t *testing.T) {
t.Parallel()

// spec := specFactory.Create("v1")
// spec.Ingress.Annotations["a-random-annotation"] = "a-random-value"
// }
for i, tc := range []struct {
annotationsIng []map[string]string
annotationsRg []map[string]string
expectedIng []map[string]string
expectedRg []map[string]string
}{
{
annotationsIng: []map[string]string{
{},
{
"example.org/i-haz-synchronize": "keep-sync",
"teapot.org/the-best": "for-real",
"example.org/no-sync-plz": "ditto",
},
},
annotationsRg: []map[string]string{
{},
{
"example.org/i-haz-synchronize": "synchronize",
"teapot.org/the-best": "of-all-time",
"example.org/no-sync-plz": "nope",
},
},
expectedIng: []map[string]string{
{
"example.org/i-haz-synchronize": "keep-sync",
"teapot.org/the-best": "for-real",
},
{
"example.org/i-haz-synchronize": "keep-sync",
"teapot.org/the-best": "for-real",
"example.org/no-sync-plz": "ditto",
},
},
expectedRg: []map[string]string{
{
"example.org/i-haz-synchronize": "synchronize",
"teapot.org/the-best": "of-all-time",
},
{
"example.org/i-haz-synchronize": "synchronize",
"teapot.org/the-best": "of-all-time",
"example.org/no-sync-plz": "nope",
},
},
},
{
annotationsIng: []map[string]string{
{
"example.org/i-haz-synchronize": "keep-sync",
"teapot.org/the-best": "for-real",
},
{
"example.org/i-haz-synchronize": "keep-sync",
"example.org/no-sync-plz": "ditto",
},
},
annotationsRg: []map[string]string{
{
"example.org/i-haz-synchronize": "synchronize",
"teapot.org/the-best": "of-all-time",
},
{
"teapot.org/the-best": "of-all-time",
"example.org/no-sync-plz": "nope",
},
},
expectedIng: []map[string]string{
{
"example.org/i-haz-synchronize": "keep-sync",
},
{
"example.org/i-haz-synchronize": "keep-sync",
"example.org/no-sync-plz": "ditto",
},
},
expectedRg: []map[string]string{
{
"teapot.org/the-best": "of-all-time",
},
{
"teapot.org/the-best": "of-all-time",
"example.org/no-sync-plz": "nope",
},
},
},
} {
stacksetName := fmt.Sprintf("stackset-annotations-sync-case-%d", i)
specFactory := NewTestStacksetSpecFactory(
stacksetName,
).Ingress().RouteGroup()
spec := specFactory.Create("v0")

Check failure on line 108 in cmd/e2e/annotations_sync_test.go

View workflow job for this annotation

GitHub Actions / tests

not enough arguments in call to specFactory.Create

for i, a := range tc.annotationsIng {
version := fmt.Sprintf("v%d", i)
spec.StackTemplate.Spec.Version = version
spec.Ingress.Annotations = a
spec.RouteGroup.Annotations = tc.annotationsRg[i]

var err error
if i == 0 {
err = createStackSetWithAnnotations(
stacksetName,
1,
spec,
map[string]string{
controller.TrafficSegmentsAnnotationKey: "true",
},
)
} else {
err = updateStackSetWithAnnotations(
stacksetName,
spec,
map[string]string{
controller.TrafficSegmentsAnnotationKey: "true",
},
)
}
require.NoError(t, err)

_, err = waitForIngress(
t,
stacksetName+"-"+version+"-traffic-segment",
)
require.NoError(t, err)

_, err = waitForRouteGroup(
t,
stacksetName+"-"+version+"-traffic-segment",
)
require.NoError(t, err)
}

// Wait some time for the annotations to be propagated
time.Sleep(time.Second * 10)

for i := 0; i < len(tc.annotationsIng); i++ {
version := fmt.Sprintf("v%d", i)
ingress, err := waitForIngress(
t,
stacksetName+"-"+version+"-traffic-segment",
)
require.NoError(t, err)

delete(
ingress.Annotations,
"stackset-controller.zalando.org/stack-generation",
)
delete(
ingress.Annotations,
core.IngressPredicateKey,
)

if !reflect.DeepEqual(tc.expectedIng[i], ingress.Annotations) {
t.Errorf(
"Expected ingress annotations in %q to be %v, got %v",
version,
tc.expectedIng[i],
ingress.Annotations,
)
}

routeGroup, err := waitForRouteGroup(
t,
stacksetName+"-"+version+"-traffic-segment",
)
require.NoError(t, err)

delete(
routeGroup.Annotations,
"stackset-controller.zalando.org/stack-generation",
)

if !reflect.DeepEqual(tc.expectedRg[i], routeGroup.Annotations) {
t.Errorf(
"Expected routeGroup annotations in %q to be %v, got %v",
version,
tc.expectedRg[i],
routeGroup.Annotations,
)
}
}
}
}
6 changes: 5 additions & 1 deletion controller/stack_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ func (c *StackSetController) ReconcileStackRouteGroup(ctx context.Context, stack

// Check if we need to update the RouteGroup
if core.IsResourceUpToDate(stack, existing.ObjectMeta) &&
equality.Semantic.DeepEqual(routegroup.Spec, existing.Spec) {
equality.Semantic.DeepEqual(routegroup.Spec, existing.Spec) &&
core.AreAnnotationsUpToDate(
routegroup.ObjectMeta,
existing.ObjectMeta,
) {

return nil
}
Expand Down

0 comments on commit d3304c6

Please sign in to comment.