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 <hsuy@vmware.com>
  • Loading branch information
yuntanghsu committed Jul 29, 2024
1 parent b7bf875 commit 0a5e09d
Show file tree
Hide file tree
Showing 5 changed files with 313 additions and 41 deletions.
41 changes: 24 additions & 17 deletions pkg/nsx/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ 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"
projects "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects"
infra "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/infra"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects"
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/vpcs"
nat "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/nat"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/nat"
vpc_sp "github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/security_policies"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/subnets"
"github.com/vmware/vsphere-automation-sdk-go/services/nsxt/orgs/projects/vpcs/subnets/ip_pools"
Expand Down Expand Up @@ -71,19 +73,24 @@ type Client struct {
VPCSecurityClient vpcs.SecurityPoliciesClient
VPCRuleClient vpc_sp.RulesClient

OrgRootClient nsx_policy.OrgRootClient
ProjectInfraClient projects.InfraClient
VPCClient projects.VpcsClient
IPBlockClient infra.IpBlocksClient
StaticRouteClient vpcs.StaticRoutesClient
NATRuleClient nat.NatRulesClient
VpcGroupClient vpcs.GroupsClient
PortClient subnets.PortsClient
PortStateClient ports.StateClient
IPPoolClient subnets.IpPoolsClient
IPAllocationClient ip_pools.IpAllocationsClient
SubnetsClient vpcs.SubnetsClient
RealizedStateClient realized_state.RealizedEntitiesClient
OrgRootClient nsx_policy.OrgRootClient
ProjectInfraClient projects.InfraClient
VPCClient projects.VpcsClient
IPBlockClient project_infra.IpBlocksClient
CertificateClient infra.CertificatesClient
ShareClient infra.SharesClient
SharedResourceClient shares.ResourcesClient
LbAppProfileClient infra.LbAppProfilesClient
LbPersistenceProfilesClient infra.LbPersistenceProfilesClient
StaticRouteClient vpcs.StaticRoutesClient
NATRuleClient nat.NatRulesClient
VpcGroupClient vpcs.GroupsClient
PortClient subnets.PortsClient
PortStateClient ports.StateClient
IPPoolClient subnets.IpPoolsClient
IPAllocationClient ip_pools.IpAllocationsClient
SubnetsClient vpcs.SubnetsClient
RealizedStateClient realized_state.RealizedEntitiesClient

NSXChecker NSXHealthChecker
NSXVerChecker NSXVersionChecker
Expand Down Expand Up @@ -152,7 +159,7 @@ func GetClient(cf *config.NSXOperatorConfig) *Client {
orgRootClient := nsx_policy.NewOrgRootClient(restConnector(cluster))
projectInfraClient := projects.NewInfraClient(restConnector(cluster))
vpcClient := projects.NewVpcsClient(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
52 changes: 30 additions & 22 deletions pkg/nsx/services/common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
TagScopeNCPVIFProjectUID string = "ncp/vif_project_uid"
TagScopeNCPPod string = "ncp/pod"
TagScopeNCPVNETInterface string = "ncp/vnet_interface"
TagScopeNCPDefaultLBCert string = "ncp/lb_default_cert"
TagScopeNCPSecret string = "ncp/secret"
TagScopeVersion string = "nsx-op/version"
TagScopeCluster string = "nsx-op/cluster"
TagScopeNamespace string = "nsx-op/namespace"
Expand Down Expand Up @@ -130,28 +132,34 @@ 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"
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"
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"

// 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 @@ -137,6 +137,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 0a5e09d

Please sign in to comment.