diff --git a/cmd/output/volume.go b/cmd/output/volume.go index 3590eed7..97d32e66 100644 --- a/cmd/output/volume.go +++ b/cmd/output/volume.go @@ -10,6 +10,7 @@ import ( "github.com/metal-stack/metal-lib/pkg/genericcli" "github.com/metal-stack/metal-lib/pkg/pointer" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" k8syaml "sigs.k8s.io/yaml" ) @@ -32,7 +33,12 @@ type ( // Print a volume as table func (p VolumeTablePrinter) Print(data []*models.V1VolumeResponse) { + showStorage := hasMultipleStorageTypes(data) + p.shortHeader = []string{"ID", "Name", "Size", "Usage", "Replicas", "QoS", "Project", "Tenant", "Partition"} + if showStorage { + p.shortHeader = append(p.shortHeader, "Storage") + } p.wideHeader = append(p.shortHeader, "Nodes") p.Order(data) @@ -79,6 +85,13 @@ func (p VolumeTablePrinter) Print(data []*models.V1VolumeResponse) { nodes := ConnectedHosts(vol) short := []string{volumeID, name, size, usage, replica, qos, project, tenant, partition} + if showStorage { + storageType := "" + if vol.StorageType != nil { + storageType = *vol.StorageType + } + short = append(short, storageType) + } wide := append(short, strings.Join(nodes, "\n")) p.addWideData(wide, vol) @@ -87,6 +100,23 @@ func (p VolumeTablePrinter) Print(data []*models.V1VolumeResponse) { p.render() } +func hasMultipleStorageTypes(data []*models.V1VolumeResponse) bool { + seen := "" + for _, vol := range data { + if vol.StorageType == nil { + continue + } + if seen == "" { + seen = *vol.StorageType + continue + } + if *vol.StorageType != seen { + return true + } + } + return false +} + // Print an snapshot as table func (p SnapshotTablePrinter) Print(data []*models.V1SnapshotResponse) { p.shortHeader = []string{"ID", "Name", "SourceVolumeID", "SourceVolumeName", "Size", "Project", "Tenant", "Partition"} @@ -197,6 +227,12 @@ spec: storageClassName: partition-silver */ func VolumeManifest(v models.V1VolumeResponse, name, namespace, sc string) error { + // Determine CSI driver based on storage type + csiDriver := "csi.lightbitslabs.com" // default for Duros + if v.StorageType != nil && *v.StorageType == "ontap" { + csiDriver = "csi.trident.netapp.io" + } + filesystem := corev1.PersistentVolumeFilesystem pv := corev1.PersistentVolume{ TypeMeta: v1.TypeMeta{Kind: "PersistentVolume", APIVersion: "v1"}, @@ -205,10 +241,9 @@ func VolumeManifest(v models.V1VolumeResponse, name, namespace, sc string) error AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, VolumeMode: &filesystem, StorageClassName: sc, - // FIXME add Capacity once figured out PersistentVolumeSource: corev1.PersistentVolumeSource{ CSI: &corev1.CSIPersistentVolumeSource{ - Driver: "csi.lightbitslabs.com", + Driver: csiDriver, FSType: "ext4", ReadOnly: false, VolumeHandle: *v.VolumeHandle, @@ -216,6 +251,11 @@ func VolumeManifest(v models.V1VolumeResponse, name, namespace, sc string) error }, }, } + if v.Size != nil { + pv.Spec.Capacity = corev1.ResourceList{ + corev1.ResourceStorage: *resource.NewQuantity(*v.Size, resource.BinarySI), + } + } if len(v.ConnectedHosts) > 0 { nodes := ConnectedHosts(&v) diff --git a/go.mod b/go.mod index b1992d45..e4f67429 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/dustin/go-humanize v1.0.1 github.com/fatih/color v1.19.0 github.com/fi-ts/accounting-go v0.11.1 - github.com/fi-ts/cloud-go v0.32.1 + github.com/fi-ts/cloud-go v0.33.0 github.com/gardener/gardener v1.123.5 github.com/gardener/machine-controller-manager v0.58.0 github.com/gizak/termui/v3 v3.1.0 diff --git a/go.sum b/go.sum index 1914173d..4a4e603d 100644 --- a/go.sum +++ b/go.sum @@ -134,8 +134,8 @@ github.com/fatih/color v1.19.0 h1:Zp3PiM21/9Ld6FzSKyL5c/BULoe/ONr9KlbYVOfG8+w= github.com/fatih/color v1.19.0/go.mod h1:zNk67I0ZUT1bEGsSGyCZYZNrHuTkJJB+r6Q9VuMi0LE= github.com/fi-ts/accounting-go v0.11.1 h1:F4rFua+Q8wF03ASNPTgiUNEQ4vTgnZ1B/ac3B+ssiT8= github.com/fi-ts/accounting-go v0.11.1/go.mod h1:yX9yqzX+i23O/Bj9Gn22oM+/nd2QtjMsvVIWab9UAU4= -github.com/fi-ts/cloud-go v0.32.1 h1:Ve3MeaWCH4h1QBeRHzVAmhFIynPaoRYnW7Cr+X+YFGM= -github.com/fi-ts/cloud-go v0.32.1/go.mod h1:gwsY2TQzq4DIu8pevHUZXI11uE1zePOnpYXkPtLYlsw= +github.com/fi-ts/cloud-go v0.33.0 h1:GMU+dUnJVGAjSORB9Sqkxg62SdOwQ+1hOXdx+MaUK4g= +github.com/fi-ts/cloud-go v0.33.0/go.mod h1:gwsY2TQzq4DIu8pevHUZXI11uE1zePOnpYXkPtLYlsw= github.com/fluent/fluent-operator/v3 v3.3.0 h1:zBtt8IOVSyTiywnmom3V2byqIi2ZXMCCKBUx/4bnFBk= github.com/fluent/fluent-operator/v3 v3.3.0/go.mod h1:x54zzJ60QYJ6jnN7n9/Mseyaz9oWjSO99hbhVXJaar0= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=