Skip to content

Commit

Permalink
Delete NCP created resource in cleanup
Browse files Browse the repository at this point in the history
In this change, we delete NCP created resource (share/sharedResource/certificate/lbAppProfile/lbPersistenProfile) in the cleanup process.

Signed-off-by: Yun-Tang Hsu <[email protected]>
  • Loading branch information
Yun-Tang Hsu authored and dantingl committed Sep 3, 2024
1 parent d6d2416 commit 58f9f3a
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 26 deletions.
14 changes: 11 additions & 3 deletions pkg/nsx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import (
mpsearch "github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/search"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/trust_management"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt-mp/nsx/trust_management/principal_identities"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/domains/security_policies"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/shares"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/infra/sites/enforcement_points"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra"
project_infra "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra/realized_state"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/transit_gateways"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs"
Expand Down Expand Up @@ -76,7 +78,7 @@ type Client struct {
ProjectInfraClient projects.InfraClient
VPCClient projects.VpcsClient
VPCConnectivityProfilesClient projects.VpcConnectivityProfilesClient
IPBlockClient infra.IpBlocksClient
IPBlockClient project_infra.IpBlocksClient
StaticRouteClient vpcs.StaticRoutesClient
NATRuleClient nat.NatRulesClient
VpcGroupClient vpcs.GroupsClient
Expand All @@ -91,6 +93,12 @@ type Client struct {
ProjectClient orgs.ProjectsClient
TransitGatewayClient projects.TransitGatewaysClient
TransitGatewayAttachmentClient transit_gateways.AttachmentsClient
CertificateClient infra.CertificatesClient
ShareClient infra.SharesClient
SharedResourceClient shares.ResourcesClient
LbAppProfileClient infra.LbAppProfilesClient
LbPersistenceProfilesClient infra.LbPersistenceProfilesClient
LbMonitorProfilesClient infra.LbMonitorProfilesClient

NSXChecker NSXHealthChecker
NSXVerChecker NSXVersionChecker
Expand Down Expand Up @@ -161,7 +169,7 @@ func GetClient(cf *config.NSXOperatorConfig) *Client {
projectClient := orgs.NewProjectsClient(restConnector(cluster))
vpcClient := projects.NewVpcsClient(restConnector(cluster))
vpcConnectivityProfilesClient := projects.NewVpcConnectivityProfilesClient(restConnector(cluster))
ipBlockClient := infra.NewIpBlocksClient(restConnector(cluster))
ipBlockClient := project_infra.NewIpBlocksClient(restConnector(cluster))
staticRouteClient := vpcs.NewStaticRoutesClient(restConnector(cluster))
natRulesClient := nat.NewNatRulesClient(restConnector(cluster))
vpcGroupClient := vpcs.NewGroupsClient(restConnector(cluster))
Expand Down
54 changes: 31 additions & 23 deletions pkg/nsx/services/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,37 @@ var (
)

var (
ResourceType = "resource_type"
ResourceTypeInfra = "Infra"
ResourceTypeDomain = "Domain"
ResourceTypeSecurityPolicy = "SecurityPolicy"
ResourceTypeNetworkPolicy = "NetworkPolicy"
ResourceTypeGroup = "Group"
ResourceTypeRule = "Rule"
ResourceTypeIPBlock = "IpAddressBlock"
ResourceTypeOrgRoot = "OrgRoot"
ResourceTypeOrg = "Org"
ResourceTypeProject = "Project"
ResourceTypeVpc = "Vpc"
ResourceTypeSubnetPort = "VpcSubnetPort"
ResourceTypeVirtualMachine = "VirtualMachine"
ResourceTypeLBService = "LBService"
ResourceTypeShare = "Share"
ResourceTypeSharedResource = "SharedResource"
ResourceTypeChildSharedResource = "ChildSharedResource"
ResourceTypeChildShare = "ChildShare"
ResourceTypeChildRule = "ChildRule"
ResourceTypeChildGroup = "ChildGroup"
ResourceTypeChildSecurityPolicy = "ChildSecurityPolicy"
ResourceTypeChildResourceReference = "ChildResourceReference"
ResourceType = "resource_type"
ResourceTypeInfra = "Infra"
ResourceTypeDomain = "Domain"
ResourceTypeSecurityPolicy = "SecurityPolicy"
ResourceTypeNetworkPolicy = "NetworkPolicy"
ResourceTypeGroup = "Group"
ResourceTypeRule = "Rule"
ResourceTypeIPBlock = "IpAddressBlock"
ResourceTypeOrgRoot = "OrgRoot"
ResourceTypeOrg = "Org"
ResourceTypeProject = "Project"
ResourceTypeVpc = "Vpc"
ResourceTypeSubnetPort = "VpcSubnetPort"
ResourceTypeVirtualMachine = "VirtualMachine"
ResourceTypeLBService = "LBService"
ResourceTypeShare = "Share"
ResourceTypeSharedResource = "SharedResource"
ResourceTypeChildSharedResource = "ChildSharedResource"
ResourceTypeChildShare = "ChildShare"
ResourceTypeChildRule = "ChildRule"
ResourceTypeChildGroup = "ChildGroup"
ResourceTypeChildSecurityPolicy = "ChildSecurityPolicy"
ResourceTypeChildResourceReference = "ChildResourceReference"
ResourceTypeTlsCertificate = "TlsCertificate"
ResourceTypeLBHttpProfile = "LBHttpProfile"
ResourceTypeLBFastTcpProfile = "LBFastTcpProfile"
ResourceTypeLBFastUdpProfile = "LBFastUdpProfile"
ResourceTypeLBCookiePersistenceProfile = "LBCookiePersistenceProfile"
ResourceTypeLBSourceIpPersistenceProfile = "LBSourceIpPersistenceProfile"
ResourceTypeLBHttpMonitorProfile = "LBHttpMonitorProfile"
ResourceTypeLBTcpMonitorProfile = "LBTcpMonitorProfile"

// ResourceTypeClusterControlPlane is used by NSXServiceAccountController
ResourceTypeClusterControlPlane = "clustercontrolplane"
Expand Down
9 changes: 9 additions & 0 deletions pkg/nsx/services/vpc/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ func (vs *VPCStore) GetByKey(key string) *model.Vpc {
return nil
}

// ResourceStore is a store to query nsx resource
type ResourceStore struct {
common.ResourceStore
}

func (r *ResourceStore) Apply(i interface{}) error {
return nil
}

func (is *IPBlockStore) GetByIndex(index string, value string) *model.IpAddressBlock {
indexResults, err := is.ResourceStore.Indexer.ByIndex(index, value)
if err != nil || len(indexResults) == 0 {
Expand Down
Loading

0 comments on commit 58f9f3a

Please sign in to comment.