util

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	OperatorNamespaceEnv   = "OPERATOR_NAMESPACE"
	OperatorWebhookModeEnv = "WEBHOOK_MODE"
	ContainerAppName       = "APP"
	ContainerOperatorApp   = "OPERATOR"
	ContainerWebhookApp    = "WEBHOOK"
	HcoKvIoVersionName     = "HCO_KV_IO_VERSION"
	KubevirtVersionEnvV    = "KUBEVIRT_VERSION"
	CdiVersionEnvV         = "CDI_VERSION"
	CnaoVersionEnvV        = "NETWORK_ADDONS_VERSION"
	SspVersionEnvV         = "SSP_VERSION"
	NmoVersionEnvV         = "NMO_VERSION"
	HppoVersionEnvV        = "HPPO_VERSION"
	VMImportEnvV           = "VM_IMPORT_VERSION"
	HcoValidatingWebhook   = "validate-hco.kubevirt.io"
	HcoMutatingWebhookNS   = "mutate-ns-hco.kubevirt.io"
	AppLabel               = "app"
	UndefinedNamespace     = ""
	OpenshiftNamespace     = "openshift"
	OperatorTestNamespace  = "test-operators"
	OperatorHubNamespace   = "operators"
	APIVersionAlpha        = "v1alpha1"
	APIVersionBeta         = "v1beta1"
	CurrentAPIVersion      = APIVersionBeta
	APIVersionGroup        = "hco.kubevirt.io"
	APIVersion             = APIVersionGroup + "/" + CurrentAPIVersion
	HyperConvergedKind     = "HyperConverged"
	// Recommended labels by Kubernetes. See
	// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
	AppLabelPrefix    = "app.kubernetes.io"
	AppLabelVersion   = AppLabelPrefix + "/version"
	AppLabelManagedBy = AppLabelPrefix + "/managed-by"
	AppLabelPartOf    = AppLabelPrefix + "/part-of"
	AppLabelComponent = AppLabelPrefix + "/component"
	// Operator name for managed-by label
	OperatorName = "hco-operator"
	// Value for "part-of" label
	HyperConvergedCluster = "hyperconverged-cluster"

	// HyperConvergedName is the name of the HyperConverged resource that will be reconciled
	HyperConvergedName          = "kubevirt-hyperconverged"
	MetricsHost                 = "0.0.0.0"
	MetricsPort           int32 = 8383
	OperatorMetricsPort   int32 = 8686
	HealthProbeHost             = "0.0.0.0"
	HealthProbePort       int32 = 6060
	ReadinessEndpointName       = "/readyz"
	LivenessEndpointName        = "/livez"
	HCOWebhookPath              = "/validate-hco-kubevirt-io-v1beta1-hyperconverged"
	HCONSWebhookPath            = "/mutate-ns-hco-kubevirt-io"
	DefaulterWebhookPath        = "/mutate-hco-kubevirt-io-v1beta1-hyperconverged"
	WebhookPort                 = 4343

	CliDownloadsServerPort = 8080
)

HCO common constants

View Source
const (
	LocalRunMode   RunModeType = "local"
	ClusterRunMode RunModeType = "cluster"

	// WatchNamespaceEnvVar is the constant for env variable WATCH_NAMESPACE
	// which is the namespace where the watch activity happens.
	// this value is empty if the operator is running with clusterScope.
	WatchNamespaceEnvVar = "WATCH_NAMESPACE"

	// PodNameEnvVar is the constant for env variable POD_NAME
	// which is the name of the current pod.
	PodNameEnvVar = "POD_NAME"
)

Variables

View Source
var ErrNoNamespace = fmt.Errorf("namespace not found for current environment")

ErrNoNamespace indicates that a namespace could not be found for the current environment

View Source
var ErrRunLocal = fmt.Errorf("operator run mode forced to local")

ErrRunLocal indicates that the operator is set to run in local mode (this error is returned by functions that only work on operators running in cluster mode)

View Source
var ForceRunModeEnv = "OSDK_FORCE_RUN_MODE"

ForceRunModeEnv indicates if the operator should be forced to run in either local or cluster mode (currently only used for local mode)

Functions

func ComponentResourceRemoval added in v1.2.0

func ComponentResourceRemoval(ctx context.Context, c client.Client, obj interface{}, hcoName string, logger logr.Logger, dryRun bool, wait bool) error

ComponentResourceRemoval removes the resource `obj` if it exists and belongs to the HCO with wait=true it will wait, (util ctx timeout, please set it!) for the resource to be effectively deleted

func ContainsString added in v1.3.0

func ContainsString(s []string, word string) bool

func DeepCopyLabels added in v1.4.0

func DeepCopyLabels(src, tgt *metav1.ObjectMeta)

func EnsureCreated added in v1.2.0

func EnsureCreated(ctx context.Context, c client.Client, obj client.Object, logger logr.Logger) error

