util

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: Apache-2.0 Imports: 39 Imported by: 1

Documentation

Index

Constants

View Source
const (
	RemovedPVCsAnnotationKey            = prefix + "/removedPersistentVolumeClaims"
	AdditionalCASecretName              = "cloudweav-additional-ca"
	AdditionalCAFileName                = "additional-ca.pem"
	AnnotationMigrationTarget           = prefix + "/migrationTargetNodeName"
	AnnotationMigrationUID              = prefix + "/migrationUID"
	AnnotationMigrationState            = prefix + "/migrationState"
	AnnotationTimestamp                 = prefix + "/timestamp"
	AnnotationVolumeClaimTemplates      = prefix + "/volumeClaimTemplates"
	AnnotationUpgradePatched            = prefix + "/upgrade-patched"
	AnnotationImageID                   = prefix + "/imageId"
	AnnotationReservedMemory            = prefix + "/reservedMemory"
	AnnotationHash                      = prefix + "/hash"
	AnnotationRunStrategy               = prefix + "/vmRunStrategy"
	AnnotationSnapshotFreezeFS          = prefix + "/snapshotFreezeFS"
	AnnotationSVMBackupID               = prefix + "/svmbackupId"
	AnnotationSVMBackupSkipCronCheck    = prefix + "/svmbackupSkipCronCheck"
	LabelImageDisplayName               = prefix + "/imageDisplayName"
	LabelSetting                        = prefix + "/setting"
	LabelVMName                         = prefix + "/vmName"
	LabelSVMBackupUID                   = prefix + "/svmbackupUID"
	LabelSVMBackupTimestamp             = prefix + "/svmbackupTimestamp"
	LabelVMCreator                      = prefix + "/creator"
	LabelNodeNameKey                    = "kubevirt.io/nodeName"
	AnnotationStorageClassName          = prefix + "/storageClassName"
	AnnotationStorageProvisioner        = prefix + "/storageProvisioner"
	AnnotationIsDefaultStorageClassName = "storageclass.kubernetes.io/is-default-class"

	// AnnotationMigratingPrefix is used to store the migrating vm in the annotation of ResourceQuota
	// eg: cloudweavhci.io/migrating-vm1: jsonOfResourceList, cloudweavhci.io/migrating-vm2: jsonOfResourceList
	AnnotationMigratingPrefix = prefix + "/migrating-"

	// AnnotationInsufficientResourceQuota is indicated the resource is insufficient of Namespace
	AnnotationInsufficientResourceQuota = prefix + "/insufficient-resource-quota"

	AnnotationDefaultUserdataSecret = prefix + "/default-userdata-secret"

	// Add to rancher-monitoring addon to record grafana pv name
	AnnotationGrafanaPVName = prefix + "/grafana-pv-name"

	// Add to cloudweav-longhorn storageclass to protect it
	// For any storageclass created & protected by controller, the controller can utilize this annotation
	AnnotationIsReservedStorageClass = prefix + "/is-reserved-storageclass"

	ContainerdRegistrySecretName = "cloudweav-containerd-registry"
	ContainerdRegistryFileName   = "registries.yaml"

	BackupTargetSecretName              = "cloudweav-backup-target-secret"
	InternalTLSSecretName               = "tls-rancher-internal"
	Rke2IngressNginxAppName             = "rke2-ingress-nginx"
	CattleSystemNamespaceName           = "cattle-system"
	CattleMonitoringSystemNamespace     = "cattle-monitoring-system"
	LonghornSystemNamespaceName         = "longhorn-system"
	LonghornDefaultManagerURL           = "http://longhorn-backend.longhorn-system:9500/v1"
	KubeSystemNamespace                 = "kube-system"
	FleetLocalNamespaceName             = "fleet-local"
	LocalClusterName                    = "local"
	CloudweavSystemNamespaceName        = "cloudweav-system"
	RancherLoggingName                  = "rancher-logging"
	RancherMonitoringPrometheus         = "rancher-monitoring-prometheus"
	RancherMonitoringAlertmanager       = "rancher-monitoring-alertmanager"
	RancherMonitoring                   = "rancher-monitoring"
	RancherMonitoringGrafana            = "rancher-monitoring-grafana"
	CattleLoggingSystemNamespaceName    = "cattle-logging-system"
	CloudweavUpgradeImageRepository     = "rancher/cloudweav-upgrade"
	GrafanaPVCName                      = "rancher-monitoring-grafana"
	RancherMonitoringName               = "rancher-monitoring"
	CattleMonitoringSystemNamespaceName = "cattle-monitoring-system"
	CloudweavVMImportController         = "vm-import-controller-cloudweav-vm-import-controller"
	// kubevirt create a CRD object automatically: type kubevirt, name kubevirt, namespace: cloudweav-system
	// this object stores all kubevirt related configuration
	KubeVirtObjectName = "kubevirt"

	HTTPProxyEnv  = "HTTP_PROXY"
	HTTPSProxyEnv = "HTTPS_PROXY"
	NoProxyEnv    = "NO_PROXY"

	LonghornOptionBackingImageName           = "backingImage"
	LonghornOptionBackingImageDataSourceName = "backingImageDataSourceType"
	LonghornOptionMigratable                 = "migratable"
	LonghornOptionEncrypted                  = "encrypted"
	AddonValuesAnnotation                    = "cloudweavhci.io/addon-defaults"

	// CSI constants
	CSIProvisionerSecretNameKey      = "csi.storage.k8s.io/provisioner-secret-name"
	CSIProvisionerSecretNamespaceKey = "csi.storage.k8s.io/provisioner-secret-namespace"
	CSINodePublishSecretNameKey      = "csi.storage.k8s.io/node-publish-secret-name"
	CSINodePublishSecretNamespaceKey = "csi.storage.k8s.io/node-publish-secret-namespace"
	CSINodeStageSecretNameKey        = "csi.storage.k8s.io/node-stage-secret-name"
	CSINodeStageSecretNamespaceKey   = "csi.storage.k8s.io/node-stage-secret-namespace"

	LabelUpgradeReadMessage          = prefix + "/read-message"
	LabelUpgradeState                = prefix + "/upgradeState"
	UpgradeStateLoggingInfraPrepared = "LoggingInfraPrepared"

	AnnotationArchiveName                 = prefix + "/archiveName"
	LabelUpgradeLog                       = prefix + "/upgradeLog"
	LabelUpgradeLogComponent              = prefix + "/upgradeLogComponent"
	UpgradeLogInfraComponent              = "infra"
	UpgradeLogShipperComponent            = "shipper"
	UpgradeLogAggregatorComponent         = "aggregator"
	UpgradeLogDownloaderComponent         = "downloader"
	UpgradeLogFlowComponent               = "clusterflow"
	UpgradeLogArchiveComponent            = "log-archive"
	UpgradeLogOperatorComponent           = "operator"
	UpgradeLogOutputComponent             = "clusteroutput"
	UpgradeLogPackagerComponent           = "packager"
	AnnotationUpgradeLogLogArchiveAltName = prefix + "/logArchiveAltName"

	UpgradeNodeDrainTaintKey   = "kubevirt.io/drain"
	UpgradeNodeDrainTaintValue = "draining"

	FieldCattlePrefix             = "field.cattle.io"
	CattleAnnotationResourceQuota = FieldCattlePrefix + "/resourceQuota"

	ManagementCattlePrefix                   = "management.cattle.io"
	LabelManagementDefaultResourceQuota      = "resourcequota." + ManagementCattlePrefix + "/default-resource-quota"
	DefaultFleetControllerConfigMapName      = "fleet-controller"
	DefaultFleetControllerConfigMapNamespace = "cattle-fleet-system"
	RancherInternalCASetting                 = "internal-cacerts"
	RancherInternalServerURLSetting          = "internal-server-url"
	APIServerURLKey                          = "apiServerURL"
	APIServerCAKey                           = "apiServerCA"

	RKEControlPlaneRoleLabel = "rke.cattle.io/control-plane-role"

	LabelMaintainModeStrategy                          = prefix + "/maintain-mode-strategy"
	AnnotationMaintainModeStrategyNodeName             = prefix + "/maintain-mode-strategy-node-name"
	MaintainModeStrategyMigrate                        = "Migrate"
	MaintainModeStrategyShutdownAndRestartAfterEnable  = "ShutdownAndRestartAfterEnable"
	MaintainModeStrategyShutdownAndRestartAfterDisable = "ShutdownAndRestartAfterDisable"
	MaintainModeStrategyShutdown                       = "Shutdown"

	// s3 backup target constants
	AWSAccessKey       = "AWS_ACCESS_KEY_ID"
	AWSSecretKey       = "AWS_SECRET_ACCESS_KEY"
	AWSEndpoints       = "AWS_ENDPOINTS"
	AWSCERT            = "AWS_CERT"
	VirtualHostedStyle = "VIRTUAL_HOSTED_STYLE"

	DefaultResourceQuotaName = "default-resource-quota"

	AnnotationCPUManagerUpdateStatus = prefix + "/cpu-manager-update-status"
	LabelCPUManagerUpdateNode        = prefix + "/cpu-manager-update-node"
	LabelCPUManagerUpdatePolicy      = prefix + "/cpu-manager-update-policy"
	LabelCPUManagerExitCode          = prefix + "/cpu-manager-exit-code"

	VClusterNamespace          = "rancher-vcluster"
	LablelVClusterAppNameKey   = "app"
	LablelVClusterAppNameValue = "vcluster"

	StorageClassCloudweavLonghorn = "cloudweav-longhorn" // the initial & default storageclass
	CloudweavChartReleaseName     = "cloudweav"          // the release name

	// copied from helm pkg/action/validate.go
	HelmReleaseNameAnnotation      = "meta.helm.sh/release-name"
	HelmReleaseNamespaceAnnotation = "meta.helm.sh/release-namespace"

	// moved from nodedrain_controller for public usage
	ContainerDiskOrCDRomKey             = "CDRomOrContainerDiskPresent"
	NodeSchedulingRequirementsNotMetKey = "NodeSchedulingRequirementsNotMet"
	MaintainModeStrategyKey             = "MaintainModeStrategy"
	LastHealthyReplicaKey               = "LastHealthyReplica"
)
View Source
const (
	AnnStorageProvisioner     = "volume.kubernetes.io/storage-provisioner"
	AnnBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
	LonghornDataLocality      = "dataLocality"
)
View Source
const (
	StatusReasonStillExists metav1.StatusReason = "StillExists"
)
View Source
const (
	VMImageMetadataFolderPath = "cloudweav/vmimages/"
)

