utils

package
v0.11.4 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 43 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FleetSystemNamespace  = fleetPrefix + "system"
	NamespaceNameFormat   = fleetPrefix + "member-%s"
	RoleNameFormat        = fleetPrefix + "role-%s"
	RoleBindingNameFormat = fleetPrefix + "rolebinding-%s"
	ValidationPathFmt     = "/validate-%s-%s-%s"
)
View Source
const (
	// NetworkingGroupName is the group name of the fleet networking.
	NetworkingGroupName = "networking.fleet.azure.com"

	DeploymentKind  = "Deployment"
	DaemonSetKind   = "DaemonSet"
	StatefulSetKind = "StatefulSet"
	ConfigMapKind   = "ConfigMap"
	ServiceKind     = "Service"
	NamespaceKind   = "Namespace"
	JobKind         = "Job"
)
View Source
const (
	PlacementFieldManagerName           = "cluster-placement-controller"
	MCControllerFieldManagerName        = "member-cluster-controller"
	OverrideControllerFieldManagerName  = "override-controller"
	UpdateRunControllerFieldManagerName = "cluster-staged-update-run-controller"
)
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"

	// LastWorkUpdateTimeAnnotationKey is used to mark the last update time on a work object.
	LastWorkUpdateTimeAnnotationKey = "work.fleet.azure.com/last-update-time"

	// ResourceIdentifierStringFormat is the format of the resource identifier string.
	ResourceIdentifierStringFormat = "%s/%s/%s/%s/%s"

	// ResourceIdentifierWithEnvelopeIdentifierStringFormat is the format of the resource identifier string with envelope identifier.
	ResourceIdentifierWithEnvelopeIdentifierStringFormat = "%s/%s/%s/%s/%s/%s/%s/%s"

	// FleetAnnotationPrefix is the prefix used to annotate fleet member cluster resources.
	FleetAnnotationPrefix = "fleet.azure.com"
)

