Skip to content

Commit

Permalink
fix: ensure delete events are sent for all replicasets (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikenorgate authored Nov 21, 2024
1 parent 5c2ff65 commit 0ef0a69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/services/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ func getDefaultInformers(f informers.SharedInformerFactory, castwareNamespace st
return false
}

return replicaSet.Namespace == castwareNamespace ||
return e == castai.EventDelete || replicaSet.Namespace == castwareNamespace ||
(replicaSet.Spec.Replicas != nil && *replicaSet.Spec.Replicas > 0 && replicaSet.Status.Replicas > 0)
},
},
Expand Down
15 changes: 14 additions & 1 deletion internal/services/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ func loadInitialHappyPathData(t *testing.T, scheme *runtime.Scheme) ([]sampleObj
func TestDefaultInformers_MatchFilters(t *testing.T) {
tests := map[string]struct {
obj runtime.Object
eventType castai.EventType
expectedMatch bool
}{
"keep if replicaset in castware namespace": {
Expand All @@ -1193,6 +1194,7 @@ func TestDefaultInformers_MatchFilters(t *testing.T) {
Namespace: "castware",
},
},
eventType: castai.EventAdd,
expectedMatch: true,
},
"discard if replicaset has zero replicas": {
Expand All @@ -1207,6 +1209,7 @@ func TestDefaultInformers_MatchFilters(t *testing.T) {
Replicas: 0,
},
},
eventType: castai.EventAdd,
expectedMatch: false,
},
"keep if replicaset has more than zero replicas": {
Expand All @@ -1221,6 +1224,16 @@ func TestDefaultInformers_MatchFilters(t *testing.T) {
Replicas: 1,
},
},
eventType: castai.EventAdd,
expectedMatch: true,
},
"keep if delete event": {
obj: &appsv1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{
Namespace: "test",
},
},
eventType: castai.EventDelete,
expectedMatch: true,
},
}
Expand All @@ -1233,7 +1246,7 @@ func TestDefaultInformers_MatchFilters(t *testing.T) {
defaultInformers := getDefaultInformers(f, "castware")
objInformer := defaultInformers[reflect.TypeOf(data.obj)]

match := objInformer.filters.Apply(castai.EventAdd, data.obj)
match := objInformer.filters.Apply(data.eventType, data.obj)

r.Equal(data.expectedMatch, match)
})
Expand Down

0 comments on commit 0ef0a69

Please sign in to comment.