common

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2023 License: Apache-2.0 Imports: 21 Imported by: 26

Documentation

Index

Constants

View Source
const (
	HashLength                      int    = 8
	MaxTagLength                    int    = 256
	MaxIdLength                     int    = 255
	MaxNameLength                   int    = 255
	MaxSubnetNameLength             int    = 80
	TagScopeNCPCluster              string = "ncp/cluster"
	TagScopeNCPProjectUID           string = "ncp/project_uid"
	TagScopeNCPVIFProjectUID        string = "ncp/vif_project_uid"
	TagScopeNCPPod                  string = "ncp/pod"
	TagScopeNCPVNETInterface        string = "ncp/vnet_interface"
	TagScopeVersion                 string = "nsx-op/version"
	TagScopeCluster                 string = "nsx-op/cluster"
	TagScopeNamespace               string = "nsx-op/namespace"
	TagScopeNamespaceUID            string = "nsx-op/namespace_uid"
	TagScopeSecurityPolicyCRName    string = "nsx-op/security_policy_cr_name"
	TagScopeSecurityPolicyCRUID     string = "nsx-op/security_policy_cr_uid"
	TagScopeStaticRouteCRName       string = "nsx-op/static_route_cr_name"
	TagScopeStaticRouteCRUID        string = "nsx-op/static_route_cr_uid"
	TagScopeRuleID                  string = "nsx-op/rule_id"
	TagScopeGoupID                  string = "nsx-op/group_id"
	TagScopeGroupType               string = "nsx-op/group_type"
	TagScopeSelectorHash            string = "nsx-op/selector_hash"
	TagScopeNSXServiceAccountCRName string = "nsx-op/nsx_service_account_name"
	TagScopeNSXServiceAccountCRUID  string = "nsx-op/nsx_service_account_uid"
	TagScopeNSXProjectID            string = "nsx-op/nsx_project_id"
	TagScopeProjectGroupShared      string = "nsx-op/is_nsx_project_shared"
	TagScopeVPCCRName               string = "nsx-op/vpc_cr_name"
	TagScopeVPCCRUID                string = "nsx-op/vpc_cr_uid"
	TagScopeSubnetPortCRName        string = "nsx-op/subnetport_cr_name"
	TagScopeSubnetPortCRUID         string = "nsx-op/subnetport_cr_uid"
	TagScopeIPPoolCRName            string = "nsx-op/ippool_cr_name"
	TagScopeIPPoolCRUID             string = "nsx-op/ippool_cr_uid"
	TagScopeIPPoolCRType            string = "nsx-op/ippool_cr_type"
	TagScopeIPSubnetName            string = "nsx-op/ipsubnet_cr_name"
	TagScopeVMNamespaceUID          string = "nsx-op/vm_namespace_uid"
	TagScopeVMNamespace             string = "nsx-op/vm_namespace"
	LabelDefaultSubnetSet           string = "nsxoperator.vmware.com/default-subnetset-for"
	LabelDefaultVMSubnetSet         string = "VirtualMachine"
	LabelDefaultPodSubnetSet        string = "Pod"
	TagScopeSubnetCRType            string = "nsx-op/subnet_cr_type"
	TagScopeSubnetCRUID             string = "nsx-op/subnet_cr_uid"
	TagScopeSubnetCRName            string = "nsx-op/subnet_cr_name"
	TagScopeSubnetSetCRName         string = "nsx-op/subnetset_cr_name"
	TagScopeSubnetSetCRUID          string = "nsx-op/subnetset_cr_uid"
	TagValueGroupScope              string = "scope"
	TagValueGroupSrc                string = "source"
	TagValueGroupDst                string = "destination"
	TagValueGroupAvi                string = "avi"
	AnnotationVPCNetworkConfig      string = "nsx.vmware.com/vpc_network_config"
	AnnotationVPCName               string = "nsx.vmware.com/vpc_name"
	AnnotationPodMAC                string = "nsx.vmware.com/mac"
	AnnotationPodAttachment         string = "nsx.vmware.com/attachment"
	DefaultNetworkConfigName        string = "default"
	TagScopePodName                 string = "nsx-op/pod_name"
	TagScopePodUID                  string = "nsx-op/pod_uid"
	ValueMajorVersion               string = "1"
	ValueMinorVersion               string = "0"
	ValuePatchVersion               string = "0"

	GCInterval          = 60 * time.Second
	RealizeTimeout      = 2 * time.Minute
	RealizeMaxRetries   = 3
	IPPoolFinalizerName = "ippool.nsx.vmware.com/finalizer"
	DefaultSNATID       = "DEFAULT"
	AVISubnetLBID       = "_AVI_SUBNET--LB"
	IPPoolTypePublic    = "Public"
	IPPoolTypePrivate   = "Private"

	SecurityPolicyFinalizerName    = "securitypolicy.nsx.vmware.com/finalizer"
	StaticRouteFinalizerName       = "staticroute.nsx.vmware.com/finalizer"
	NSXServiceAccountFinalizerName = "nsxserviceaccount.nsx.vmware.com/finalizer"
	SubnetFinalizerName            = "subnet.nsx.vmware.com/finalizer"
	SubnetSetFinalizerName         = "subnetset.nsx.vmware.com/finalizer"
	SubnetPortFinalizerName        = "subnetport.nsx.vmware.com/finalizer"
	VPCFinalizerName               = "vpc.nsx.vmware.com/finalizer"
	PodFinalizerName               = "pod.nsx.vmware.com/finalizer"

	IndexKeySubnetID            = "IndexKeySubnetID"
	IndexKeyPathPath            = "Path"
	IndexKeyNodeName            = "IndexKeyNodeName"
	GCValidationInterval uint16 = 720
)
View Source
const (
	PageSize int64 = 1000
)