TODO(ryanzhang): move this to the api directory

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{"*"},
	}
	FleetClusterRule = rbacv1.PolicyRule{
		Verbs:     []string{"*"},
		APIGroups: []string{clusterv1beta1.GroupVersion.Group},
		Resources: []string{"*"},
	}
	FleetPlacementRule = rbacv1.PolicyRule{
		Verbs:     []string{"*"},
		APIGroups: []string{placementv1beta1.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{NetworkingGroupName},
		Resources: []string{"*"},
	}
)
View Source
var (
	ClusterResourcePlacementV1Alpha1GVK = schema.GroupVersionKind{
		Group:   fleetv1alpha1.GroupVersion.Group,
		Version: fleetv1alpha1.GroupVersion.Version,
		Kind:    "ClusterResourcePlacement",
	}

	ClusterResourcePlacementV1Alpha1GVR = schema.GroupVersionResource{
		Group:    fleetv1alpha1.GroupVersion.Group,
		Version:  fleetv1alpha1.GroupVersion.Version,
		Resource: fleetv1alpha1.ClusterResourcePlacementResource,
	}

	ClusterResourcePlacementGVR = schema.GroupVersionResource{
		Group:    placementv1beta1.GroupVersion.Group,
		Version:  placementv1beta1.GroupVersion.Version,
		Resource: placementv1beta1.ClusterResourcePlacementResource,
	}

	ClusterResourcePlacementMetaGVK = metav1.GroupVersionKind{
		Group:   placementv1beta1.GroupVersion.Group,
		Version: placementv1beta1.GroupVersion.Version,
		Kind:    placementv1beta1.ClusterResourcePlacementKind,
	}

	ConfigMapGVK = schema.GroupVersionKind{
		Group:   corev1.GroupName,
		Version: corev1.SchemeGroupVersion.Version,
		Kind:    ConfigMapKind,
	}

	CRDMetaGVK = metav1.GroupVersionKind{
		Group:   apiextensionsv1.SchemeGroupVersion.Group,
		Version: apiextensionsv1.SchemeGroupVersion.Version,
		Kind:    "CustomResourceDefinition",
	}

	EndpointSliceExportMetaGVK = metav1.GroupVersionKind{
		Group:   fleetnetworkingv1alpha1.GroupVersion.Group,
		Version: fleetnetworkingv1alpha1.GroupVersion.Version,
		Kind:    "EndpointSliceExport",
	}

	EndpointSliceImportMetaGVK = metav1.GroupVersionKind{
		Group:   fleetnetworkingv1alpha1.GroupVersion.Group,
		Version: fleetnetworkingv1alpha1.GroupVersion.Version,
		Kind:    "EndpointSliceImport",
	}

	EventMetaGVK = metav1.GroupVersionKind{
		Group:   corev1.SchemeGroupVersion.Group,
		Version: corev1.SchemeGroupVersion.Version,
		Kind:    "Event",
	}

	IMCV1Alpha1MetaGVK = metav1.GroupVersionKind{
		Group:   fleetv1alpha1.GroupVersion.Group,
		Version: fleetv1alpha1.GroupVersion.Version,
		Kind:    "InternalMemberCluster",
	}

	InternalServiceExportMetaGVK = metav1.GroupVersionKind{
		Group:   fleetnetworkingv1alpha1.GroupVersion.Group,
		Version: fleetnetworkingv1alpha1.GroupVersion.Version,
		Kind:    "InternalServiceExport",
	}

	InternalServiceImportMetaGVK = metav1.GroupVersionKind{
		Group:   fleetnetworkingv1alpha1.GroupVersion.Group,
		Version: fleetnetworkingv1alpha1.GroupVersion.Version,
		Kind:    "InternalServiceImport",
	}

	IMCMetaGVK = metav1.GroupVersionKind{
		Group:   clusterv1beta1.GroupVersion.Group,
		Version: clusterv1beta1.GroupVersion.Version,
		Kind:    "InternalMemberCluster",
	}

	MCV1Alpha1MetaGVK = metav1.GroupVersionKind{
		Group:   fleetv1alpha1.GroupVersion.Group,
		Version: fleetv1alpha1.GroupVersion.Version,
		Kind:    "MemberCluster",
	}

	MCV1Alpha1GVK = schema.GroupVersionKind{
		Group:   fleetv1alpha1.GroupVersion.Group,
		Version: fleetv1alpha1.GroupVersion.Version,
		Kind:    fleetv1alpha1.MemberClusterKind,
	}

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

	MCMetaGVK = metav1.GroupVersionKind{
		Group:   clusterv1beta1.GroupVersion.Group,
		Version: clusterv1beta1.GroupVersion.Version,
		Kind:    "MemberCluster",
	}

	NamespaceMetaGVK = metav1.GroupVersionKind{
		Group:   corev1.GroupName,
		Version: corev1.SchemeGroupVersion.Version,
		Kind:    NamespaceKind,
	}

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

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

	PodMetaGVK = metav1.GroupVersionKind{
		Group:   corev1.SchemeGroupVersion.Group,
		Version: corev1.SchemeGroupVersion.Version,
		Kind:    "Pod",
	}

	RoleMetaGVK = metav1.GroupVersionKind{
		Group:   rbacv1.SchemeGroupVersion.Group,
		Version: rbacv1.SchemeGroupVersion.Version,
		Kind:    "Role",
	}

	RoleBindingMetaGVK = metav1.GroupVersionKind{
		Group:   rbacv1.SchemeGroupVersion.Group,
		Version: rbacv1.SchemeGroupVersion.Version,
		Kind:    "RoleBinding",
	}

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

	WorkV1Alpha1MetaGVK = metav1.GroupVersionKind{
		Group:   workv1alpha1.GroupVersion.Group,
		Version: workv1alpha1.GroupVersion.Version,
		Kind:    "Work",
	}

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

	WorkV1Alpha1GVR = schema.GroupVersionResource{
		Group:    workv1alpha1.GroupVersion.Group,
		Version:  workv1alpha1.GroupVersion.Version,
		Resource: workv1alpha1.WorkResource,
	}

	WorkMetaGVK = metav1.GroupVersionKind{
		Group:   placementv1beta1.GroupVersion.Group,
		Version: placementv1beta1.GroupVersion.Version,
		Kind:    "Work",
	}

	ClusterResourceOverrideSnapshotKind = schema.GroupVersionKind{
		Group:   placementv1alpha1.GroupVersion.Group,
		Version: placementv1alpha1.GroupVersion.Version,
		Kind:    placementv1alpha1.ClusterResourceOverrideSnapshotKind,
	}

	ResourceOverrideSnapshotKind = schema.GroupVersionKind{
		Group:   placementv1alpha1.GroupVersion.Group,
		Version: placementv1alpha1.GroupVersion.Version,
		Kind:    placementv1alpha1.ResourceOverrideSnapshotKind,
	}

	DeploymentGVR = schema.GroupVersionResource{
		Group:    appv1.GroupName,
		Version:  appv1.SchemeGroupVersion.Version,
		Resource: "deployments",
	}

	DeploymentGVK = schema.GroupVersionKind{
		Group:   appv1.GroupName,
		Version: appv1.SchemeGroupVersion.Version,
		Kind:    DeploymentKind,
	}

	DaemonSettGVR = schema.GroupVersionResource{
		Group:    appv1.GroupName,
		Version:  appv1.SchemeGroupVersion.Version,
		Resource: "daemonsets",
	}

	StatefulSettGVR = schema.GroupVersionResource{
		Group:    appv1.GroupName,
		Version:  appv1.SchemeGroupVersion.Version,
		Resource: "statefulsets",
	}

	JobGVR = schema.GroupVersionResource{
		Group:    batchv1.GroupName,
		Version:  batchv1.SchemeGroupVersion.Version,
		Resource: "jobs",
	}

	ConfigMapGVR = schema.GroupVersionResource{
		Group:    corev1.GroupName,
		Version:  corev1.SchemeGroupVersion.Version,
		Resource: string(corev1.ResourceConfigMaps),
	}

	SecretGVR = schema.GroupVersionResource{
		Group:    corev1.GroupName,
		Version:  corev1.SchemeGroupVersion.Version,
		Resource: string(corev1.ResourceSecrets),
	}

	RoleGVR = schema.GroupVersionResource{
		Group:    rbacv1.GroupName,
		Version:  rbacv1.SchemeGroupVersion.Version,
		Resource: "roles",
	}

	ClusterRoleGVR = schema.GroupVersionResource{
		Group:    rbacv1.GroupName,
		Version:  rbacv1.SchemeGroupVersion.Version,
		Resource: "clusterroles",
	}

	ClusterRoleGVK = schema.GroupVersionKind{
		Group:   rbacv1.GroupName,
		Version: rbacv1.SchemeGroupVersion.Version,
		Kind:    "ClusterRole",
	}

	RoleBindingGVR = schema.GroupVersionResource{
		Group:    rbacv1.GroupName,
		Version:  rbacv1.SchemeGroupVersion.Version,
		Resource: "rolebindings",
	}

	ClusterRoleBindingGVR = schema.GroupVersionResource{
		Group:    rbacv1.GroupName,
		Version:  rbacv1.SchemeGroupVersion.Version,
		Resource: "clusterrolebindings",
	}
)

