utils

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 37 Imported by: 2

Documentation

Overview

Copyright 2022/9/2 Alibaba Cloud.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2022/8/26 Alibaba Cloud.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2022/9/6 Alibaba Cloud.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2022/8/27 Alibaba Cloud.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	Cgroupfs CgroupDriverType = "cgroupfs"
	Systemd  CgroupDriverType = "systemd"

	KubeRootNameSystemd       = "kubepods.slice/"
	KubeBurstableNameSystemd  = "kubepods-burstable.slice/"
	KubeBesteffortNameSystemd = "kubepods-besteffort.slice/"

	KubeRootNameCgroupfs       = "kubepods/"
	KubeBurstableNameCgroupfs  = "burstable/"
	KubeBesteffortNameCgroupfs = "besteffort/"
)
View Source
const (
	DefaultNodeAffinityWeight int = 5
	MinScore                  int = 0
	MaxScore                  int = 10
)
View Source
const (
	// General
	LocalGi        uint64 = 1024 * 1024 * 1024
	LocalMi        uint64 = 1024 * 1024
	TestPort       int32  = 23000
	LocalNameSpace string = "default"
	// Node
	NodeName1 string = "node-192.168.0.1"
	NodeName2 string = "node-192.168.0.2"
	NodeName3 string = "node-192.168.0.3"
	NodeName4 string = "node-192.168.0.4"

	//Pod
	InvolumePodName string = "involume_pod"

	// VG
	VGSSD string = "ssd"
	VGHDD string = "hdd"
	// StorageClass
	SCLVMWithVG    string = "sc-vg"
	SCLVMWithoutVG string = "sc-novg"
	SCWithMP       string = "sc-mp"
	SCWithDevice   string = "sc-device"
	SCNoLocal      string = "sc-nolocal"
	// PVC
	PVCWithVG         string = "pvc-vg"
	PVCWithoutVG      string = "pvc-novg"
	PVCSnapshot       string = "pvc-snapshot"
	PVCWithVGError    string = "pvc-vg-error"
	PVCWithMountPoint string = "pvc-mp"
	PVCWithDevice     string = "pvc-device"
	PVCNoLocal        string = "pvc-nolocal"
	// Pod
	TestPodName string = "testpod"
)

Variables

View Source
var CgroupPathFormatter = cgroupPathFormatterInSystemd

default use Systemd cgroup path format

Functions

func CheckMountPointOptions

func CheckMountPointOptions(mp *nodelocalstorage.MountPoint) bool

CheckDiskOptions excludes mp which is readyonly or with unsupported fs type

func ContainInlineVolumes added in v0.5.0

func ContainInlineVolumes(pod *corev1.Pod) (contain bool, node string)

func ContainsProvisioner

func ContainsProvisioner(name string) bool

func ContainsString

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

Contains method for a slice

func CreateNode added in v0.6.0

func CreateNode(nodeInfo *TestNodeInfo) *corev1.Node

func CreatePVsBound added in v0.6.0

func CreatePVsBound() []*corev1.PersistentVolume

func CreatePod added in v0.6.0

func CreatePod(podInfo *TestPodInfo) *corev1.Pod

func CreateTestNodeLocalStorage added in v0.6.0

func CreateTestNodeLocalStorage() (crds []*localv1alpha1.NodeLocalStorage)

func CreateTestNodeLocalStorage1 added in v0.6.0

func CreateTestNodeLocalStorage1() *localv1alpha1.NodeLocalStorage

func CreateTestNodeLocalStorage2 added in v0.6.0

func CreateTestNodeLocalStorage2() *localv1alpha1.NodeLocalStorage

func CreateTestNodeLocalStorage3 added in v0.6.0

func CreateTestNodeLocalStorage3() *localv1alpha1.NodeLocalStorage

func CreateTestNodeLocalStorage4 added in v0.6.0

func CreateTestNodeLocalStorage4() *localv1alpha1.NodeLocalStorage

func CreateTestPersistentVolume added in v0.6.0

func CreateTestPersistentVolume(pvInfos []TestPVInfo) (pvs []*corev1.PersistentVolume)

