utils

package
v0.3.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: Apache-2.0 Imports: 23 Imported by: 4

Documentation

Overview

Package utils contains shared utility methods for the Liqonet package.

Index

Constants

View Source
const (
	// LogInfoLevel -> level associated with informational messages.
	LogInfoLevel = 0
	// LogDebugLevel -> level associated with debug messages.
	LogDebugLevel = 4
)

Variables

This section is empty.

Functions

func AddRemoteNamespaceCondition added in v0.3.0

func AddRemoteNamespaceCondition(conditions *[]offv1alpha1.RemoteNamespaceCondition,
	newCondition *offv1alpha1.RemoteNamespaceCondition)

AddRemoteNamespaceCondition sets newCondition in the conditions slice. conditions must be non-nil.

  1. if the condition of the specified type already exists (all fields of the existing condition are updated to newCondition, LastTransitionTime is set to now if the new status differs from the old status).
  2. if a condition of the specified type does not exist (LastTransitionTime is set to now() if unset, and newCondition is appended).

func FindRemoteNamespaceCondition added in v0.3.0

FindRemoteNamespaceCondition finds the conditionType in conditions.

func FromResult added in v0.3.0

func FromResult(result controllerutil.OperationResult) klog.Level

FromResult returns a logger level, given the result of a CreateOrUpdate operation.

func GetAPIServerAddressFromMasterNode

func GetAPIServerAddressFromMasterNode(ctx context.Context,
	clientset kubernetes.Interface) (address string, err error)

GetAPIServerAddressFromMasterNode returns the API Server address using the IP of the master node of this cluster. The port is always defaulted to 6443.

func GetAPIServerURL

func GetAPIServerURL(apiServerConfigProvider ApiServerConfigProvider, clientset kubernetes.Interface) (string, error)

GetAPIServerURL retrieves the API server URL either from the configuration or selecting the IP address of a master node (with port 6443).

func GetClusterIDFromNodeName added in v0.3.0

func GetClusterIDFromNodeName(nodeName string) string

GetClusterIDFromNodeName returns the clusterID from a node name.

func GetClusterIDWithControllerClient added in v0.3.0

func GetClusterIDWithControllerClient(ctx context.Context, controllerClient client.Client, namespace string) (string, error)

GetClusterIDWithControllerClient returns clusterID using a client.Client client.

func GetClusterIDWithNativeClient added in v0.3.0

func GetClusterIDWithNativeClient(ctx context.Context, nativeClient kubernetes.Interface, namespace string) (string, error)

GetClusterIDWithNativeClient returns clusterID using a kubernetes.Interface client.

func GetOwnerByKind added in v0.3.0

func GetOwnerByKind(ownerReferences *[]v1.OwnerReference, kind string) *v1.OwnerReference

func GetRestConfig added in v0.3.0

func GetRestConfig(configPath string) (config *rest.Config, err error)

GetRestConfig returns a rest.Config object to initialize a client to the target cluster.

func IsNodeReady added in v0.3.0

func IsNodeReady(node *corev1.Node) bool

IsNodeReady returns true if the passed node has the NodeReady condition = True, false otherwise.

func IsStatusConditionFalse added in v0.3.0

func IsStatusConditionFalse(conditions []offv1alpha1.RemoteNamespaceCondition,
	conditionType offv1alpha1.RemoteNamespaceConditionType) bool

IsStatusConditionFalse returns true when the conditionType is present and set to `corev1.ConditionFalse`.

func IsStatusConditionPresentAndEqual added in v0.3.0

func IsStatusConditionPresentAndEqual(conditions []offv1alpha1.RemoteNamespaceCondition,
	conditionType offv1alpha1.RemoteNamespaceConditionType, status corev1.ConditionStatus) bool

IsStatusConditionPresentAndEqual returns true when conditionType is present and equal to status.

func IsStatusConditionTrue added in v0.3.0

func IsStatusConditionTrue(conditions []offv1alpha1.RemoteNamespaceCondition,
	conditionType offv1alpha1.RemoteNamespaceConditionType) bool

IsStatusConditionTrue returns true when the conditionType is present and set to `corev1.ConditionTrue`.

func MergeMaps added in v0.3.0

func MergeMaps(m1, m2 map[string]string) map[string]string

MergeMaps merges two maps.

func RemoveRemoteNamespaceCondition added in v0.3.0

func RemoveRemoteNamespaceCondition(conditions *[]offv1alpha1.RemoteNamespaceCondition,
	conditionType offv1alpha1.RemoteNamespaceConditionType)

RemoveRemoteNamespaceCondition removes the corresponding conditionType from conditions. conditions must be non-nil.

func RetrieveNamespace added in v0.3.0

func RetrieveNamespace() (string, error)

RetrieveNamespace tries to retrieve the name of the namespace where the process is executed. It tries to get the namespace: - Firstly, using the POD_NAMESPACE variable - Secondly, by looking for the namespace value contained in a mounted ServiceAccount (if any) Otherwise, it returns an empty string and an error.

func SubMaps added in v0.3.0

func SubMaps(m1, m2 map[string]string) map[string]string

SubMaps removes elements of m2 from m1.

func UserConfig

func UserConfig(configPath string) (*rest.Config, error)

func WatchConfiguration

func WatchConfiguration(handler func(*configv1alpha1.ClusterConfig), client *crdclient.CRDClient, kubeconfigPath string)

WatchConfiguration watches the ClusterConfig CR, and calls the handler funcition on updates.

func WriteFile

func WriteFile(filepath string, content []byte) error

Types

type ApiServerConfigProvider

type ApiServerConfigProvider interface {
	GetAPIServerConfig() *configv1alpha1.APIServerConfig
}

Directories

Path Synopsis
Package authenticationtoken contains shared utility methods for the management of the authentication token.
Package authenticationtoken contains shared utility methods for the management of the authentication token.
Package cachedclient contains utility methods to create a new controller runtime client with cache.
Package cachedclient contains utility methods to create a new controller runtime client with cache.
Package errorsmanagement contains all utility function to use in case of errors.
Package errorsmanagement contains all utility function to use in case of errors.
Package foreigncluster contains shared utility methods to handle the ForeignCluster resources.
Package foreigncluster contains shared utility methods to handle the ForeignCluster resources.
Package peeringconditionsutils contains shared utility methods to handle the PeeringCondition resource.
Package peeringconditionsutils contains shared utility methods to handle the PeeringCondition resource.
Package pod contains utilities to deal with Pod objects.
Package pod contains utilities to deal with Pod objects.
Package restcfg contains utility functions to deal with rest configs.
Package restcfg contains utility functions to deal with rest configs.
Package slice contains utility functions to manage slices.
Package slice contains utility functions to manage slices.
Package testutil contains some methods useful to mock components while testing
Package testutil contains some methods useful to mock components while testing
Package trace contains utility functions to deal with traces.
Package trace contains utility functions to deal with traces.

Jump to

Keyboard shortcuts

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