Skip to content

Commit 0c1203f

Browse files
Merge pull request openshift#7095 from andfasano/fix-agent-tui-nmstate2
OCPBUGS-11801: Fix agent-tui libnmstate dependency name
2 parents 105d848 + d164ed2 commit 0c1203f

File tree

5 files changed

+62
-66
lines changed

5 files changed

+62
-66
lines changed

cmd/openshift-install/agent_internal_integration_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,11 @@ func checkFileFromInitrdImg(isoPath string, fileName string) error {
322322

323323
// check if the current cpio files match the required ones
324324
for _, f := range files {
325-
if f == fileName {
325+
matched, err := filepath.Match(fileName, f)
326+
if err != nil {
327+
return err
328+
}
329+
if matched {
326330
return nil
327331
}
328332
}

cmd/openshift-install/testdata/agent/image/assets/default_assets.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exists $WORK/agent.x86_64.iso
66

77
ignitionImgContains agent.x86_64.iso config.ign
88
initrdImgContains agent.x86_64.iso /agent-files/agent-tui
9-
initrdImgContains agent.x86_64.iso /agent-files/libnmstate.so.1.3.3
9+
initrdImgContains agent.x86_64.iso /agent-files/libnmstate.so.*
1010
initrdImgContains agent.x86_64.iso /usr/lib/dracut/hooks/pre-pivot/99-agent-copy-files.sh
1111

1212
-- install-config.yaml --

pkg/asset/agent/image/agentimage.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,19 @@ func (a *AgentImage) fetchAgentTuiFiles(releaseImage string, pullSecret string,
7878
files := []string{}
7979

8080
for _, srcFile := range agentTuiFilenames {
81-
f, err := release.ExtractFile("agent-installer-node-agent", srcFile)
81+
extracted, err := release.ExtractFile("agent-installer-node-agent", srcFile)
8282
if err != nil {
8383
return nil, err
8484
}
85-
// Make sure it could be executed
86-
err = os.Chmod(f, 0o555)
87-
if err != nil {
88-
return nil, err
85+
86+
for _, f := range extracted {
87+
// Make sure it could be executed
88+
err = os.Chmod(f, 0o555)
89+
if err != nil {
90+
return nil, err
91+
}
92+
files = append(files, f)
8993
}
90-
files = append(files, f)
9194
}
9295

9396
return files, nil

pkg/asset/agent/image/cpio.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package image
33
import (
44
"bytes"
55
"compress/gzip"
6+
"fmt"
67
"io"
78
"os"
89
"path/filepath"
@@ -70,13 +71,7 @@ func (ca *CpioArchive) StorePath(path string) error {
7071

7172
// StoreFile appends to the current archive the specified file.
7273
func (ca *CpioArchive) StoreFile(filename string, dstPath string) error {
73-
f, err := os.Open(filename)
74-
if err != nil {
75-
return err
76-
}
77-
defer f.Close()
78-
79-
fileInfo, err := f.Stat()
74+
fileInfo, err := os.Lstat(filename)
8075
if err != nil {
8176
return err
8277
}
@@ -91,9 +86,32 @@ func (ca *CpioArchive) StoreFile(filename string, dstPath string) error {
9186
return err
9287
}
9388

94-
_, err = io.Copy(ca.cpioWriter, f)
95-
if err != nil {
96-
return err
89+
fm := fileInfo.Mode()
90+
switch {
91+
case fm.IsRegular():
92+
// Copy the file content
93+
f, err := os.Open(filename)
94+
if err != nil {
95+
return err
96+
}
97+
defer f.Close()
98+
99+
_, err = io.Copy(ca.cpioWriter, f)
100+
if err != nil {
101+
return err
102+
}
103+
case fm&os.ModeSymlink != 0:
104+
// In case of a symbolic link, copy the link text
105+
s, err := os.Readlink(filename)
106+
if err != nil {
107+
return err
108+
}
109+
_, err = ca.cpioWriter.Write([]byte(s))
110+
if err != nil {
111+
return err
112+
}
113+
default:
114+
return fmt.Errorf("unsupported file mode %v for file %s", fm, filename)
97115
}
98116

99117
return nil

pkg/asset/agent/image/oc.go

Lines changed: 19 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Config struct {
4545
// Release is the interface to use the oc command to the get image info
4646
type Release interface {
4747
GetBaseIso(architecture string) (string, error)
48-
ExtractFile(image string, filename string) (string, error)
48+
ExtractFile(image string, filename string) ([]string, error)
4949
}
5050

5151
type release struct {
@@ -75,20 +75,20 @@ const (
7575
)
7676

7777
// ExtractFile extracts the specified file from the given image name, and store it in the cache dir.
78-
func (r *release) ExtractFile(image string, filename string) (string, error) {
78+
func (r *release) ExtractFile(image string, filename string) ([]string, error) {
7979
imagePullSpec, err := r.getImageFromRelease(image)
8080
if err != nil {
81-
return "", err
81+
return nil, err
8282
}
8383

8484
cacheDir, err := GetCacheDir(filesDataType)
8585
if err != nil {
86-
return "", err
86+
return nil, err
8787
}
8888

8989
path, err := r.extractFileFromImage(imagePullSpec, filename, cacheDir)
9090
if err != nil {
91-
return "", err
91+
return nil, err
9292
}
9393
return path, err
9494
}
@@ -130,7 +130,7 @@ func (r *release) GetBaseIso(architecture string) (string, error) {
130130
return "", err
131131
}
132132
logrus.Infof("Base ISO obtained from release and cached at %s", path)
133-
return path, err
133+
return path[0], err
134134
}
135135

136136
func (r *release) getImageFromRelease(imageName string) (string, error) {
@@ -170,12 +170,12 @@ func (r *release) getImageFromRelease(imageName string) (string, error) {
170170
return image, nil
171171
}
172172

173-
func (r *release) extractFileFromImage(image, file, cacheDir string) (string, error) {
173+
func (r *release) extractFileFromImage(image, file, cacheDir string) ([]string, error) {
174174
var cmd string
175175
if len(r.mirrorConfig) > 0 {
176176
icspFile, err := getIcspFileFromRegistriesConfig(r.mirrorConfig)
177177
if err != nil {
178-
return "", err
178+
return nil, err
179179
}
180180
defer removeIcspFile(icspFile)
181181
cmd = fmt.Sprintf(templateImageExtractWithIcsp, file, cacheDir, icspFile, image)
@@ -185,29 +185,25 @@ func (r *release) extractFileFromImage(image, file, cacheDir string) (string, er
185185
path := filepath.Join(cacheDir, path.Base(file))
186186
// Remove file if it exists
187187
if err := removeCacheFile(path); err != nil {
188-
return "", err
188+
return nil, err
189189
}
190190

191191
logrus.Debugf("extracting %s to %s, %s", file, cacheDir, cmd)
192192
_, err := retry.Do(r.config.MaxTries, r.config.RetryDelay, execute, r.executer, r.pullSecret, cmd)
193193
if err != nil {
194-
return "", err
195-
}
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-
}
194+
return nil, err
202195
}
203196

204-
// Make sure file exists after extraction
205-
if _, err := os.Stat(path); err != nil {
206-
logrus.Debugf("File %s was not found, err %s", file, err.Error())
207-
return "", err
197+
// Make sure file(s) exist after extraction
198+
matches, err := filepath.Glob(path)
199+
if err != nil {
200+
return nil, err
201+
}
202+
if matches == nil {
203+
return nil, fmt.Errorf("file %s was not found", file)
208204
}
209205

210-
return path, nil
206+
return matches, nil
211207
}
212208

213209
// Get hash from rhcos.json
@@ -280,7 +276,7 @@ func (r *release) verifyCacheFile(image, file, architecture string) (bool, error
280276
return false, nil
281277
}
282278

283-
payloadSha, err := os.ReadFile(shaFile)
279+
payloadSha, err := os.ReadFile(shaFile[0])
284280
if err != nil {
285281
return false, err
286282
}
@@ -309,31 +305,6 @@ func removeCacheFile(path string) error {
309305
return nil
310306
}
311307

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-
337308
func execute(executer executer.Executer, pullSecret, command string) (string, error) {
338309
ps, err := executer.TempFile("", "registry-config")
339310
if err != nil {

0 commit comments

Comments
 (0)