common

package
v0.0.0-...-aba7421 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashLength                         int    = 8
	MaxTagScopeLength                  int    = 128
	MaxTagValueLength                  int    = 256
	MaxIdLength                        int    = 255
	MaxNameLength                      int    = 255
	MaxSubnetNameLength                int    = 80
	PriorityNetworkPolicyAllowRule     int    = 2010
	PriorityNetworkPolicyIsolationRule int    = 2090
	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"
	TagScopeSecurityPolicyName         string = "nsx-op/security_policy_name"
	TagScopeSecurityPolicyUID          string = "nsx-op/security_policy_uid"
	TagScopeNetworkPolicyName          string = "nsx-op/network_policy_name"
	TagScopeNetworkPolicyUID           string = "nsx-op/network_policy_uid"
	TagScopeStaticRouteCRName          string = "nsx-op/static_route_name"
	TagScopeStaticRouteCRUID           string = "nsx-op/static_route_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_name"
	TagScopeVPCCRUID                   string = "nsx-op/vpc_uid"
	TagScopeSubnetPortCRName           string = "nsx-op/subnetport_name"
	TagScopeSubnetPortCRUID            string = "nsx-op/subnetport_uid"
	TagScopeIPPoolCRName               string = "nsx-op/ippool_name"
	TagScopeIPPoolCRUID                string = "nsx-op/ippool_uid"
	TagScopeIPPoolCRType               string = "nsx-op/ippool_type"
	TagScopeIPSubnetName               string = "nsx-op/ipsubnet_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"
	LabelLbIngressIpMode               string = "tanzu.vmware.com/ingress-ip-mode"
	LabelLbIngressIpModeVipValue       string = "vip"
	LabelLbIngressIpModeProxyValue     string = "proxy"
	DefaultPodSubnetSet                string = "pod-default"
	DefaultVMSubnetSet                 string = "vm-default"
	TagScopeSubnetCRUID                string = "nsx-op/subnet_uid"
	TagScopeSubnetCRName               string = "nsx-op/subnet_name"
	TagScopeSubnetSetCRName            string = "nsx-op/subnetset_name"
	TagScopeSubnetSetCRUID             string = "nsx-op/subnetset_uid"
	TagValueGroupScope                 string = "scope"
	TagValueGroupSource                string = "source"
	TagValueGroupDestination           string = "destination"
	TagValueGroupAvi                   string = "avi"
	AnnotationVPCNetworkConfig         string = "nsx.vmware.com/vpc_network_config"
	AnnotationVPCName                  string = "nsx.vmware.com/vpc_name"
	AnnotationDefaultNetworkConfig     string = "nsx.vmware.com/default"
	AnnotationAttachmentRef            string = "nsx.vmware.com/attachment_ref"
	AnnotationPodMAC                   string = "nsx.vmware.com/mac"
	AnnotationPodAttachment            string = "nsx.vmware.com/attachment"
	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"
	NetworkPolicyFinalizerName     = "networkpolicy.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

	RuleSuffixIngressAllow  = "ingress-allow"
	RuleSuffixEgressAllow   = "egress-allow"
	RuleSuffixIngressDrop   = "ingress-isolation"
	RuleSuffixEgressDrop    = "egress-isolation"
	RuleSuffixIngressReject = "ingress-reject"
	RuleSuffixEgressReject  = "egress-reject"
	SecurityPolicyPrefix    = "sp"
	NetworkPolicyPrefix     = "np"
	TargetGroupSuffix       = "scope"
	SrcGroupSuffix          = "src"
	DstGroupSuffix          = "dst"
	IpSetGroupSuffix        = "ipset"
	SharePrefix             = "share"
)
View Source
const (
	PageSize int64 = 1000
)
View Source
const (
	TagsCountMax = 26
)

Variables

View Source
var (
	TagValueVersion                 = []string{ValueMajorVersion, ValueMinorVersion, ValuePatchVersion}
	TagValueScopeSecurityPolicyName = TagScopeSecurityPolicyCRName
	TagValueScopeSecurityPolicyUID  = TagScopeSecurityPolicyCRUID
)
View Source
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"

	// 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

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