Variables

View Source
var (
	PersistentVolumeClaimsKind = schema.GroupVersionKind{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"}
)

Functions

func AddBuiltInNoProxy

func AddBuiltInNoProxy(noProxy string) string

func AddFinalizer

func AddFinalizer(obj metav1.Object, finalizer string)

func CalculateCronOffset added in v1.4.0

func CalculateCronOffset(svmbackup1, svmbackup2 *cloudweavv1.ScheduleVMBackup) (time.Duration, error)

func ConstructEndpoint added in v1.4.0

func ConstructEndpoint(target *settings.BackupTarget) string

func ContainsFinalizer

func ContainsFinalizer(obj metav1.Object, finalizer string) bool

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte

EncodePrivateKeyToPEM encodes Private Key from RSA to PEM format

func EncodeVars

func EncodeVars(vars map[string]string) map[string]string

func GeneratePrivateKey

func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)

GeneratePrivateKey creates a RSA Private Key of specified byte size

func GeneratePublicKey

func GeneratePublicKey(publicKey *rsa.PublicKey) ([]byte, error)

GeneratePublicKey take a rsa.PublicKey and return bytes suitable for writing to .pub file returns in the format "ssh-rsa ..."

func GetBackingImage

func GetBackingImage(backingImageCache ctllhv1.BackingImageCache, image *cloudweavv1.VirtualMachineImage) (*v1beta2.BackingImage, error)

