Skip to content

Commit

Permalink
Delete central ingress/routegroup when StackSet has no Stacks. (#597)
Browse files Browse the repository at this point in the history
* Delete central ingress/routegroup when StackSet has no Stacks.

Signed-off-by: Rodrigo Reis <[email protected]>

* Wait for stack also, get name from return value.

Signed-off-by: Rodrigo Reis <[email protected]>

* Fix presclaing timeout.

Signed-off-by: Rodrigo Reis <[email protected]>

* Improve commenting.

Signed-off-by: Rodrigo Reis <[email protected]>

* Fix prescaling timeout.

Signed-off-by: Rodrigo Reis <[email protected]>

---------

Signed-off-by: Rodrigo Reis <[email protected]>
  • Loading branch information
gargravarr authored Feb 28, 2024
1 parent 6521cbd commit c9e6ecf
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
50 changes: 49 additions & 1 deletion cmd/e2e/ingress_source_switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func TestStackTTLConvertToSegmentIngress(t *testing.T) {

// create stackset with central ingress
spec := specFactory.Create(t, "v1")
err := createStackSet(stacksetName, 1, spec)
err := createStackSet(stacksetName, 0, spec)
require.NoError(t, err)
_, err = waitForIngress(t, stacksetName)
require.NoError(t, err)
Expand Down Expand Up @@ -183,3 +183,51 @@ func TestStackTTLConvertToSegmentIngress(t *testing.T) {
).await()
require.NoError(t, err)
}

func TestShallowStackSetConvertToSegmentIngress(t *testing.T) {
t.Parallel()
stacksetName := "stackset-shallow-convert-segment"
stackVersion := "v1"
specFactory := NewTestStacksetSpecFactory(stacksetName).Ingress()

// create stackset with central ingress
spec := specFactory.Create(t, stackVersion)
err := createStackSet(stacksetName, 0, spec)
require.NoError(t, err)

_, err = waitForIngress(t, stacksetName)
require.NoError(t, err)
stack, err := waitForStack(t, stacksetName, stackVersion)
require.NoError(t, err)

err = deleteStack(stack.Name)
require.NoError(t, err)

err = resourceDeleted(
t,
"stack",
stack.Name,
stackInterface(),
).withTimeout(time.Second * 60).await()
require.NoError(t, err)

// Add the annotation to convert to segment ingresses but DON'T increase the
// StackSet version.
err = updateStackSetWithAnnotations(
stacksetName,
spec,
map[string]string{controller.TrafficSegmentsAnnotationKey: "true"},
)
require.NoError(t, err)

time.Sleep(time.Second * 20)

// make sure controller DOES delete the ingress
err = resourceDeleted(
t,
"ingress",
stacksetName,
ingressInterface(),
).await()
require.NoError(t, err)
}
8 changes: 8 additions & 0 deletions cmd/e2e/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ func createStackSetWithAnnotations(
return err
}

func deleteStack(stackName string) error {
return stackInterface().Delete(
context.Background(),
stackName,
metav1.DeleteOptions{},
)
}

func stacksetExists(stacksetName string) bool {
_, err := stacksetInterface().Get(context.Background(), stacksetName, metav1.GetOptions{})
return err == nil
Expand Down
16 changes: 16 additions & 0 deletions controller/stackset.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,22 @@ func (c *StackSetController) convertToTrafficSegments(
}
}

if len(ssc.StackContainers) == 0 {
c.logger.Infof(
"No stacks found for StackSet %s, safe to delete central "+
"ingress/routegroup",
ssc.StackSet.Name,
)

// If we don't have any stacks, we can delete the central ingress
// resources
oldEnough := metav1.NewTime(
time.Now().Add(-c.ingressSourceSwitchTTL-time.Minute),
)
ingTimestamp = &oldEnough
rgTimestamp = &oldEnough
}

if ingTimestamp != nil && ssc.Ingress != nil {
if !resourceReadyTime(ingTimestamp.Time, c.ingressSourceSwitchTTL) {
c.logger.Infof(
Expand Down

0 comments on commit c9e6ecf

Please sign in to comment.