Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added empty FinalizeKind definition to prevent delete sources from hanging #3113

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions control-plane/pkg/reconciler/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func GetLabels(name string) map[string]string {
}
}

// Need to have an empty definition here to ensure that we can delete older sources which had a finalizer
func (r Reconciler) FinalizeKind(ctx context.Context, ks *sources.KafkaSource) reconciler.Event {
return nil
}

func (r Reconciler) reconcileConsumerGroup(ctx context.Context, ks *sources.KafkaSource) (*internalscg.ConsumerGroup, error) {
var deliverySpec *internalscg.DeliverySpec
deliveryOrder := DefaultDeliveryOrder
Expand Down
147 changes: 147 additions & 0 deletions control-plane/pkg/reconciler/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ import (
kedaclient "knative.dev/eventing-kafka-broker/third_party/pkg/client/injection/client/fake"
)

const (
finalizerName = "kafkasources.sources.knative.dev"
)

var (
finalizerUpdatedEvent = Eventf(
corev1.EventTypeNormal,
"FinalizerUpdate",
fmt.Sprintf(`Updated %q finalizers`, SourceName),
)
)

func TestGetLabels(t *testing.T) {

testLabels := GetLabels("testSourceName")
Expand Down Expand Up @@ -136,6 +148,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal, offset earliest",
Expand Down Expand Up @@ -183,6 +201,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal, offset latest",
Expand Down Expand Up @@ -230,6 +254,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal with delivery spec",
Expand Down Expand Up @@ -282,6 +312,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal, key type label",
Expand Down Expand Up @@ -330,6 +366,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal with SASL with type",
Expand Down Expand Up @@ -459,6 +501,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal with SASL without type",
Expand Down Expand Up @@ -572,6 +620,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - ce overrides",
Expand Down Expand Up @@ -627,6 +681,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - with autoscaling annotations",
Expand Down Expand Up @@ -675,6 +735,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg with sink update",
Expand Down Expand Up @@ -758,6 +824,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg with update",
Expand Down Expand Up @@ -817,6 +889,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg with annotations update",
Expand Down Expand Up @@ -877,6 +955,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg with update but not ready",
Expand Down Expand Up @@ -935,6 +1019,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg without update",
Expand Down Expand Up @@ -982,6 +1072,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg without update but not ready",
Expand Down Expand Up @@ -1027,6 +1123,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg but failed",
Expand Down Expand Up @@ -1073,6 +1175,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - existing cg with replicas set in status",
Expand Down Expand Up @@ -1121,6 +1229,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - update cg replicas",
Expand Down Expand Up @@ -1203,6 +1317,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - ignore source replicas when KEDA is enabled",
Expand Down Expand Up @@ -1254,6 +1374,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - with unordered consumer verticle",
Expand Down Expand Up @@ -1301,6 +1427,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
{
Name: "Reconciled normal - with ordered consumer verticle",
Expand Down Expand Up @@ -1348,6 +1480,12 @@ func TestReconcileKind(t *testing.T) {
),
},
},
WantPatches: []clientgotesting.PatchActionImpl{
patchFinalizers(),
},
WantEvents: []string{
finalizerUpdatedEvent,
},
},
}

Expand Down Expand Up @@ -1459,3 +1597,12 @@ func SourceNetSaslTls(withType bool) KRShapedOption {
}
}
}

func patchFinalizers() clientgotesting.PatchActionImpl {
action := clientgotesting.PatchActionImpl{}
action.Name = SourceName
action.Namespace = SourceNamespace
patch := `{"metadata":{"finalizers":["` + finalizerName + `"],"resourceVersion":""}}`
action.Patch = []byte(patch)
return action
}