util

package
v4.3.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHashAnnotation added in v4.3.6

func AddHashAnnotation(obj *unstructured.Unstructured, key, hash string, newAnnotations map[string]string) map[string]string

SetHashAnnotation sets the hash annotation in the object

func AddObjectField added in v4.3.6

func AddObjectField(obj interface{}, jsonPath string, value interface{})

AddObjectField adds the field to the object according to the jsonPath jsonPath is a string that represents the path to the field in the object, always starts with "."

func CalculateHash added in v4.3.6

func CalculateHash(input []byte) string

CalculateHash calculates the hash value for single resource

func CalculateResHashes added in v4.3.6

func CalculateResHashes(fromCluster *unstructured.Unstructured, fromTemplate []byte) (string, string)

CalculateResHashes calculates the hash for the existing cluster resource and the new template resource

func CompareChannelVersion

func CompareChannelVersion(v1, v2 string) (v1IsLarger bool, err error)

func CompareConfigMap

func CompareConfigMap(configMap *corev1.ConfigMap, existingConfigMap *corev1.ConfigMap) (needUpdate bool)

func CompareSecret

func CompareSecret(secret *corev1.Secret, existingSecret *corev1.Secret) (needUpdate bool)

func Contains

func Contains(list []string, s string) bool

func Differs

func Differs(list []string, s string) bool

func EnsureAnnotationForConfigMap added in v4.3.7

func EnsureAnnotationForConfigMap(cm *corev1.ConfigMap, annotations map[string]string)

func EnsureAnnotationsForSecret added in v4.3.7

func EnsureAnnotationsForSecret(secret *corev1.Secret, annotatinos map[string]string)

func EnsureLabelsForConfigMap

func EnsureLabelsForConfigMap(cm *corev1.ConfigMap, labels map[string]string)

func EnsureLabelsForRoute

func EnsureLabelsForRoute(r *ocproute.Route, labels map[string]string)

func EnsureLabelsForSecret

func EnsureLabelsForSecret(secret *corev1.Secret, labels map[string]string)

func EnsureLabelsForService

func EnsureLabelsForService(s *corev1.Service, labels map[string]string)

func FindMaxSemver added in v4.3.5

func FindMaxSemver(curChannel string, semverlList []string, semVerChannelMappings map[string]string) string

FindMaxSemver returns the maximal semantic version by given channel and semver list

func FindMinSemver added in v4.3.4

func FindMinSemver(curChannel string, semverlList []string, semVerChannelMappings map[string]string) string

FindMinSemver returns the minimal semantic version by given channel and semver list

func FindMinSemverFromAnnotations added in v4.3.5

func FindMinSemverFromAnnotations(annotations map[string]string, curChannel string) string

func FindSemantic added in v4.3.4

func FindSemantic(input string) string

FindSemantic checks if a given string contains a substring which is a valid semantic version, and returns that substring

func FindSemverFromAnnotations added in v4.3.5

func FindSemverFromAnnotations(annotations map[string]string) ([]string, map[string]string)

func GetFirstNCharacter added in v4.3.7

func GetFirstNCharacter(str string, n int) string

func GetInstallScope

func GetInstallScope() string

GetInstallScope returns the scope of the installation

func GetIsolatedMode

func GetIsolatedMode() bool

func GetOperatorNamespace

func GetOperatorNamespace() string

GetOperatorNamespace returns the Namespace of the operator

func GetWatchNamespace

func GetWatchNamespace() string

GetWatchNamespace returns the Namespace of the operator

func GetoperatorCheckerMode

func GetoperatorCheckerMode() bool

func MergeCR

func MergeCR(defaultCR, changedCR []byte) map[string]interface{}

MergeCR deep merge two custom resource spec

func ObjectToNewUnstructured

func ObjectToNewUnstructured(obj interface{}) (*unstructured.Unstructured, error)

func RemoveObjectField added in v4.3.6

func RemoveObjectField(obj interface{}, jsonPath string)

RemoveObjectField removes the field from the object according to the jsonPath jsonPath is a string that represents the path to the field in the object, always starts with "."

func ResourceExists

func ResourceExists(dc discovery.DiscoveryInterface, apiGroupVersion, kind string) (bool, error)

ResourceExists returns true if the given resource kind exists in the given api groupversion

func ResourceNamespaced

func ResourceNamespaced(dc discovery.DiscoveryInterface, apiGroupVersion, kind string) (bool, error)

ResourceNamespaced returns true if the given resource is namespaced

func SanitizeObjectString

func SanitizeObjectString(jsonPath string, data interface{}) (string, error)

SanitizeObjectString takes a string, i.e. .metadata.namespace, and a K8s object and returns a string got from K8s object. The required string is sanitized because the values are YAML fields in a K8s object. Ensures that:

  1. the field actually exists, otherwise returns an error
  2. extracts the value from the K8s Service's field, the value will be stringified

func StringSliceContentEqual

func StringSliceContentEqual(a, b []string) bool

StringSliceContentEqual checks if the contant from two string slice are the same

func WaitTimeout

func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool

WaitTimeout waits for the waitgroup for the specified max timeout. Returns true if waiting timed out.

Types

type ConfigMapRef

type ConfigMapRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	Key       string `json:"key"`
}

type DefaultObjectRef

type DefaultObjectRef struct {
	Required        bool          `json:"required,omitempty"`
	ConfigMapKeyRef *ConfigMapRef `json:"configMapKeyRef,omitempty"`
	SecretRef       *SecretRef    `json:"secretKeyRef,omitempty"`
	// RouteRef        *RouteRef     `json:"routePathRef,omitempty"`
	ObjectRef    *ObjectRef `json:"objectRef,omitempty"`
	DefaultValue string     `json:"defaultValue,omitempty"`
}

type MultiErr

type MultiErr struct {
	Errors []string
}

MultiErr is a multiple error slice

func (*MultiErr) Add

func (mer *MultiErr) Add(err error)

Add appends error message

func (*MultiErr) Error

func (mer *MultiErr) Error() string

Error is the error message

type ObjectRef

type ObjectRef struct {
	Name       string `json:"name"`
	Namespace  string `json:"namespace"`
	Path       string `json:"path"`
	APIVersion string `json:"apiVersion"`
	Kind       string `json:"kind"`
}

type SecretRef

type SecretRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	Key       string `json:"key"`
}

type TemplateValueRef

type TemplateValueRef struct {
	Required        bool              `json:"required,omitempty"`
	Default         *DefaultObjectRef `json:"default,omitempty"`
	ConfigMapKeyRef *ConfigMapRef     `json:"configMapKeyRef,omitempty"`
	SecretRef       *SecretRef        `json:"secretKeyRef,omitempty"`
	// RouteRef        *RouteRef         `json:"routePathRef,omitempty"`
	ObjectRef *ObjectRef `json:"objectRef,omitempty"`
}

Jump to

Keyboard shortcuts

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