@@ -29,6 +29,7 @@ import (
2929 clientset "k8s.io/client-go/kubernetes"
3030 "k8s.io/client-go/kubernetes/fake"
3131 k8stesting "k8s.io/client-go/testing"
32+ "k8s.io/client-go/tools/cache"
3233
3334 crdv1beta1 "antrea.io/antrea/v2/pkg/apis/crd/v1beta1"
3435 "antrea.io/antrea/v2/pkg/client/clientset/versioned"
@@ -197,3 +198,34 @@ func newCRDClientset() *fakeversioned.Clientset {
197198
198199 return client
199200}
201+
202+ func TestDeleteTraceflow_Tombstone (t * testing.T ) {
203+ tfc := newController ()
204+
205+ tf := & crdv1beta1.Traceflow {
206+ ObjectMeta : metav1.ObjectMeta {Name : "tf1" , UID : "uid1" },
207+ Spec : crdv1beta1.TraceflowSpec {
208+ Source : crdv1beta1.Source {Namespace : "ns1" , Pod : "pod1" },
209+ Destination : crdv1beta1.Destination {Namespace : "ns2" , Pod : "pod2" },
210+ },
211+ Status : crdv1beta1.TraceflowStatus {
212+ DataplaneTag : 5 ,
213+ },
214+ }
215+
216+ // Simulate the tag being tracked as running.
217+ tfc .runningTraceflowsMutex .Lock ()
218+ tfc .runningTraceflows [uint8 (tf .Status .DataplaneTag )] = tf .Name
219+ tfc .runningTraceflowsMutex .Unlock ()
220+
221+ // Deliver the delete as a tombstone, as the informer does after a watch reconnect.
222+ tfc .deleteTraceflow (cache.DeletedFinalStateUnknown {
223+ Key : tf .Name ,
224+ Obj : tf ,
225+ })
226+
227+ tfc .runningTraceflowsMutex .Lock ()
228+ _ , exists := tfc .runningTraceflows [uint8 (tf .Status .DataplaneTag )]
229+ tfc .runningTraceflowsMutex .Unlock ()
230+ assert .False (t , exists , "expected tag to be deallocated after tombstone delete" )
231+ }
0 commit comments