func CreateTestPersistentVolumeClaim added in v0.6.0

func CreateTestPersistentVolumeClaim(pvcInfos []TestPVCInfo) (pvcs []*corev1.PersistentVolumeClaim)

func CreateTestStorageClass added in v0.6.0

func CreateTestStorageClass() (scs []*storagev1.StorageClass)

func CreateVolumeSnapshot added in v0.7.0

func CreateVolumeSnapshot(info *TestVolumeSnapshotInfo) *volumesnapshotv1.VolumeSnapshot

func CreateVolumeSnapshotClass added in v0.7.0

func CreateVolumeSnapshotClass(info *TestVolumeSnapshotClassInfo) *volumesnapshotv1.VolumeSnapshotClass

func EnsureBlock added in v0.6.0

func EnsureBlock(target string) error

func Format

func Format(source, fsType string) error

Format formats the source with the given filesystem type

func FormatBlockDevice added in v0.6.0

func FormatBlockDevice(dev, fsType string) error

func FsInfo added in v0.7.0

func FsInfo(path string) (int64, int64, int64, int64, int64, int64, error)

FsInfo linux returns (available bytes, byte capacity, byte usage, total inodes, inodes free, inode usage, error) for the filesystem that path resides upon.

func GeneratePVPatch added in v0.6.0

func GeneratePVPatch(oldPV, newPV *corev1.PersistentVolume) ([]byte, error)

func GeneratePodPatch added in v0.6.0

func GeneratePodPatch(oldPod, newPod *corev1.Pod) ([]byte, error)

func GetAccessModes added in v0.6.0

func GetAccessModes(caps []*csilib.VolumeCapability) *[]string

GetAccessModes returns a slice containing all of the access modes defined in the passed in VolumeCapabilities.

func GetAddedAndRemovedItems

func GetAddedAndRemovedItems(newList, oldList []string) (addedItems, unchangedItems, removedItems []string)

func GetClusterID added in v0.7.0

func GetClusterID(kubeclient kubernetes.Interface) (string, error)

func GetDeviceNameFromCsiPV

func GetDeviceNameFromCsiPV(pv *corev1.PersistentVolume) string

GetDeviceNameFromCsiPV extracts Device Name from open-local csi PV via VolumeAttributes

func GetInlineVolumeInfoFromParam added in v0.5.0

func GetInlineVolumeInfoFromParam(attributes map[string]string) (vgName string, size int64)

func GetMetrics

func GetMetrics(path string) (*csilib.NodeGetVolumeStatsResponse, error)

GetMetrics get path metric

func GetMountPointFromCsiPV

func GetMountPointFromCsiPV(pv *corev1.PersistentVolume) string

GetMountPointFromCsiPV extracts MountPoint from open-local csi PV via VolumeAttributes

func GetName added in v0.7.1

func GetName(meta metav1.ObjectMeta) string

func GetNameKey added in v0.7.1

func GetNameKey(nameSpace, name string) string

func GetNodeNameFromCsiPV added in v0.6.0

func GetNodeNameFromCsiPV(pv *corev1.PersistentVolume) string

func GetPVCRequested

func GetPVCRequested(pvc *corev1.PersistentVolumeClaim) int64

func GetPVFromBoundPVC

func GetPVFromBoundPVC(pvc *corev1.PersistentVolumeClaim) (name string)

func GetPVSize

func GetPVSize(pv *corev1.PersistentVolume) int64

func GetPVStorageSize

func GetPVStorageSize(pv *corev1.PersistentVolume) int64

func GetVGNameFromCsiPV

func GetVGNameFromCsiPV(pv *corev1.PersistentVolume) string

GetVGNameFromCsiPV extracts vgName from open-local csi PV via VolumeAttributes

func GetVGRequested

func GetVGRequested(localPVs map[string]corev1.PersistentVolume, vgName string) (requested int64)

func GetVolumeSnapshotContent added in v0.7.0

func GetVolumeSnapshotContent(snapclient snapshot.Interface, snapshotContentID string) (*snapshotapi.VolumeSnapshotContent, error)

