Skip to content

Commit

Permalink
Merge pull request #156 from clobrano/fix-deprecations/0
Browse files Browse the repository at this point in the history
Fix some deprecations
  • Loading branch information
openshift-ci[bot] authored Oct 28, 2023
2 parents 2b6fae3 + 6b9769b commit 6786790
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/certificates/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (s *SecretCertStorage) StoreCerts(caPem, certPem, keyPem *bytes.Buffer) err
Namespace: s.namespace,
Name: secretName,
},
Immutable: pointer.BoolPtr(true),
Immutable: pointer.Bool(true),
Data: nil,
StringData: map[string]string{
caPemKey: caPem.String(),
Expand Down
25 changes: 15 additions & 10 deletions pkg/watchdog/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package watchdog

import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -79,7 +78,7 @@ func NewLinux(log logr.Logger) (Watchdog, error) {
return nil, err
}

newWatchdogDevice, err := getLastModifiedWatchdog()
newWatchdogDevice, err := getLastModifiedWatchdog(log)

if err != nil {
log.Error(err, "failed to find softdog path")
Expand All @@ -105,26 +104,32 @@ func NewLinux(log logr.Logger) (Watchdog, error) {

// this func returns watchdog path with the latest modification time assuming that
// after softdog enablement
func getLastModifiedWatchdog() (string, error) {
files, err := ioutil.ReadDir(watchdogsFolder)
func getLastModifiedWatchdog(log logr.Logger) (string, error) {
entries, err := os.ReadDir(watchdogsFolder)
if err != nil {
return "", errors.Wrap(err, "failed to list watchdogs folder: "+watchdogsFolder)
}

maxModTime := time.Time{}
latestWatchdog := ""
for _, file := range files {
if file.IsDir() {
for _, entry := range entries {
if entry.IsDir() {
continue
}

if !strings.HasPrefix(file.Name(), watchdogPrefix) {
if !strings.HasPrefix(entry.Name(), watchdogPrefix) {
continue
}

if file.ModTime().After(maxModTime) || file.ModTime().Equal(maxModTime) {
maxModTime = file.ModTime()
latestWatchdog = filepath.Join(watchdogsFolder, file.Name())
fileInfo, err := entry.Info()
if err != nil {
log.Error(err, "failed to get info for file in watchdogs folder", "file", entry.Name(), "watchdog folder", watchdogsFolder)
continue
}

if fileInfo.ModTime().After(maxModTime) || fileInfo.ModTime().Equal(maxModTime) {
maxModTime = fileInfo.ModTime()
latestWatchdog = filepath.Join(watchdogsFolder, entry.Name())
}
}

Expand Down

0 comments on commit 6786790

Please sign in to comment.