Skip to content

Commit 08a1075

Browse files
authored
chore: remove unnecessary logrus dependency (#1214)
The troubleshoot project uses klog logging library. There is room for only one library unfortunately. Sorry logrus :)
1 parent 0a855f2 commit 08a1075

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ require (
3030
github.com/replicatedhq/termui/v3 v3.1.1-0.20200811145416-f40076d26851
3131
github.com/segmentio/ksuid v1.0.4
3232
github.com/shirou/gopsutil/v3 v3.23.5
33-
github.com/sirupsen/logrus v1.9.3
3433
github.com/spf13/cobra v1.7.0
3534
github.com/spf13/pflag v1.0.5
3635
github.com/spf13/viper v1.16.0
@@ -70,6 +69,7 @@ require (
7069
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
7170
github.com/russross/blackfriday/v2 v2.1.0 // indirect
7271
github.com/shoenig/go-m1cpu v0.1.6 // indirect
72+
github.com/sirupsen/logrus v1.9.3 // indirect
7373
github.com/sylabs/sif/v2 v2.11.1 // indirect
7474
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
7575
go.opentelemetry.io/otel/metric v1.16.0 // indirect

pkg/longhorn/types/setting.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"strings"
1010

1111
"github.com/pkg/errors"
12-
"github.com/sirupsen/logrus"
1312
"gopkg.in/yaml.v2"
1413

1514
v1 "k8s.io/api/core/v1"
15+
"k8s.io/klog/v2"
1616

1717
"github.com/replicatedhq/troubleshoot/pkg/longhorn/util"
1818
)
@@ -941,7 +941,7 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
941941

942942
// `yaml.Unmarshal()` can return a partial result. We shouldn't allow it
943943
if err := yaml.Unmarshal(data, &defaultSettings); err != nil {
944-
logrus.Errorf("Failed to unmarshal customized default settings from yaml data %v, will give up using them: %v", string(data), err)
944+
klog.Errorf("Failed to unmarshal customized default settings from yaml data %v, will give up using them: %v", string(data), err)
945945
defaultSettings = map[string]string{}
946946
}
947947
}
@@ -951,7 +951,7 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
951951
value = strings.Trim(value, " ")
952952
definition, exist := SettingDefinitions[SettingName(name)]
953953
if !exist {
954-
logrus.Errorf("Customized settings are invalid, will give up using them: undefined setting %v", name)
954+
klog.Errorf("Customized settings are invalid, will give up using them: undefined setting %v", name)
955955
defaultSettings = map[string]string{}
956956
break
957957
}
@@ -963,14 +963,14 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
963963
if definition.Type == SettingTypeBool {
964964
result, err := strconv.ParseBool(value)
965965
if err != nil {
966-
logrus.Errorf("Invalid value %v for the boolean setting %v: %v", value, name, err)
966+
klog.Errorf("Invalid value %v for the boolean setting %v: %v", value, name, err)
967967
defaultSettings = map[string]string{}
968968
break
969969
}
970970
value = strconv.FormatBool(result)
971971
}
972972
if err := ValidateInitSetting(name, value); err != nil {
973-
logrus.Errorf("Customized settings are invalid, will give up using them: the value of customized setting %v is invalid: %v", name, err)
973+
klog.Errorf("Customized settings are invalid, will give up using them: the value of customized setting %v is invalid: %v", name, err)
974974
defaultSettings = map[string]string{}
975975
break
976976
}
@@ -986,15 +986,15 @@ func GetCustomizedDefaultSettings() (map[string]string, error) {
986986
guaranteedReplicaManagerCPU = defaultSettings[string(SettingNameGuaranteedReplicaManagerCPU)]
987987
}
988988
if err := ValidateCPUReservationValues(guaranteedEngineManagerCPU, guaranteedReplicaManagerCPU); err != nil {
989-
logrus.Errorf("Customized settings GuaranteedEngineManagerCPU and GuaranteedReplicaManagerCPU are invalid, will give up using them: %v", err)
989+
klog.Errorf("Customized settings GuaranteedEngineManagerCPU and GuaranteedReplicaManagerCPU are invalid, will give up using them: %v", err)
990990
defaultSettings = map[string]string{}
991991
}
992992

