@@ -13,6 +13,10 @@ import (
13
13
"strings"
14
14
"time"
15
15
16
+ "github.com/spf13/cast"
17
+
18
+ "github.com/containers/common/pkg/strongunits"
19
+
16
20
"github.com/crc-org/crc/v2/pkg/crc/constants"
17
21
"github.com/crc-org/crc/v2/pkg/crc/errors"
18
22
"github.com/crc-org/crc/v2/pkg/crc/logging"
@@ -64,46 +68,46 @@ func checkCertValidity(sshRunner *ssh.Runner, cert string) (bool, error) {
64
68
}
65
69
66
70
// Return size of disk, used space in bytes and the mountpoint
67
- func GetRootPartitionUsage (sshRunner * ssh.Runner ) (int64 , int64 , error ) {
71
+ func GetRootPartitionUsage (sshRunner * ssh.Runner ) (strongunits. B , strongunits. B , error ) {
68
72
cmd := "df -B1 --output=size,used,target /sysroot | tail -1"
69
73
70
74
out , _ , err := sshRunner .Run (cmd )
71
75
72
76
if err != nil {
73
- return 0 , 0 , err
77
+ return strongunits . B ( 0 ), strongunits . B ( 0 ) , err
74
78
}
75
79
diskDetails := strings .Split (strings .TrimSpace (out ), " " )
76
80
diskSize , err := strconv .ParseInt (diskDetails [0 ], 10 , 64 )
77
81
if err != nil {
78
- return 0 , 0 , err
82
+ return strongunits . B ( 0 ), strongunits . B ( 0 ) , err
79
83
}
80
84
diskUsage , err := strconv .ParseInt (diskDetails [1 ], 10 , 64 )
81
85
if err != nil {
82
- return 0 , 0 , err
86
+ return strongunits . B ( 0 ), strongunits . B ( 0 ) , err
83
87
}
84
- return diskSize , diskUsage , nil
88
+ return strongunits . B ( cast . ToUint64 ( diskSize )), strongunits . B ( cast . ToUint64 ( diskUsage )) , nil
85
89
}
86
90
87
91
// GetRAMUsage return RAM size and RAM usage in bytes
88
- func GetRAMUsage (sshRunner * ssh.Runner ) (int64 , int64 , error ) {
92
+ func GetRAMUsage (sshRunner * ssh.Runner ) (strongunits. B , strongunits. B , error ) {
89
93
cmd := "awk '/^Mem/ {print $2,$3}' <(free -b)"
90
94
out , _ , err := sshRunner .Run (cmd )
91
95
92
96
if err != nil {
93
- return 0 , 0 , err
97
+ return strongunits . B ( 0 ), strongunits . B ( 0 ) , err
94
98
}
95
99
96
100
ramDetails := strings .Split (strings .TrimSpace (out ), " " )
97
101
ramSize , err := strconv .ParseInt (ramDetails [0 ], 10 , 64 )
98
102
if err != nil {
99
- return 0 , 0 , err
103
+ return strongunits . B ( 0 ), strongunits . B ( 0 ) , err
100
104
}
101
105
ramUsage , err := strconv .ParseInt (ramDetails [1 ], 10 , 64 )
102
106
if err != nil {
103
- return 0 , 0 , err
107
+ return strongunits . B ( 0 ), strongunits . B ( 0 ) , err
104
108
}
105
109
106
- return ramSize , ramUsage , nil
110
+ return strongunits . B ( cast . ToUint64 ( ramSize )), strongunits . B ( cast . ToUint64 ( ramUsage )) , nil
107
111
}
108
112
109
113
// GetCPUUsage return CPU usage array, index correspond to CPU number, value is load % (values between 0 nad 100)
@@ -130,7 +134,7 @@ func GetCPUUsage(sshRunner *ssh.Runner) ([]int64, error) {
130
134
131
135
}
132
136
133
- func GetPVCUsage (sshRunner * ssh.Runner ) (int , error ) {
137
+ func GetPVCUsage (sshRunner * ssh.Runner ) (strongunits. B , error ) {
134
138
cmd := `#!/bin/bash
135
139
mountpoints=$(lsblk --output=mountpoints | grep pvc | uniq | tr '\n' ' ')
136
140
if [ -z "$mountpoints" ]; then
@@ -144,13 +148,13 @@ sudo df -B1 --output=size $mountpoints | awk ' { sum += $1 } END { printf "%d",
144
148
}
145
149
out = strings .TrimSpace (out )
146
150
if len (out ) == 0 {
147
- return 0 , nil
151
+ return strongunits . B ( 0 ) , nil
148
152
}
149
153
ans , err := strconv .Atoi (out )
150
154
if err != nil {
151
- return 0 , err
155
+ return strongunits . B ( 0 ) , err
152
156
}
153
- return ans , nil
157
+ return strongunits . B ( cast . ToUint64 ( ans )) , nil
154
158
}
155
159
156
160
func EnsureSSHKeyPresentInTheCluster (ctx context.Context , ocConfig oc.Config , sshPublicKeyPath string ) error {
0 commit comments