func GetBackingImageDataSourceName

func GetBackingImageDataSourceName(backingImageCache ctllhv1.BackingImageCache, image *cloudweavv1.VirtualMachineImage) (string, error)

func GetBackingImageName

func GetBackingImageName(backingImageCache ctllhv1.BackingImageCache, image *cloudweavv1.VirtualMachineImage) (string, error)

func GetBackupStoreDriver added in v1.4.0

func GetBackupStoreDriver(secretCache ctlcorev1.SecretCache, target *settings.BackupTarget) (backupstore.BackupStoreDriver, error)

func GetCronGranularity added in v1.4.0

func GetCronGranularity(svmbackup *cloudweavv1.ScheduleVMBackup) (time.Duration, error)

func GetImageDefaultStorageClassParameters

func GetImageDefaultStorageClassParameters() map[string]string

func GetImageStorageClassName

func GetImageStorageClassName(imageName string) string

func GetImageStorageClassParameters

func GetImageStorageClassParameters(backingImageCache ctllhv1.BackingImageCache, image *cloudweavv1.VirtualMachineImage) (map[string]string, error)

func GetProvisionedPVCProvisioner

func GetProvisionedPVCProvisioner(pvc *corev1.PersistentVolumeClaim) string

GetProvisionedPVCProvisioner do not use this function when the PVC is just created

