utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FleetSystemNamespace = "fleet-system"

	NamespaceNameFormat = "fleet-member-%s"

	RoleNameFormat = "fleet-role-%s"

	RoleBindingNameFormat = "fleet-rolebinding-%s"

	PlacementFieldManagerName = "work-api-agent"

	WorkNameFormat = "work-%s"
)
View Source
const (
	// LabelFleetObj is a label key indicate the resource is created by the fleet
	LabelFleetObj      = "kubernetes.azure.com/managed-by"
	LabelFleetObjValue = "fleet"

	// LabelWorkPlacementName is used to indicate which placement created the work.
	// This label aims to enable different work objects to be managed by different placement.
	LabelWorkPlacementName = "work.fleet.azure.com/placement-name"

	// AnnotationPlacementList is used to store all the placements that select this resource.
	// This annotation aims to enable identify the placements that need to notified when a resource
	// is changed.
	AnnotationPlacementList = "work.fleet.azure.com/placement-list"
	PlacementListSep        = ";"

	// PlacementFinalizer is used to make sure that we handle the deleting of an already placed resource
	PlacementFinalizer = "work.fleet.azure.com/placement-protection"
)
View Source
const (
	// TestCaseMsg is used in the table driven test
	TestCaseMsg string = "\nTest case:  %s"
)

Variables

View Source
var (
	FleetRule = rbacv1.PolicyRule{
		Verbs:     []string{"*"},
		APIGroups: []string{fleetv1alpha1.GroupVersion.Group},
		Resources: []string{"*"},
	}
	EventRule = rbacv1.PolicyRule{
		Verbs:     []string{"get", "list", "update", "patch", "watch", "create"},
		APIGroups: []string{""},
		Resources: []string{"events"},
	}
	WorkRule = rbacv1.PolicyRule{
		Verbs:     []string{"*"},
		APIGroups: []string{workv1alpha1.GroupName},
		Resources: []string{"*"},
	}
	FleetNetworkRule = rbacv1.PolicyRule{
		Verbs:     []string{"*"},
		APIGroups: []string{"networking.fleet.azure.com"},
		Resources: []string{"*"},
	}
	// LeaseRule Leases permissions are required for leader election of hub controller manager in member cluster.
	LeaseRule = rbacv1.PolicyRule{
		Verbs:     []string{"create", "get", "list", "update"},
		APIGroups: []string{"coordination.k8s.io"},
		Resources: []string{"leases"},
	}
)
View Source
var (
	ClusterResourcePlacementGVR = schema.GroupVersionResource{
		Group:    fleetv1alpha1.GroupVersion.Group,
		Version:  fleetv1alpha1.GroupVersion.Version,
		Resource: fleetv1alpha1.ClusterResourcePlacementResource,
	}

	NamespaceGVK = schema.GroupVersionKind{
		Group:   corev1.GroupName,
		Version: corev1.SchemeGroupVersion.Version,
		Kind:    "Namespace",
	}

	NamespaceGVR = schema.GroupVersionResource{
		Group:    corev1.GroupName,
		Version:  corev1.SchemeGroupVersion.Version,
		Resource: "namespaces",
	}

	MemberClusterGVR = schema.GroupVersionResource{
		Group:    fleetv1alpha1.GroupVersion.Group,
		Version:  fleetv1alpha1.GroupVersion.Version,
		Resource: fleetv1alpha1.MemberClusterResource,
	}

	WorkGVK = schema.GroupVersionKind{
		Group:   workv1alpha1.GroupVersion.Group,
		Version: workv1alpha1.GroupVersion.Version,
		Kind:    workv1alpha1.WorkKind,
	}

	WorkGVR = schema.GroupVersionResource{
		Group:   workv1alpha1.GroupVersion.Group,
		Version: workv1alpha1.GroupVersion.Version,

		Resource: "works",
	}

	ServiceGVR = schema.GroupVersionResource{
		Group:    corev1.GroupName,
		Version:  corev1.SchemeGroupVersion.Version,
		Resource: "services",
	}
)

Functions

func CheckCRDInstalled

func CheckCRDInstalled(discoveryClient discovery.DiscoveryInterface, gvk schema.GroupVersionKind) error

CheckCRDInstalled checks if the custom resource definition is installed

func ContextForChannel

func ContextForChannel(parentCh <-chan struct{}) (context.Context, context.CancelFunc)

ContextForChannel derives a child context from a parent channel.

The derived context's Done channel is closed when the returned cancel function is called or when the parent channel is closed, whichever happens first.

Note the caller must *always* call the CancelFunc, otherwise resources may be leaked.

func GetEventString

func GetEventString(object runtime.Object, eventtype, reason, messageFmt string, args ...interface{}) string

GetEventString get the exact string literal of the event created by the fake event library.

func NewFakeRecorder

func NewFakeRecorder(bufferSize int) *record.FakeRecorder

NewFakeRecorder makes a new fake event recorder that prints the object.

func NewResourceList

func NewResourceList() v1.ResourceList

NewResourceList returns a resource list for test purpose.

func NewTestNodes

