Jelajahi Sumber

fix k3s local volume name detection

Nikolay Sivko 2 tahun lalu
induk
melakukan
bc1e161abb
3 mengubah file dengan 7 tambahan dan 3 penghapusan
  1. 1 1
      common/volumes.go
  2. 4 0
      common/volumes_test.go
  3. 2 2
      node/disk.go

+ 1 - 1
common/volumes.go

@@ -5,7 +5,7 @@ import (
 )
 
 var (
-	k8sVolumeDir = regexp.MustCompile(`.+/(volumes/kubernetes.io~([^/]+)|volume-subpaths)/([^/]+)`)
+	k8sVolumeDir = regexp.MustCompile(`.+/(volumes/kubernetes.io~([^/]+)|volume-subpaths|k3s/storage)/(pvc-[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})`)
 )
 
 func ParseKubernetesVolumeSource(source string) string {

+ 4 - 0
common/volumes_test.go

@@ -14,6 +14,10 @@ func TestParseKubernetesVolumeSource(t *testing.T) {
 		"pvc-0307b722-e448-4d73-9d75-091ebf367264",
 		ParseKubernetesVolumeSource("/var/lib/kubelet/pods/adf669ca-c3f8-49de-9ad4-9dd66721dc0d/volume-subpaths/pvc-0307b722-e448-4d73-9d75-091ebf367264/pg/0"),
 	)
+	assert.Equal(t,
+		"pvc-d0c0cc92-ef36-4b4f-90c0-5c5ed489df0b",
+		ParseKubernetesVolumeSource("/var/lib/rancher/k3s/storage/pvc-d0c0cc92-ef36-4b4f-90c0-5c5ed489df0b_default_mongod-data-mongo-psmdb-db-rs0-0"))
+
 	assert.Equal(t,
 		"",
 		ParseKubernetesVolumeSource("/var/lib/kubelet/pods/adf669ca-c3f8-49de-9ad4-9dd66721dc0d/volumes/kubernetes.io~projected/kube-api-access-jvvq6"),

+ 2 - 2
node/disk.go

@@ -1,8 +1,8 @@
 package node
 
 import (
-	"io/ioutil"
 	"k8s.io/klog/v2"
+	"os"
 	"path"
 	"regexp"
 	"strconv"
@@ -60,7 +60,7 @@ func (disks *Disks) GetParentBlockDevice(majorMinor string) *DevStat {
 }
 
 func GetDisks() (*Disks, error) {
-	data, err := ioutil.ReadFile(path.Join(procRoot, "diskstats"))
+	data, err := os.ReadFile(path.Join(procRoot, "diskstats"))
 	if err != nil {
 		return nil, err
 	}