func HashSpec

func HashSpec(storage *nodelocalstorage.NodeLocalStorage) uint64

func HashStorageSpec

func HashStorageSpec(obj interface{}) uint64

func HashWithoutState

func HashWithoutState(storage *nodelocalstorage.NodeLocalStorage) uint64

HashWithoutState remove the state field then compare

func HttpJSON

func HttpJSON(w http.ResponseWriter, code int, result interface{})

func HttpResponse

func HttpResponse(w http.ResponseWriter, code int, msg []byte)

func IsBlockDevice added in v0.6.0

func IsBlockDevice(fullPath string) (bool, error)

IsBlockDevice checks if the given path is a block device

func IsEmpty

func IsEmpty(r string) bool

func IsLocalPV

func IsLocalPV(pv *corev1.PersistentVolume) (isLocalPV bool, node string)

func IsOpenLocalPV added in v0.2.2

func IsOpenLocalPV(pv *corev1.PersistentVolume) (bool, localtype.VolumeType)

func IsPodNeedAllocate added in v0.6.0

func IsPodNeedAllocate(pod *corev1.Pod) bool

func IsReadOnlyPV added in v0.7.0

func IsReadOnlyPV(pv *corev1.PersistentVolume) bool

func IsReadOnlySnapshotPVC added in v0.7.0

func IsReadOnlySnapshotPVC(claim *corev1.PersistentVolumeClaim, snapInformer volumesnapshotinformers.Interface) bool

func IsReadOnlySnapshotPVC2 added in v0.7.0

func IsReadOnlySnapshotPVC2(claim *corev1.PersistentVolumeClaim, snapClient snapshot.Interface) bool

func IsSnapshotClassReadOnly added in v0.7.0

func IsSnapshotClassReadOnly(className string, snapInformer volumesnapshotinformers.Interface) bool

func IsSnapshotClassReadOnly2 added in v0.7.0

func IsSnapshotClassReadOnly2(className string, snapClient snapshot.Interface) bool

func LocalPVType added in v0.2.2

func LocalPVType(sc *storagev1.StorageClass) localtype.VolumeType

func MountBlock added in v0.6.0

func MountBlock(source, target string, opts ...string) error

func NeedSkip added in v0.3.0

func NeedSkip(args schedulerapi.ExtenderArgs) bool

func NodeNameFromPV added in v0.6.0

func NodeNameFromPV(pv *corev1.PersistentVolume) string

func NodeNameFromPVC added in v0.6.0

func NodeNameFromPVC(pvc *corev1.PersistentVolumeClaim) string

func PVCName

func PVCName(storageObj interface{}) string

func PVCNameFromPV added in v0.6.0

func PVCNameFromPV(pv *corev1.PersistentVolume) (pvcName, pvcNamespace string)

func ParseWeight added in v0.6.0

func ParseWeight(nodeAntiAffinity string) (weights *pkg.NodeAntiAffinityWeight, err error)

func PatchAllocateInfoToPV added in v0.6.0

func PatchAllocateInfoToPV(ctx context.Context, kubeclientset kubernetes.Interface, originPV *corev1.PersistentVolume, pvAllocatedInfo *localtype.PVAllocatedInfo) error

func PodPvcAllowReschedule

func PodPvcAllowReschedule(pvcs []*corev1.PersistentVolumeClaim, fakeNow *time.Time) bool

PodPvcAllowReschedule returns true if any of pvcs has in pending status for more than 5 minutes the fakeNow is parameter for unit testing

func PvcContainsSelectedNode

func PvcContainsSelectedNode(pvc *corev1.PersistentVolumeClaim) bool

func Run

func Run(cmd string) (string, error)

Run run shell command

func SetupCgroupPathFormatter added in v0.6.0

func SetupCgroupPathFormatter(driver CgroupDriverType)

func SliceEquals

func SliceEquals(src interface{}, dst interface{}) bool

func StringsContains

func StringsContains(array []string, val string) (index int)

StringsContains check val exist in array

func TimeTrack added in v0.7.0

func TimeTrack(start time.Time, name string)