func GetVMImageMetadataFilePath added in v1.4.0

func GetVMImageMetadataFilePath(vmImageNamespace, vmImageName string) string

func GetValue

func GetValue(data map[string]interface{}, keys ...string) (interface{}, bool)

GetValue retrieve value from map[string]interface{} by keys example: GetValue(map[string]interface{}{"a": map[string]interface{}{"b": "c"}}, "a", "b") -> "c"

func GetWranglerFinalizerName added in v1.4.0

func GetWranglerFinalizerName(controllerName string) string

func IsBackupTargetSame added in v1.4.0

func IsBackupTargetSame(statusBackupTarget *cloudweavv1.BackupTarget, target *settings.BackupTarget) bool

func IsRetriableNetworkError

func IsRetriableNetworkError(err error) bool

func IsStillExists

func IsStillExists(err error) bool

func LoadCSIDriverConfig

func LoadCSIDriverConfig(settingCache ctlcloudweavv1.SettingCache) (map[string]settings.CSIDriverInfo, error)

LoadCSIDriverConfig loads the CSI driver configuration from settings.

func NewStillExists

func NewStillExists(qualifiedResource schema.GroupResource, name string) *apierrors.StatusError

func ReGenerateNTPServers

func ReGenerateNTPServers(ntpSettings *NTPSettings) string

func RemoveFinalizer

func RemoveFinalizer(obj metav1.Object, finalizer string)

func ResolveSVMBackupRef added in v1.4.0

func ResolveSVMBackupRef(svmbackupCache ctlcloudweavv1.ScheduleVMBackupCache, obj metav1.Object) *cloudweavv1.ScheduleVMBackup

func ResponseBody

func ResponseBody(obj interface{}) []byte

func ResponseError

func ResponseError(rw http.ResponseWriter, statusCode int, err error)

func ResponseErrorMsg

func ResponseErrorMsg(rw http.ResponseWriter, statusCode int, errMsg string)

func ResponseOK

func ResponseOK(rw http.ResponseWriter)

func ResponseOKWithBody

func ResponseOKWithBody(rw http.ResponseWriter, obj interface{})

func SkipCronGranularityCheck added in v1.4.0

func SkipCronGranularityCheck(svmbackup *cloudweavv1.ScheduleVMBackup) bool

func VirtClientUpdateVmi

func VirtClientUpdateVmi(ctx context.Context, client rest.Interface, managementNamespace, namespace, name string, obj runtime.Object) error

Types

type HTTPProxyConfig

type HTTPProxyConfig struct {
	HTTPProxy  string `json:"httpProxy,omitempty"`
	HTTPSProxy string `json:"httpsProxy,omitempty"`
	NoProxy    string `json:"noProxy,omitempty"`
}

type NTPSettings

type NTPSettings struct {
	NTPServers []string `json:"ntpServers,omitempty"`
}

Jump to

Keyboard shortcuts

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