@@ -14,53 +14,6 @@ import (
1414	"k8s.io/client-go/tools/cache" 
1515)
1616
17- type  InventoryType  string 
18- 
19- const  (
20- 	// Inventory object types 
21- 	ContainerCluster              InventoryType  =  "ContainerCluster" 
22- 	ContainerClusterNode          InventoryType  =  "ContainerClusterNode" 
23- 	ContainerProject              InventoryType  =  "ContainerProject" 
24- 	ContainerApplication          InventoryType  =  "ContainerApplication" 
25- 	ContainerApplicationInstance  InventoryType  =  "ContainerApplicationInstance" 
26- 	ContainerNetworkPolicy        InventoryType  =  "ContainerNetworkPolicy" 
27- 	ContainerIngressPolicy        InventoryType  =  "ContainerIngressPolicy" 
28- 
29- 	// Inventory cluster type 
30- 	InventoryClusterTypeWCP  =  "WCP" 
31- 
32- 	InventoryClusterCNIType  =  "NSX-Operator" 
33- 
34- 	// Inventory network status 
35- 	NetworkStatusHealthy    =  "HEALTHY" 
36- 	NetworkStatusUnhealthy  =  "UNHEALTHY" 
37- 
38- 	// Inventory infra 
39- 	InventoryInfraTypeVsphere  =  "vSphere" 
40- 
41- 	InventoryMaxDisTags  =  20 
42- 	InventoryK8sPrefix   =  "dis:k8s:" 
43- 	MaxTagLen            =  256 
44- 	MaxResourceTypeLen   =  128 
45- )
46- 
47- type  InventoryKey  struct  {
48- 	InventoryType  InventoryType 
49- 	ExternalId     string 
50- 	Key            string 
51- }
52- 
53- const  (
54- 	operationCreate  =  "CREATE" 
55- 	operationUpdate  =  "UPDATE" 
56- 	operationDelete  =  "DELETE" 
57- 	operationNone    =  "NONE" 
58- 
59- 	InventoryStatusUp       =  "UP" 
60- 	InventoryStatusDown     =  "DOWN" 
61- 	InventoryStatusUnknown  =  "UNKNOWN" 
62- )
63- 
6417var  (
6518	log          =  & logger .Log 
6619	emptyKeySet  =  sets .New [InventoryKey ]()
@@ -223,34 +176,34 @@ func (s *InventoryService) SyncInventoryObject(bufferedKeys sets.Set[InventoryKe
223176	return  retryKeys , err 
224177}
225178
179+ func  (s  * InventoryService ) prepareDelete (resourceType  InventoryType , externalId  string , inventoryObject  interface {}) {
180+ 	deletedInfo  :=  map [string ]interface {}{
181+ 		"resource_type" : resourceType ,
182+ 		"external_id" :   externalId ,
183+ 	}
184+ 	s .requestBuffer  =  append (s .requestBuffer , containerinventory.ContainerInventoryObject {
185+ 		ContainerObject :  deletedInfo ,
186+ 		ObjectUpdateType : operationDelete ,
187+ 	})
188+ 	switch  resourceType  {
189+ 	case  ContainerApplicationInstance :
190+ 		s .pendingDelete [externalId ] =  inventoryObject .(* containerinventory.ContainerApplicationInstance )
191+ 	}
192+ }
193+ 
226194func  (s  * InventoryService ) DeleteResource (externalId  string , resourceType  InventoryType ) error  {
227195	log .V (1 ).Info ("Delete inventory resource" , "resource_type" , resourceType , "external_id" , externalId )
228- 	var  inventoryObject  interface {}
229- 	exists  :=  false 
230196	switch  resourceType  {
231- 
232197	case  ContainerApplicationInstance :
233- 		inventoryObject  =  s .ApplicationInstanceStore .GetByKey (externalId )
234- 		if  inventoryObject  ! =nil  {
235- 			exists   =   true 
198+ 		inventoryObject  : =s .ApplicationInstanceStore .GetByKey (externalId )
199+ 		if  inventoryObject  = =nil  {
200+ 			return   nil 
236201		}
202+ 		s .prepareDelete (resourceType , externalId , inventoryObject )
203+ 		return  s .DeleteContainerApplicationInstance (externalId , inventoryObject .(* containerinventory.ContainerApplicationInstance ))
237204	default :
238205		return  fmt .Errorf ("unknown resource_type : %v for external_id %s" , resourceType , externalId )
239206	}
240- 
241- 	if  exists  {
242- 		deletedInfo  :=  make (map [string ]interface {})
243- 		deletedInfo ["resource_type" ] =  resourceType 
244- 		deletedInfo ["external_id" ] =  externalId 
245- 		s .requestBuffer  =  append (s .requestBuffer , containerinventory.ContainerInventoryObject {ContainerObject : deletedInfo ,
246- 			ObjectUpdateType : operationDelete })
247- 		s .pendingDelete [externalId ] =  inventoryObject .(* containerinventory.ContainerApplicationInstance )
248- 
249- 		if  resourceType  ==  ContainerApplicationInstance  {
250- 			return  s .DeleteContainerApplicationInstance (externalId , inventoryObject .(* containerinventory.ContainerApplicationInstance ))
251- 		}
252- 	}
253- 	return  nil 
254207}
255208
256209func  (s  * InventoryService ) sendNSXRequestAndUpdateInventoryStore () error  {
@@ -262,7 +215,9 @@ func (s *InventoryService) sendNSXRequestAndUpdateInventoryStore() error {
262215			containerinventory.ContainerInventoryData {ContainerInventoryObjects : s .requestBuffer })
263216
264217		// Update NSX Inventory store when the request succeeds. 
265- 		log .V (1 ).Info ("NSX request response" , "response status code" , resp .StatusCode )
218+ 		if  resp  !=  nil  {
219+ 			log .V (1 ).Info ("NSX request response" , "response status code" , resp .StatusCode )
220+ 		}
266221		if  err  ==  nil  {
267222			err  =  s .updateInventoryStore ()
268223		}
0 commit comments