Skip to content

Commit

Permalink
introduce seperate finalizer for ep
Browse files Browse the repository at this point in the history
Signed-off-by: Karol Szwaj <karol.szwaj@gmail.com>
  • Loading branch information
cnvergence committed Jul 25, 2024
1 parent 25ea8b2 commit bab6210
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions internal/provider/kubernetes/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,9 @@ func (r *gatewayAPIReconciler) removeFinalizer(ctx context.Context, obj client.O
}
return nil
case *egv1a1.EnvoyProxy:
if slice.ContainsString(objType.Finalizers, gatewayClassFinalizer) {
if slice.ContainsString(objType.Finalizers, envoyProxyFinalizer) {
base := client.MergeFrom(objType.DeepCopy())
objType.Finalizers = slice.RemoveString(objType.Finalizers, gatewayClassFinalizer)
objType.Finalizers = slice.RemoveString(objType.Finalizers, envoyProxyFinalizer)
if err := r.client.Patch(ctx, objType, base); err != nil {
return fmt.Errorf("failed to add finalizer to Envoy Proxy %s: %w", objType.Name, err)

Check warning on line 1038 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L1038

Added line #L1038 was not covered by tests
}
Expand All @@ -1057,9 +1057,9 @@ func (r *gatewayAPIReconciler) addFinalizer(ctx context.Context, obj client.Obje
}
return nil
case *egv1a1.EnvoyProxy:
if !slice.ContainsString(objType.Finalizers, gatewayClassFinalizer) {
if !slice.ContainsString(objType.Finalizers, envoyProxyFinalizer) {
base := client.MergeFrom(objType.DeepCopy())
objType.Finalizers = append(objType.Finalizers, gatewayClassFinalizer)
objType.Finalizers = append(objType.Finalizers, envoyProxyFinalizer)
if err := r.client.Patch(ctx, objType, base); err != nil {
return fmt.Errorf("failed to add finalizer to Envoy Proxy %s: %w", objType.Name, err)

Check warning on line 1064 in internal/provider/kubernetes/controller.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/kubernetes/controller.go#L1064

Added line #L1064 was not covered by tests
}
Expand Down
10 changes: 5 additions & 5 deletions internal/provider/kubernetes/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestAddEnvoyProxyFinalizer(t *testing.T) {
Name: "test",
},
},
expect: []string{gatewayClassFinalizer},
expect: []string{envoyProxyFinalizer},
},
{
name: "envoyproxy with a different finalizer",
Expand All @@ -109,17 +109,17 @@ func TestAddEnvoyProxyFinalizer(t *testing.T) {
Finalizers: []string{"fooFinalizer"},
},
},
expect: []string{"fooFinalizer", gatewayClassFinalizer},
expect: []string{"fooFinalizer", envoyProxyFinalizer},
},
{
name: "envoyproxy with existing gatewayclass finalizer",
ep: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "test-ep",
Finalizers: []string{gatewayClassFinalizer},
Finalizers: []string{envoyProxyFinalizer},
},
},
expect: []string{gatewayClassFinalizer},
expect: []string{envoyProxyFinalizer},
},
}
// Create the reconciler.
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestRemoveEnvoyProxyFinalizer(t *testing.T) {
ep: &egv1a1.EnvoyProxy{
ObjectMeta: metav1.ObjectMeta{
Name: "test-ep",
Finalizers: []string{gatewayClassFinalizer},
Finalizers: []string{envoyProxyFinalizer},
},
},
expect: nil,
Expand Down
1 change: 1 addition & 0 deletions internal/provider/kubernetes/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

const (
gatewayClassFinalizer = gwapiv1.GatewayClassFinalizerGatewaysExist
envoyProxyFinalizer = "gatewayclass-exists-finalizer.gateway.envoyproxy.github.com"
)

type ObjectKindNamespacedName struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func testGatewayClassWithParamRef(ctx context.Context, t *testing.T, provider *P
// Ensure the envoyproxy has not been finalized.
require.Eventually(t, func() bool {
err := cli.Get(ctx, types.NamespacedName{Name: ep.Name, Namespace: testNs}, ep)
return err == nil && !slices.Contains(ep.Finalizers, gatewayClassFinalizer)
return err == nil && !slices.Contains(ep.Finalizers, envoyProxyFinalizer)
}, defaultWait, defaultTick)

// Ensure the gateway class has not been finalized.
Expand Down Expand Up @@ -343,15 +343,15 @@ func testGatewayClassWithParamRef(ctx context.Context, t *testing.T, provider *P
// Ensure the envoyproxy has been finalized.
require.Eventually(t, func() bool {
err := cli.Get(ctx, types.NamespacedName{Name: ep.Name, Namespace: testNs}, ep)
return err == nil && slices.Contains(ep.Finalizers, gatewayClassFinalizer)
return err == nil && slices.Contains(ep.Finalizers, envoyProxyFinalizer)
}, defaultWait, defaultTick)

//Ensure that envoyproxy finalizer will be removed when GatewayClass stops referencing it
gc.Spec.ParametersRef = nil
require.NoError(t, cli.Update(ctx, gc))
require.Eventually(t, func() bool {
err := cli.Get(ctx, types.NamespacedName{Name: ep.Name, Namespace: testNs}, ep)
return err == nil && !slices.Contains(ep.Finalizers, gatewayClassFinalizer)
return err == nil && !slices.Contains(ep.Finalizers, envoyProxyFinalizer)
}, defaultWait, defaultTick)
}

Expand Down

0 comments on commit bab6210

Please sign in to comment.