func NewTestNodes(ns string) []v1.Node

NewTestNodes return a set of nodes for test purpose. Those nodes have random names and capacities/ allocatable.

func RandSecureInt

func RandSecureInt(limit int64) int64

func RandStr

func RandStr() string

func ShouldPropagateObj added in v0.3.0

func ShouldPropagateObj(informerManager InformerManager, uObj *unstructured.Unstructured) (bool, error)

ShouldPropagateObj decides if one should propagate the object

Types

type APIResourceMeta

type APIResourceMeta struct {
	// GroupVersionResource is the gvr of the resource.
	GroupVersionResource schema.GroupVersionResource

	// IsClusterScoped indicates if the resource is a cluster scoped resource.
	IsClusterScoped bool
	// contains filtered or unexported fields
}

APIResourceMeta contains the gvk and associated metadata about an api resource

type DisabledResourceConfig

type DisabledResourceConfig struct {
	// contains filtered or unexported fields
}

DisabledResourceConfig represents the configuration that identifies the API resources should not be selected.

func NewDisabledResourceConfig

func NewDisabledResourceConfig() *DisabledResourceConfig

NewDisabledResourceConfig to create DisabledResourceConfig

func (*DisabledResourceConfig) DisableGroup

func (r *DisabledResourceConfig) DisableGroup(g string)

DisableGroup to disable group.

func (*DisabledResourceConfig) DisableGroupVersion

func (r *DisabledResourceConfig) DisableGroupVersion(gv schema.GroupVersion)

DisableGroupVersion to disable group version.

func (*DisabledResourceConfig) DisableGroupVersionKind

func (r *DisabledResourceConfig) DisableGroupVersionKind(gvk schema.GroupVersionKind)

DisableGroupVersionKind to disable GroupVersionKind.

func (*DisabledResourceConfig) IsResourceDisabled

func (r *DisabledResourceConfig) IsResourceDisabled(gvk schema.GroupVersionKind) bool

IsResourceDisabled returns whether a given GroupVersionKind is disabled. a gkv is disabled if its group or group version is disabled

func (*DisabledResourceConfig) Parse

func (r *DisabledResourceConfig) Parse(c string) error

Parse parses the --avoid-selecting-apis input.

type InformerManager

type InformerManager interface {
	// AddDynamicResources builds a dynamicInformer for each resource in the resources list with the event handler.
	// A resource is dynamic if its definition can be created/deleted/updated during runtime.
	// Normally, it is a custom resource that is installed by users. The handler should not be nil.
	AddDynamicResources(resources []APIResourceMeta, handler cache.ResourceEventHandler, listComplete bool)

	// AddStaticResource creates a dynamicInformer for the static 'resource' and set its event handler.
	// A resource is static if its definition is pre-determined and immutable during runtime.
	// Normally, it is a resource that is pre-installed by the system.
	// This function can only be called once for each type of static resource during the initialization of the informer manager.
	AddStaticResource(resource APIResourceMeta, handler cache.ResourceEventHandler)

	// IsInformerSynced checks if the resource's informer is synced.
	IsInformerSynced(resource schema.GroupVersionResource) bool

	// Start will run all informers, the informers will keep running until the channel closed.
	// It is intended to be called after create new informer(s), and it's safe to call multi times.
	Start()

	// Stop stops all informers of in this manager. Once it is stopped, it will be not able to Start again.
	Stop()

	// Lister returns a generic lister used to get 'resource' from informer's store.
	// The informer for 'resource' will be created if not exist, but without any event handler.
	Lister(resource schema.GroupVersionResource) cache.GenericLister

	// GetNameSpaceScopedResources returns the list of namespace scoped resources we are watching.
	GetNameSpaceScopedResources() []schema.GroupVersionResource

	// IsClusterScopedResources returns if a resource is cluster scoped.
	IsClusterScopedResources(resource schema.GroupVersionResource) bool

	// WaitForCacheSync waits for the informer cache to populate.
	WaitForCacheSync()

	// GetClient returns the dynamic dynamicClient.
	GetClient() dynamic.Interface
}

InformerManager manages dynamic shared informer for all resources, include Kubernetes resource and custom resources defined by CustomResourceDefinition.

func NewInformerManager

func NewInformerManager(client dynamic.Interface, defaultResync time.Duration, parentCh <-chan struct{}) InformerManager

NewInformerManager constructs a new instance of informerManagerImpl. defaultResync with value '0' means no re-sync.

type NotFoundMatcher

type NotFoundMatcher struct {
}

NotFoundMatcher matches the error to be not found.

func (NotFoundMatcher) FailureMessage

func (matcher NotFoundMatcher) FailureMessage(actual interface{}) (message string)

FailureMessage builds an error message.

func (NotFoundMatcher) Match

func (matcher NotFoundMatcher) Match(actual interface{}) (success bool, err error)

Match matches the api error.

func (NotFoundMatcher) NegatedFailureMessage

func (matcher NotFoundMatcher) NegatedFailureMessage(actual interface{}) (message string)

NegatedFailureMessage builds an error message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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