EnsureCreated creates the runtime object if it does not exist

func EnsureDeleted added in v1.2.0

func EnsureDeleted(ctx context.Context, c client.Client, obj client.Object, hcoName string, logger logr.Logger, dryRun bool, wait bool) error

EnsureDeleted calls ComponentResourceRemoval if the runtime object exists with wait=true it will wait, (util ctx timeout, please set it!) for the resource to be effectively deleted

func GetCSVfromPod

func GetCSVfromPod(pod *corev1.Pod, c client.Reader, logger logr.Logger) (*csvv1alpha1.ClusterServiceVersion, error)

func GetHcoKvIoVersion added in v1.4.0

func GetHcoKvIoVersion() string

func GetHcoPing added in v1.3.0

func GetHcoPing() healthz.Checker

func GetManifestDirPath added in v1.5.0

func GetManifestDirPath(envVarName string, defaultDir string) string

func GetOperatorNamespace added in v1.3.0

func GetOperatorNamespace(logger logr.Logger) (string, error)

GetOperatorNamespace returns the namespace the operator should be running in.

func GetOperatorNamespaceFromEnv

func GetOperatorNamespaceFromEnv() (string, error)

func GetPod

func GetPod(ctx context.Context, c client.Reader, logger logr.Logger, ci ClusterInfo) (*corev1.Pod, error)

func GetRuntimeObject added in v1.2.0

func GetRuntimeObject(ctx context.Context, c client.Client, obj client.Object, logger logr.Logger) error

GetRuntimeObject will query the apiserver for the object

func GetWatchNamespace added in v1.3.0

func GetWatchNamespace() (string, error)

GetWatchNamespace returns the namespace the operator should be watching for changes

func IsReady added in v1.3.0

func IsReady() bool

func IsRunModeLocal added in v1.4.0

func IsRunModeLocal() bool

func NewProcessingError added in v1.5.0

func NewProcessingError(err error) error

wrap an error if we want to actually stop processing by the error. unwrapping it will return the original error. unwrapping a regular error will return nil

func SetReady added in v1.3.0

func SetReady(ready bool)

func ToUnstructured added in v1.4.0

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

ToUnstructured convers an arbitrary object (which MUST obey the k8s object conventions) to an Unstructured

func UnmarshalYamlFileToObject added in v1.5.0

func UnmarshalYamlFileToObject(file io.Reader, o interface{}) error

func ValidateManifestDir added in v1.5.0

func ValidateManifestDir(dir string) error

ValidateManifestDir checks a directory contains manifests file in YAML format This function returns 3-state error:

err := ValidateManifestDir(...)
err == nil - OK: directory exists
err != nil && errors.Unwrap(err) == nil - directory does not exist, but that ok
err != nil && errors.Unwrap(err) != nil - actual error

Types

type AppComponent added in v1.4.0

type AppComponent string
const (
	AppComponentCompute    AppComponent = "compute"
	AppComponentStorage    AppComponent = "storage"
	AppComponentImport     AppComponent = "import"
	AppComponentNetwork    AppComponent = "network"
	AppComponentMonitoring AppComponent = "monitoring"
	AppComponentSchedule   AppComponent = "schedule"
	AppComponentDeployment AppComponent = "deployment"
)

type ClusterInfo added in v1.1.0

type ClusterInfo interface {
	CheckRunningInOpenshift(creader client.Reader, ctx context.Context, logger logr.Logger, runningLocally bool) error
	IsOpenshift() bool
	IsRunningLocally() bool
	GetDomain() string
}

func GetClusterInfo added in v1.2.0

func GetClusterInfo() ClusterInfo

type ClusterInfoImp added in v1.1.0

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

func (*ClusterInfoImp) CheckRunningInOpenshift added in v1.1.0

func (c *ClusterInfoImp) CheckRunningInOpenshift(creader client.Reader, ctx context.Context, logger logr.Logger, runningLocally bool) error

func (ClusterInfoImp) GetDomain added in v1.5.0

func (c ClusterInfoImp) GetDomain() string

func (ClusterInfoImp) IsOpenshift added in v1.1.0

func (c ClusterInfoImp) IsOpenshift() bool

func (ClusterInfoImp) IsRunningLocally added in v1.2.0

func (c ClusterInfoImp) IsRunningLocally() bool

type EventEmitter added in v1.2.0

type EventEmitter interface {
	Init(ctx context.Context, mgr manager.Manager, ci ClusterInfo, logger logr.Logger)
	EmitEvent(object runtime.Object, eventType, reason, msg string)
	UpdateClient(ctx context.Context, clnt client.Reader, logger logr.Logger)
}

func GetEventEmitter added in v1.2.0

func GetEventEmitter() EventEmitter

type RunModeType added in v1.3.0

type RunModeType string

Jump to

Keyboard shortcuts

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