Those are the GVR/GVK of the fleet related resources.

View Source
var (

	// IgnoreConditionLTTAndMessageFields is a cmpopts.IgnoreFields that ignores the LastTransitionTime and Message fields
	IgnoreConditionLTTAndMessageFields = cmpopts.IgnoreFields(metav1.Condition{}, "LastTransitionTime", "Message")
)
View Source
var LessFuncFailedResourcePlacements = func(a, b placementv1beta1.FailedResourcePlacement) bool {
	var aStr, bStr string
	if a.Envelope != nil {
		aStr = fmt.Sprintf(ResourceIdentifierWithEnvelopeIdentifierStringFormat, a.Group, a.Version, a.Kind, a.Namespace, a.Name, a.Envelope.Type, a.Envelope.Namespace, a.Envelope.Name)
	} else {
		aStr = fmt.Sprintf(ResourceIdentifierStringFormat, a.Group, a.Version, a.Kind, a.Namespace, a.Name)
	}
	if b.Envelope != nil {
		bStr = fmt.Sprintf(ResourceIdentifierWithEnvelopeIdentifierStringFormat, b.Group, b.Version, b.Kind, b.Namespace, b.Name, b.Envelope.Type, b.Envelope.Namespace, b.Envelope.Name)
	} else {
		bStr = fmt.Sprintf(ResourceIdentifierStringFormat, b.Group, b.Version, b.Kind, b.Namespace, b.Name)

	}
	return aStr < bStr
}

LessFuncFailedResourcePlacements is a less function for sorting failed resource placements

View Source
var LessFuncResourceIdentifier = func(a, b placementv1beta1.ResourceIdentifier) bool {
	aStr := fmt.Sprintf(ResourceIdentifierStringFormat, a.Group, a.Version, a.Kind, a.Namespace, a.Name)
	bStr := fmt.Sprintf(ResourceIdentifierStringFormat, b.Group, b.Version, b.Kind, b.Namespace, b.Name)
	return aStr < bStr
}

LessFuncResourceIdentifier is a less function for sorting resource identifiers

Functions

func CheckCRDInstalled

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

CheckCRDInstalled checks if the custom resource definition is installed

func GenerateGroupString added in v0.8.1

func GenerateGroupString(groups []string) string