Variables

View Source
var (
	ResourceType                    = "resource_type"
	ResourceTypeSecurityPolicy      = "SecurityPolicy"
	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"

	// ResourceTypeClusterControlPlane is used by NSXServiceAccountController
	ResourceTypeClusterControlPlane = "clustercontrolplane"
	// ResourceTypePrincipalIdentity is used by NSXServiceAccountController, and it is MP resource type.
	ResourceTypePrincipalIdentity = "principalidentity"
	ResourceTypeSubnet            = "VpcSubnet"
	ResourceTypeIPPool            = "IpAddressPool"
	ResourceTypeIPPoolBlockSubnet = "IpAddressPoolBlockSubnet"
	ResourceTypeNode              = "HostTransportNode"
)
View Source
var (
	String = pointy.String // address of string
	Int64  = pointy.Int64  // address of int64
	Bool   = pointy.Bool   // address of bool
)

Functions

func CompareResource

func CompareResource(existing Comparable, expected Comparable) (isChanged bool)

func CompareResources

func CompareResources(existing []Comparable, expected []Comparable) (changed []Comparable, stale []Comparable)

func ConvertMPTagsToTags

func ConvertMPTagsToTags(mpTags []mpmodel.Tag) []model.Tag

func ConvertTagsToMPTags

func ConvertTagsToMPTags(tags []model.Tag) []mpmodel.Tag

func DecrementPageSize

func DecrementPageSize(pageSize *int64)

func NewConverter

func NewConverter() *bindings.TypeConverter

func QueryTagCondition

func QueryTagCondition(resourceType, cluster string) string

func TransError

func TransError(err error) error

Types

type Comparable

type Comparable interface {
	Key() string
	Value() data.DataValue
}

type Filter added in v0.0.3

type Filter func(interface{}) *data.StructValue

type ResourceStore

type ResourceStore struct {
	cache.Indexer        // the ultimate place to store the resource
	bindings.BindingType // used by converter to convert the resource
}

