Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions cmd/output/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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"}
Expand Down Expand Up @@ -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"},
Expand All @@ -205,17 +241,21 @@ 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,
},
},
},
}
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)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down