GenerateGroupString generates a string which prints groups in which a user belongs, it compresses the string to just display three groups if length of groups is more than 10.

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 GetObjectFromManifest added in v0.6.4

func GetObjectFromManifest(relativeFilePath string, obj runtime.Object) error

GetObjectFromManifest returns a runtime object decoded from the file.

func GetObjectFromRawExtension added in v0.6.4

func GetObjectFromRawExtension(rawByte []byte, obj runtime.Object) error

GetObjectFromRawExtension returns an object decoded from the raw byte array.

func IsFailedResourcePlacementsEqual added in v0.10.8

func IsFailedResourcePlacementsEqual(oldFailedResourcePlacements, newFailedResourcePlacements []placementv1beta1.FailedResourcePlacement) bool

func IsFleetAnnotationPresent added in v0.10.10

func IsFleetAnnotationPresent(annotations map[string]string) bool

IsFleetAnnotationPresent returns true if a key with fleet prefix is present in the annotations map.

func IsReservedNamespace added in v0.6.3

func IsReservedNamespace(namespace string) bool

IsReservedNamespace indicates if an argued namespace is reserved.

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

RandSecureInt returns a uniform random value in [1, max] or panic. Only use this in tests.

func RandStr

func RandStr() string

func ShouldPropagateNamespace added in v0.5.5

func ShouldPropagateNamespace(namespace string, skippedNamespaces map[string]bool) bool

ShouldPropagateNamespace decides if we should propagate the resources in the namespace.

func ShouldPropagateObj added in v0.3.0

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

ShouldPropagateObj decides if one should propagate the object

Types

type AlreadyExistMatcher added in v0.5.5

type AlreadyExistMatcher struct {
}

AlreadyExistMatcher matches the error to be already exist

func (AlreadyExistMatcher) FailureMessage added in v0.5.5

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

FailureMessage builds an error message.

func (AlreadyExistMatcher) Match added in v0.5.5

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

Match matches error.

func (AlreadyExistMatcher) NegatedFailureMessage added in v0.5.5

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

NegatedFailureMessage builds an error message.

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.

type ResourceConfig added in v0.8.3

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

ResourceConfig represents the configuration that identifies the API resources that are parsed from the user input to either allow or disable propagating them.

func NewResourceConfig added in v0.8.3

func NewResourceConfig(isAllowList bool) *ResourceConfig

NewResourceConfig creates an empty ResourceConfig with an allow list flag. If the resourceConfig is not an allowlist, it creates a default skipped propagating APIs list.

func (*ResourceConfig) AddGroup added in v0.8.3

func (r *ResourceConfig) AddGroup(g string)

AddGroup stores a group in the resource config.

func (*ResourceConfig) AddGroupVersion added in v0.8.3

func (r *ResourceConfig) AddGroupVersion(gv schema.GroupVersion)

AddGroupVersion stores a group version in the resource config.

func (*ResourceConfig) AddGroupVersionKind added in v0.8.3

func (r *ResourceConfig) AddGroupVersionKind(gvk schema.GroupVersionKind)

AddGroupVersionKind stores a GroupVersionKind in the resource config.

func (*ResourceConfig) IsResourceDisabled added in v0.8.3

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

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

func (*ResourceConfig) Parse added in v0.8.3

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

Parse parses the user inputs that provides apis as GVK, GV or Group.

type TestMapper added in v0.10.8

type TestMapper struct {
	meta.RESTMapper
}

TestMapper interface for abstract class.

func (TestMapper) RESTMapping added in v0.10.8

func (m TestMapper) RESTMapping(gk schema.GroupKind, _ ...string) (*meta.RESTMapping, error)

Directories

Path Synopsis
Package annotations provides the utils related to object annotations.
Package annotations provides the utils related to object annotations.
cloudconfig
azure
Package azure provides utilities to load, parse, and validate Azure cloud configuration.
Package azure provides utilities to load, parse, and validate Azure cloud configuration.
Package condition provides condition related utils.
Package condition provides condition related utils.
Package defaulter is an interface for setting default values for a resource.
Package defaulter is an interface for setting default values for a resource.
Package labels provides utils related to object labels.
Package labels provides utils related to object labels.
Package overrider defines common utils for working with override.
Package overrider defines common utils for working with override.
Package resource defines common utils for working with kubernetes resources.
Package resource defines common utils for working with kubernetes resources.
Package validator provides utils to validate ClusterResourceOverride resources.
Package validator provides utils to validate ClusterResourceOverride resources.

Jump to

Keyboard shortcuts

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