993993
return defaultSettings, nil
994994
}
995995

996996
func OverwriteBuiltInSettingsWithCustomizedValues() error {
997-
logrus.Infof("Start overwriting built-in settings with customized values")
997+
klog.V(2).Info("Start overwriting built-in settings with customized values")
998998
customizedDefaultSettings, err := GetCustomizedDefaultSettings()
999999
if err != nil {
10001000
return err

pkg/longhorn/util/iscsi.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strings"
1111

1212
"github.com/pkg/errors"
13-
"github.com/sirupsen/logrus"
13+
"k8s.io/klog/v2"
1414

1515
iscsi_util "github.com/longhorn/go-iscsi-helper/util"
1616
)
@@ -58,7 +58,7 @@ func RemoveHostDirectoryContent(directory string) (err error) {
5858
}
5959
// check if the directory already deleted
6060
if _, err := nsExec.Execute("ls", []string{dir}); err != nil {
61-
logrus.Warnf("cannot find host directory %v for removal", dir)
61+
klog.Warningf("cannot find host directory %v for removal", dir)
6262
return nil
6363
}
6464
if _, err := nsExec.Execute("rm", []string{"-rf", dir}); err != nil {
@@ -92,7 +92,7 @@ func CopyHostDirectoryContent(src, dest string) (err error) {
9292

9393
// There can be no src directory, hence returning nil is fine.
9494
if _, err := nsExec.Execute("bash", []string{"-c", fmt.Sprintf("ls %s", filepath.Join(srcDir, "*"))}); err != nil {
95-
logrus.Infof("cannot list the content of the src directory %v for the copy, will do nothing: %v", srcDir, err)
95+
klog.V(2).Infof("cannot list the content of the src directory %v for the copy, will do nothing: %v", srcDir, err)
9696
return nil
9797
}
9898
// Check if the dest directory exists.
@@ -164,7 +164,7 @@ func ExpandFileSystem(volumeName string) (err error) {
164164
mountPoint := ""
165165
mountRes, err := nsExec.Execute("bash", []string{"-c", "mount | grep \"/" + volumeName + " \" | awk '{print $3}'"})
166166
if err != nil {
167-
logrus.Warnf("failed to use command mount to get the mount info of volume %v, consider the volume as unmounted: %v", volumeName, err)
167+
klog.Warningf("failed to use command mount to get the mount info of volume %v, consider the volume as unmounted: %v", volumeName, err)
168168
} else {
169169
// For empty `mountRes`, `mountPoints` is [""]
170170
mountPoints := strings.Split(strings.TrimSpace(mountRes), "\n")
@@ -178,13 +178,13 @@ func ExpandFileSystem(volumeName string) (err error) {
178178
}
179179
}
180180
if tmpMountNeeded {
181-
logrus.Errorf("BUG: Found mount point records %v for volume %v but there is no valid(non-empty) mount point", mountRes, volumeName)
181+
klog.Errorf("BUG: Found mount point records %v for volume %v but there is no valid(non-empty) mount point", mountRes, volumeName)
182182
}
183183
}
184184
}
185185
if tmpMountNeeded {
186186
mountPoint = filepath.Join(TemporaryMountPointDirectory, volumeName)
187-
logrus.Infof("The volume %v is unmounted, hence it will be temporarily mounted on %v for file system expansion", volumeName, mountPoint)
187+
klog.V(2).Infof("The volume %v is unmounted, hence it will be temporarily mounted on %v for file system expansion", volumeName, mountPoint)
188188
if _, err := nsExec.Execute("mkdir", []string{"-p", mountPoint}); err != nil {
189189
return errors.Wrapf(err, "failed to create a temporary mount point %v before file system expansion", mountPoint)
190190
}

pkg/longhorn/util/util.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/google/uuid"
2727
"github.com/gorilla/handlers"
2828
"github.com/pkg/errors"
29-
"github.com/sirupsen/logrus"
3029

3130
v1 "k8s.io/api/core/v1"
3231
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -36,6 +35,7 @@ import (
3635
"k8s.io/apimachinery/pkg/util/validation"
3736
"k8s.io/apimachinery/pkg/util/version"
3837
clientset "k8s.io/client-go/kubernetes"
38+
"k8s.io/klog/v2"
3939
)
4040

4141
const (
@@ -222,16 +222,16 @@ func ExecuteWithTimeout(timeout time.Duration, envs []string, binary string, arg
222222
case <-time.After(timeout):
223223
if cmd.Process != nil {
224224
if err := cmd.Process.Kill(); err != nil {
225-
logrus.Warnf("Problem killing process pid=%v: %s", cmd.Process.Pid, err)
225+
klog.Warningf("Problem killing process pid=%v: %s", cmd.Process.Pid, err)
226226
}
227227

228228
}
229-
return "", fmt.Errorf("Timeout executing: %v %v, output %s, stderr, %s, error %v",
229+
return "", fmt.Errorf("timeout executing: %v %v, output %s, stderr, %s, error %v",
230230
binary, args, output.String(), stderr.String(), err)
231231
}
232232

233233
if err != nil {
234-
return "", fmt.Errorf("Failed to execute: %v %v, output %s, stderr, %s, error %v",
234+
return "", fmt.Errorf("failed to execute: %v %v, output %s, stderr, %s, error %v",
235235
binary, args, output.String(), stderr.String(), err)
236236
}
237237
return output.String(), nil
@@ -256,7 +256,7 @@ func TimestampAfterTimeout(ts string, timeout time.Duration) bool {
256256
now := time.Now()
257257
t, err := time.Parse(time.RFC3339, ts)
258258
if err != nil {
259-
logrus.Errorf("Cannot parse time %v", ts)
259+
klog.Errorf("Cannot parse time %v", ts)
260260
return false
261261
}
262262
deadline := t.Add(timeout)
@@ -266,7 +266,7 @@ func TimestampAfterTimeout(ts string, timeout time.Duration) bool {
266266
func TimestampWithinLimit(latest time.Time, ts string, limit time.Duration) bool {
267267
t, err := time.Parse(time.RFC3339, ts)
268268
if err != nil {
269-
logrus.Errorf("Cannot parse time %v", ts)
269+
klog.Errorf("Cannot parse time %v", ts)
270270
return false
271271
}
272272
deadline := t.Add(limit)
@@ -329,7 +329,7 @@ func RegisterShutdownChannel(done chan struct{}) {
329329
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
330330
go func() {
331331
sig := <-sigs
332-
logrus.Infof("Receive %v to exit", sig)
332+
klog.V(2).Infof("Receive %v to exit", sig)
333333
close(done)
334334
}()
335335
}
@@ -367,14 +367,14 @@ func GetSortedKeysFromMap(maps interface{}) []string {
367367
func AutoCorrectName(name string, maxLength int) string {
368368
newName := strings.ToLower(name)
369369
if len(name) > maxLength {
370-
logrus.Warnf("Name %v is too long, auto-correct to fit %v characters", name, maxLength)
370+
klog.Warningf("Name %v is too long, auto-correct to fit %v characters", name, maxLength)
371371
checksum := GetStringChecksum(name)
372372
newNameSuffix := "-" + checksum[:8]
373373
newNamePrefix := strings.TrimRight(newName[:maxLength-len(newNameSuffix)], "-")
374374
newName = newNamePrefix + newNameSuffix
375375
}
376376
if newName != name {
377-
logrus.Warnf("Name auto-corrected from %v to %v", name, newName)
377+
klog.Warningf("Name auto-corrected from %v to %v", name, newName)
378378
}
379379
return newName
380380
}

0 commit comments

Comments
 (0)