type MockVPCServiceProvider

type MockVPCServiceProvider struct {
	mock.Mock
}

func (*MockVPCServiceProvider) GetDefaultNetworkConfig

func (m *MockVPCServiceProvider) GetDefaultNetworkConfig() (bool, *VPCNetworkConfigInfo)

func (*MockVPCServiceProvider) GetVPCNetworkConfig

func (m *MockVPCServiceProvider) GetVPCNetworkConfig(ncCRName string) (VPCNetworkConfigInfo, bool)

func (*MockVPCServiceProvider) GetVPCNetworkConfigByNamespace

func (m *MockVPCServiceProvider) GetVPCNetworkConfigByNamespace(ns string) *VPCNetworkConfigInfo

func (*MockVPCServiceProvider) ListVPCInfo

func (m *MockVPCServiceProvider) ListVPCInfo(ns string) []VPCResourceInfo

func (*MockVPCServiceProvider) RegisterNamespaceNetworkconfigBinding

func (m *MockVPCServiceProvider) RegisterNamespaceNetworkconfigBinding(ns string, ncCRName string)

func (*MockVPCServiceProvider) UnRegisterNamespaceNetworkconfigBinding

func (m *MockVPCServiceProvider) UnRegisterNamespaceNetworkconfigBinding(ns string)

func (*MockVPCServiceProvider) ValidateNetworkConfig

func (m *MockVPCServiceProvider) ValidateNetworkConfig(nc VPCNetworkConfigInfo) bool

type NodeServiceReader

type NodeServiceReader interface {
	GetNodeByName(nodeName string) []*model.HostTransportNode
}

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.Set[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

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

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.Set[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 SubnetPortServiceProvider

type SubnetPortServiceProvider interface {
	GetPortsOfSubnet(nsxSubnetID string) (ports []*model.VpcSubnetPort)
}

type SubnetServiceProvider

type SubnetServiceProvider interface {
	GetSubnetByKey(key string) (*model.VpcSubnet, error)
	GetSubnetByPath(path string) (*model.VpcSubnet, error)
	GetSubnetsByIndex(key, value string) []*model.VpcSubnet
	CreateOrUpdateSubnet(obj client.Object, vpcInfo VPCResourceInfo, tags []model.Tag) (string, error)
	GenerateSubnetNSTags(obj client.Object, nsUID string) []model.Tag
}

type VPCNetworkConfigInfo

type VPCNetworkConfigInfo struct {
	IsDefault                  bool
	Org                        string
	Name                       string
	DefaultGatewayPath         string
	EdgeClusterPath            string
	NsxtProject                string
	ExternalIPv4Blocks         []string
	PrivateIPv4CIDRs           []string
	DefaultIPv4SubnetSize      int
	DefaultPodSubnetAccessMode string
	ShortID                    string
}

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
	PrivateIpv4Blocks  []string
	ExternalIPv4Blocks []string
}

func ParseVPCResourcePath

func ParseVPCResourcePath(nsxResourcePath string) (VPCResourceInfo, error)

type VPCServiceProvider

type VPCServiceProvider interface {
	RegisterNamespaceNetworkconfigBinding(ns string, ncCRName string)
	UnRegisterNamespaceNetworkconfigBinding(ns string)
	GetVPCNetworkConfig(ncCRName string) (VPCNetworkConfigInfo, bool)
	ValidateNetworkConfig(nc VPCNetworkConfigInfo) bool
	GetVPCNetworkConfigByNamespace(ns string) *VPCNetworkConfigInfo
	GetDefaultNetworkConfig() (bool, *VPCNetworkConfigInfo)
	ListVPCInfo(ns string) []VPCResourceInfo
}

VPCServiceProvider provides to methods other controllers and services. Using interface instead vpc service instance can prevent other service calling method that should not be exposed.

Jump to

Keyboard shortcuts

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