Skip to content

Commit f4db677

Browse files
Merge pull request openshift#7075 from bfournie/upgrade-libnm
OCPBUGS-11479: Upgrade libnmstate version used
2 parents 46c3594 + 6ab187e commit f4db677

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

pkg/asset/agent/image/agentimage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (a *AgentImage) fetchAgentTuiFiles(releaseImage string, pullSecret string,
7474
Config{MaxTries: OcDefaultTries, RetryDelay: OcDefaultRetryDelay},
7575
releaseImage, pullSecret, mirrorConfig)
7676

77-
agentTuiFilenames := []string{"/usr/bin/agent-tui", "/usr/lib64/libnmstate.so.1.3.3"}
77+
agentTuiFilenames := []string{"/usr/bin/agent-tui", "/usr/lib64/libnmstate.so.*"}
7878
files := []string{}
7979

8080
for _, srcFile := range agentTuiFilenames {

pkg/asset/agent/image/oc.go

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@ import (
88
"encoding/json"
99
"fmt"
1010
"io"
11-
"io/fs"
1211
"os"
1312
"os/exec"
1413
"path"
1514
"path/filepath"
1615
"strings"
1716
"time"
1817

19-
"github.com/pkg/errors"
2018
"github.com/sirupsen/logrus"
2119
"github.com/thedevsaddam/retry"
2220
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -184,10 +182,9 @@ func (r *release) extractFileFromImage(image, file, cacheDir string) (string, er
184182
} else {
185183
cmd = fmt.Sprintf(templateImageExtract, file, cacheDir, image)
186184
}
187-
// Remove file if it exists
188185
path := filepath.Join(cacheDir, path.Base(file))
189-
if err := os.Remove(path); err != nil && !errors.Is(err, fs.ErrNotExist) {
190-
logrus.Debugf("Could not remove existing baseISO %s", path)
186+
// Remove file if it exists
187+
if err := removeCacheFile(path); err != nil {
191188
return "", err
192189
}
193190

@@ -196,6 +193,14 @@ func (r *release) extractFileFromImage(image, file, cacheDir string) (string, er
196193
if err != nil {
197194
return "", err
198195
}
196+
// Get actual file if the file ends in wildcard
197+
if strings.HasSuffix(file, "*") {
198+
path, err = getExtractedFileFromWildcard(path)
199+
if err != nil {
200+
return "", err
201+
}
202+
}
203+
199204
// Make sure file exists after extraction
200205
if _, err := os.Stat(path); err != nil {
201206
logrus.Debugf("File %s was not found, err %s", file, err.Error())
@@ -288,6 +293,47 @@ func (r *release) verifyCacheFile(image, file, architecture string) (bool, error
288293
return false, nil
289294
}
290295

296+
// Remove any existing files in the cache.
297+
func removeCacheFile(path string) error {
298+
matches, err := filepath.Glob(path)
299+
if err != nil {
300+
return err
301+
}
302+
303+
for _, file := range matches {
304+
if err = os.Remove(file); err != nil {
305+
return err
306+
}
307+
logrus.Debugf("Removed file %s", file)
308+
}
309+
return nil
310+
}
311+
312+
func getExtractedFileFromWildcard(path string) (string, error) {
313+
matches, err := filepath.Glob(path)
314+
if err != nil {
315+
return "", err
316+
}
317+
318+
var found string
319+
for _, file := range matches {
320+
fileInfo, err := os.Lstat(file)
321+
if err != nil {
322+
return "", err
323+
}
324+
if fileInfo.Mode()&os.ModeSymlink == 0 {
325+
if found != "" {
326+
logrus.Warningf("Additional file %s matching %s in release", filepath.Base(path), filepath.Base(path))
327+
}
328+
found = file
329+
}
330+
}
331+
if found == "" {
332+
return "", fmt.Errorf("failed to extract file %s", filepath.Base(path))
333+
}
334+
return found, nil
335+
}
336+
291337
func execute(executer executer.Executer, pullSecret, command string) (string, error) {
292338
ps, err := executer.TempFile("", "registry-config")
293339
if err != nil {

0 commit comments

Comments
 (0)