From 1a1964bfcf528a5cbf6afcf401df515c2d5d1a58 Mon Sep 17 00:00:00 2001 From: Neelesh Thakur Date: Sun, 11 Aug 2024 08:25:12 -0700 Subject: [PATCH] PWX-38509: vendor in sched-ops (#1636) This is to pull in the fix for kubevirt GetVirtualMachineInstance. --- go.mod | 4 +- go.sum | 4 +- .../portworx/sched-ops/k8s/core/core.go | 11 ++- .../k8s/core/persistentvolumeclaims.go | 10 +- .../k8s/kubevirt-dynamic/kubevirt.go | 21 +++++ .../virtualmachineinstance.go | 94 +++++++++++-------- vendor/modules.txt | 4 +- 7 files changed, 92 insertions(+), 56 deletions(-) diff --git a/go.mod b/go.mod index 12de8bca47..62627ee4d8 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/openshift/api v0.0.0-20230503133300-8bbcb7ca7183 github.com/pborman/uuid v1.2.1 github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b - github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4 + github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2 github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.63.0 github.com/prometheus-operator/prometheus-operator/pkg/client v0.46.0 github.com/sirupsen/logrus v1.9.3 @@ -131,7 +131,7 @@ replace ( github.com/coreos/prometheus-operator => github.com/prometheus-operator/prometheus-operator v0.46.0 github.com/kubernetes-incubator/external-storage => github.com/libopenstorage/external-storage v5.1.1-0.20190919185747-9394ee8dd536+incompatible github.com/libopenstorage/openstorage => github.com/libopenstorage/openstorage v1.0.1-0.20240221210452-7757fdc2b8ff - github.com/portworx/sched-ops => github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4 + github.com/portworx/sched-ops => github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2 github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring => github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.46.0 golang.org/x/tools => golang.org/x/tools v0.1.11 google.golang.org/grpc => google.golang.org/grpc v1.29.1 diff --git a/go.sum b/go.sum index 7f810ceff3..74c9b5a027 100644 --- a/go.sum +++ b/go.sum @@ -4084,8 +4084,8 @@ github.com/portworx/kvdb v0.0.0-20230326003017-21a38cf82d4b/go.mod h1:Q8YyrNDvPp github.com/portworx/px-backup-api v1.0.1-0.20200915150042-274508e876ef/go.mod h1:puy7YVXeb6glot1vVCIePIiRLSwB//+rFtN2ZjvXeEw= github.com/portworx/px-object-controller v0.0.0-20220804234424-40d3b8a84987/go.mod h1:g3pw2lI2AjqAixUCRhaBdKTY98znsCPR7NGRrlpimVU= github.com/portworx/pxc v0.33.0/go.mod h1:Tl7hf4K2CDr0XtxzM08sr9H/KsMhscjf9ydb+MnT0U4= -github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4 h1:+pKJx5jqqxqFrtbOQaGg8Fwl0LrbX71ejZHlc9NZG3I= -github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4/go.mod h1:KOe618gr1FAzVmLNe9LFHss19df3MBZ0qom6Ct7RpyM= +github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2 h1:ZyZs2zfyKwDQPUT61SfauB2rn4HPIdBAXnGTeHRsMu8= +github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2/go.mod h1:KOe618gr1FAzVmLNe9LFHss19df3MBZ0qom6Ct7RpyM= github.com/portworx/talisman v0.0.0-20210302012732-8af4564777f7/go.mod h1:e8a6uFpSbOlRpZQlW9aXYogC+GWAo065G0RL9hDkD4Q= github.com/portworx/torpedo v0.20.4-rc1.0.20210325154352-eb81b0cdd145/go.mod h1:CkLAs/ojTzSu3SPyeDxc3qhsbRU78H5Xz1qJlj1Ap1U= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= diff --git a/vendor/github.com/portworx/sched-ops/k8s/core/core.go b/vendor/github.com/portworx/sched-ops/k8s/core/core.go index 65ada45734..e2d52f913f 100644 --- a/vendor/github.com/portworx/sched-ops/k8s/core/core.go +++ b/vendor/github.com/portworx/sched-ops/k8s/core/core.go @@ -24,11 +24,12 @@ import ( ) const ( - masterLabelKey = "node-role.kubernetes.io/master" - controlplaneLabelKey = "node-role.kubernetes.io/controlplane" - controlDashPlaneLabelKey = "node-role.kubernetes.io/control-plane" - pvcStorageProvisionerKey = "volume.beta.kubernetes.io/storage-provisioner" - labelUpdateMaxRetries = 5 + masterLabelKey = "node-role.kubernetes.io/master" + controlplaneLabelKey = "node-role.kubernetes.io/controlplane" + controlDashPlaneLabelKey = "node-role.kubernetes.io/control-plane" + pvcStorageProvisionerKeyDeprecated = "volume.beta.kubernetes.io/storage-provisioner" + pvcStorageProvisionerKey = "volume.kubernetes.io/storage-provisioner" + labelUpdateMaxRetries = 5 ) var ( diff --git a/vendor/github.com/portworx/sched-ops/k8s/core/persistentvolumeclaims.go b/vendor/github.com/portworx/sched-ops/k8s/core/persistentvolumeclaims.go index d86aab947e..e0baaf3478 100644 --- a/vendor/github.com/portworx/sched-ops/k8s/core/persistentvolumeclaims.go +++ b/vendor/github.com/portworx/sched-ops/k8s/core/persistentvolumeclaims.go @@ -312,16 +312,18 @@ func (c *Client) GetPVCsUsingStorageClass(scName string) ([]corev1.PersistentVol // GetStorageProvisionerForPVC returns storage provisioner for given PVC if it exists func (c *Client) GetStorageProvisionerForPVC(pvc *corev1.PersistentVolumeClaim) (string, error) { // first try to get the provisioner directly from the annotations - provisionerName, present := pvc.Annotations[pvcStorageProvisionerKey] - if present { + provisionerName := pvc.Annotations[pvcStorageProvisionerKey] + if provisionerName != "" { + return provisionerName, nil + } + provisionerName = pvc.Annotations[pvcStorageProvisionerKeyDeprecated] + if provisionerName != "" { return provisionerName, nil } - sc, err := c.GetStorageClassForPVC(pvc) if err != nil { return "", err } - return sc.Provisioner, nil } diff --git a/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/kubevirt.go b/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/kubevirt.go index 6cc66dd18b..076bb70bf1 100644 --- a/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/kubevirt.go +++ b/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/kubevirt.go @@ -241,6 +241,27 @@ func (c *Client) unstructuredFindKeyValInt64( return nil, nil } +// unstructuredGetStringValuesForKey scans the specified slice of maps and returns string values +// for the specified key. +// The input slice members are expected to be of type map[string]interface{}. +func (c *Client) unstructuredGetStringValuesForKey(data []interface{}, key string) ([]string, error) { + var ret []string + for _, rawMap := range data { + typedMap, ok := rawMap.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("wrong type of element in slice: expected map[string]interface{}, actual %T", rawMap) + } + mapVal, found, err := c.unstructuredGetValString(typedMap, key) + if err != nil { + return nil, fmt.Errorf("failed to get key %q in map in the slice", key) + } else if !found { + continue + } + ret = append(ret, mapVal) + } + return ret, nil +} + func (c *Client) unstructuredGetStringAsBool(obj map[string]interface{}, fields ...string) (bool, bool, error) { ret := false val, found, err := unstructured.NestedString(obj, fields...) diff --git a/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/virtualmachineinstance.go b/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/virtualmachineinstance.go index c0ff8eaea7..8d23b286fd 100644 --- a/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/virtualmachineinstance.go +++ b/vendor/github.com/portworx/sched-ops/k8s/kubevirt-dynamic/virtualmachineinstance.go @@ -74,7 +74,10 @@ func (c *Client) GetVirtualMachineInstance( if err != nil { return nil, err } - // Find name of the root disk (one with bootOrder=1) in VMI. Sample yaml: + // Find name of the root disk (one with bootOrder=1) in VMI. If bootOrder is not present, find the first + // PVC or a dataVolume and treat it as a root disk. + // + // Sample yaml: //spec: // domain: // devices: @@ -95,23 +98,23 @@ func (c *Client) GetVirtualMachineInstance( if err != nil || !found || len(disks) == 0 { return nil, fmt.Errorf("failed to find vmi disks: %w", err) } - rootDiskName := "" + var rootDiskCandidates []string bootDisk, err := c.unstructuredFindKeyValInt64(disks, "bootOrder", 1) if err != nil { return nil, fmt.Errorf("failed to find boot disk in vmi: %w", err) } - if bootDisk == nil { - // No "bootOrder" present in the VM spec. Assume that the first disk is the boot disk. - var ok bool - rawMap := disks[0] - bootDisk, ok = rawMap.(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("wrong type of element in slice: expected map[string]interface{}, actual %T", rawMap) + if bootDisk != nil { + rootDiskName, found, err := c.unstructuredGetValString(bootDisk, "name") + if err != nil || !found || rootDiskName == "" { + return nil, fmt.Errorf("failed to find rootDisk name: %w", err) + } + rootDiskCandidates = append(rootDiskCandidates, rootDiskName) + } else { + // no bootOrder. Gather all the disk names. + rootDiskCandidates, err = c.unstructuredGetStringValuesForKey(disks, "name") + if err != nil { + return nil, fmt.Errorf("bootOrder is not present and failed to find disk names: %w", err) } - } - rootDiskName, found, err = c.unstructuredGetValString(bootDisk, "name") - if err != nil || !found || rootDiskName == "" { - return nil, fmt.Errorf("failed to find rootDisk name: %w", err) } // Find name of the PVC in VMI. Sample yaml when dataVolume was used by the VMI: // NOTE: the dataVolume may have been garbage collected after pvc was ready. @@ -125,40 +128,49 @@ func (c *Client) GetVirtualMachineInstance( if err != nil || !found { return nil, fmt.Errorf("failed to find vmi volumes: %w", err) } - pvcName := "" - rootVolume, err := c.unstructuredFindKeyValString(volumes, "name", rootDiskName) - if err != nil || rootVolume == nil { - return nil, fmt.Errorf("failed to find root volume %q in the vmi: %w", rootDiskName, err) - } - - // Check if this is a dataVolume or a pvc - if dataVolumeRaw, ok := rootVolume["dataVolume"]; ok { - dataVolume, ok := dataVolumeRaw.(map[string]interface{}) - if !ok { - return nil, fmt.Errorf( - "wrong type for vmi dataVolume: expected map[string]interface{}, actual %T", dataVolumeRaw) + var rootDiskName, pvcName string + for _, rootDiskCandidate := range rootDiskCandidates { + rootVolume, err := c.unstructuredFindKeyValString(volumes, "name", rootDiskCandidate) + if err != nil { + // malformed data + return nil, fmt.Errorf("failed to get root disk candidate %q from the volumes section of vmi: %w", + rootDiskCandidate, err) } - name, found, err := c.unstructuredGetValString(dataVolume, "name") - if err != nil || !found { - return nil, fmt.Errorf("failed to get name of the rootdisk data volume: %w", err) + if rootVolume == nil { + continue } - // pvc name is always same as the data volume name - pvcName = name - } else if pvcRaw, ok := rootVolume["persistentVolumeClaim"]; ok { - pvc, ok := pvcRaw.(map[string]interface{}) - if !ok { - return nil, fmt.Errorf("wrong type for vmi pvc: expected map[string]interface{}, actual %T", pvcRaw) + // Check if this is a dataVolume or a pvc + if dataVolumeRaw, ok := rootVolume["dataVolume"]; ok { + dataVolume, ok := dataVolumeRaw.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf( + "wrong type for vmi dataVolume: expected map[string]interface{}, actual %T", dataVolumeRaw) + } + name, found, err := c.unstructuredGetValString(dataVolume, "name") + if err != nil || !found { + return nil, fmt.Errorf( + "failed to get dataVolume name for root disk candidate %q: %w", rootDiskCandidate, err) + } + // pvc name is always same as the data volume name + pvcName = name + } else if pvcRaw, ok := rootVolume["persistentVolumeClaim"]; ok { + pvc, ok := pvcRaw.(map[string]interface{}) + if !ok { + return nil, fmt.Errorf("wrong type for vmi pvc: expected map[string]interface{}, actual %T", pvcRaw) + } + name, found, err := c.unstructuredGetValString(pvc, "claimName") + if err != nil || !found { + return nil, fmt.Errorf("failed to get PVC name for root disk candidate %q: %w", rootDiskCandidate, err) + } + pvcName = name } - name, found, err := c.unstructuredGetValString(pvc, "claimName") - if err != nil || !found { - return nil, fmt.Errorf("failed to get name of the rootdisk pvc: %w", err) + if pvcName != "" { + rootDiskName = rootDiskCandidate + break } - pvcName = name - } else { - return nil, fmt.Errorf("root volume is neither a dataVolume nor a pvc") } if pvcName == "" { - return nil, fmt.Errorf("empty pvc name for the root disk") + return nil, fmt.Errorf("could not find a PVC or a dataVolume among VM disks %v", rootDiskCandidates) } // check if the VMI is live migratable and ready diff --git a/vendor/modules.txt b/vendor/modules.txt index ed74e0d3d2..631ddb0060 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -304,7 +304,7 @@ github.com/portworx/kvdb/etcd/common github.com/portworx/kvdb/etcd/v2 github.com/portworx/kvdb/etcd/v3 github.com/portworx/kvdb/mem -# github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4 => github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4 +# github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2 => github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2 ## explicit; go 1.19 github.com/portworx/sched-ops/k8s/apiextensions github.com/portworx/sched-ops/k8s/apps @@ -1044,7 +1044,7 @@ sigs.k8s.io/yaml/goyaml.v2 # github.com/coreos/prometheus-operator => github.com/prometheus-operator/prometheus-operator v0.46.0 # github.com/kubernetes-incubator/external-storage => github.com/libopenstorage/external-storage v5.1.1-0.20190919185747-9394ee8dd536+incompatible # github.com/libopenstorage/openstorage => github.com/libopenstorage/openstorage v1.0.1-0.20240221210452-7757fdc2b8ff -# github.com/portworx/sched-ops => github.com/portworx/sched-ops v1.20.4-rc1.0.20240613172635-81b5b390baf4 +# github.com/portworx/sched-ops => github.com/portworx/sched-ops v1.20.4-rc1.0.20240731224434-94e4e354c4b2 # github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring => github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.46.0 # golang.org/x/tools => golang.org/x/tools v0.1.11 # google.golang.org/grpc => google.golang.org/grpc v1.29.1