func WordSepNormalizeFunc

func WordSepNormalizeFunc(f *pflag.FlagSet, name string) pflag.NormalizedName

WordSepNormalizeFunc changes all flags that contain "_" separators

Types

type CgroupDriverType added in v0.6.0

type CgroupDriverType string

func (CgroupDriverType) Validate added in v0.6.0

func (c CgroupDriverType) Validate() bool

type CommandRunFunc

type CommandRunFunc func(cmd string) (string, error)

CommandRunFunc define the run function in utils for ut

type TestInlineVolumeInfo added in v0.6.0

type TestInlineVolumeInfo struct {
	VolumeName string
	VolumeSize string
	VgName     string
}

type TestNodeInfo added in v0.6.0

type TestNodeInfo struct {
	NodeName  string
	IPAddress string
}

type TestPVCInfo added in v0.6.0

type TestPVCInfo struct {
	PVCName      string
	PVCNameSpace string
	Size         string
	SCName       string
	VolumeName   string
	NodeName     string
	PVCStatus    corev1.PersistentVolumeClaimPhase

	IsSnapshot    bool
	SnapName      string
	SourcePVCName string
}

type TestPVCPVInfo added in v0.6.0

type TestPVCPVInfo struct {
	PVCPending  *TestPVCInfo
	PVCBounding *TestPVCInfo
	PVBounding  *TestPVInfo
}

func GetTestPVCPVDevice added in v0.6.0

func GetTestPVCPVDevice() *TestPVCPVInfo

func GetTestPVCPVNotLocal added in v0.6.0

func GetTestPVCPVNotLocal() *TestPVCPVInfo

func GetTestPVCPVSnapshot added in v0.6.0

func GetTestPVCPVSnapshot() *TestPVCPVInfo

func GetTestPVCPVWithVG added in v0.6.0

func GetTestPVCPVWithVG() *TestPVCPVInfo

func GetTestPVCPVWithoutVG added in v0.6.0

func GetTestPVCPVWithoutVG() *TestPVCPVInfo

func (*TestPVCPVInfo) SetSize added in v0.6.0

func (info *TestPVCPVInfo) SetSize(size string)

type TestPVCPVInfoList added in v0.6.0

type TestPVCPVInfoList []*TestPVCPVInfo

func (TestPVCPVInfoList) GetTestPVBounding added in v0.6.0

func (list TestPVCPVInfoList) GetTestPVBounding() []TestPVInfo

func (TestPVCPVInfoList) GetTestPVCBounding added in v0.6.0

func (list TestPVCPVInfoList) GetTestPVCBounding() []TestPVCInfo

func (TestPVCPVInfoList) GetTestPVCPending added in v0.6.0

func (list TestPVCPVInfoList) GetTestPVCPending() []TestPVCInfo

type TestPVInfo added in v0.6.0

type TestPVInfo struct {
	VolumeName string
	VolumeSize string
	VolumeType string
	VgName     string
	DeviceName string
	NodeName   string
	ClaimRef   *corev1.ObjectReference
	PVStatus   corev1.PersistentVolumePhase
	IsSnapshot bool
	IsLocalPV  bool
}

type TestPodInfo added in v0.6.0

type TestPodInfo struct {
	PodName      string
	PodNameSpace string
	NodeName     string
	PodStatus    corev1.PodPhase

	PVCInfos          []*TestPVCInfo
	InlineVolumeInfos []*TestInlineVolumeInfo
}

type TestVolumeSnapshotClassInfo added in v0.7.0

type TestVolumeSnapshotClassInfo struct {
	Name       string
	Parameters map[string]string
}

type TestVolumeSnapshotInfo added in v0.7.0

type TestVolumeSnapshotInfo struct {
	SnapshotName      string
	SnapshotClassName string
	SrcPVCName        string
}

Directories

Path Synopsis
Package jsonrpc implements a JSON-RPC 1.0 ClientCodec and ServerCodec for the rpc package.
Package jsonrpc implements a JSON-RPC 1.0 ClientCodec and ServerCodec for the rpc package.

Jump to

Keyboard shortcuts

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