ResourceStore is the store for resource, embed it to subclass

func (*ResourceStore) GetByIndex

func (resourceStore *ResourceStore) GetByIndex(index string, value string) []interface{}

GetByIndex is the method to get the resource list by index, it is used by the subclass to convert it to the specific type.

func (*ResourceStore) GetByKey

func (resourceStore *ResourceStore) GetByKey(key string) interface{}

GetByKey is the method to get the resource by key, it is used by the subclass to convert it to the specific type.

func (*ResourceStore) IsPolicyAPI

func (resourceStore *ResourceStore) IsPolicyAPI() bool

func (*ResourceStore) ListIndexFuncValues

func (resourceStore *ResourceStore) ListIndexFuncValues(key string) sets.String

func (*ResourceStore) TransResourceToStore

func (resourceStore *ResourceStore) TransResourceToStore(entity *data.StructValue) error

TransResourceToStore is the method to transform the resource of type data.StructValue subclass could reuse it, distinguish the resource by bindingType and resourceAssertion

type Service

type Service struct {
	Client    client.Client
	NSXClient *nsx.Client
	NSXConfig *config.NSXOperatorConfig
}

func (*Service) InitializeCommonStore

func (service *Service) InitializeCommonStore(wg *sync.WaitGroup, fatalErrors chan error, org string, project string, resourceTypeValue string, tags []model.Tag, store Store)

InitializeCommonStore is the common method used by InitializeResourceStore and InitializeVPCResourceStore

func (*Service) InitializeResourceStore

func (service *Service) InitializeResourceStore(wg *sync.WaitGroup, fatalErrors chan error, resourceTypeValue string, tags []model.Tag, store Store)

InitializeResourceStore is the method to query all the various resources from nsx-t side and save them to the store, we could use it to cache all the resources when process starts.

func (*Service) InitializeVPCResourceStore

func (service *Service) InitializeVPCResourceStore(wg *sync.WaitGroup, fatalErrors chan error, org string, project string, resourceTypeValue string, tags []model.Tag, store Store)

InitializeVPCResourceStore is the method to query all the various VPC resources from nsx-t side and save them to the store, we could use it to cache all the resources when process starts.

func (*Service) PopulateResourcetoStore added in v0.0.3

func (service *Service) PopulateResourcetoStore(wg *sync.WaitGroup, fatalErrors chan error, resourceTypeValue string, queryParam string, store Store, filter Filter)

PopulateResourcetoStore is the method used by populating resources created not by nsx-operator

func (*Service) SearchResource added in v0.0.3

func (service *Service) SearchResource(resourceTypeValue string, queryParam string, store Store, filter Filter) (uint64, error)

type Store

type Store interface {
	// TransResourceToStore is the method to transform the resource of type data.StructValue
	// to specific nsx-t side resource and then add it to the store.
	TransResourceToStore(obj *data.StructValue) error
	// ListIndexFuncValues is the method to list all the values of the index
	ListIndexFuncValues(key string) sets.String
	// Apply is the method to create, update and delete the resource to the store based
	// on its tag MarkedForDelete.
	Apply(obj interface{}) error
	// IsPolicyAPI returns if it is Policy resource
	IsPolicyAPI() bool
}

Store is the interface for store, it should be implemented by subclass

type VPCResourceInfo

type VPCResourceInfo struct {
	OrgID     string
	ProjectID string
	VPCID     string
	// 1. For the subnetport with path /orgs/o1/projects/p1/vpcs/v1/subnets/s1/ports/port1,
	//    ID=port1, ParentID=s1;
	// 2. For the subnet with path /orgs/o1/projects/p1/vpcs/v1/subnets/s1,
	//    ID=s1, ParentID=v1 (ParentID==VPCID).
	ID       string
	ParentID string
}

func ParseVPCResourcePath

func ParseVPCResourcePath(nsxResourcePath string) (VPCResourceInfo, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL