Skip to content

Commit b580613

Browse files
authored
Make extractor handle standalone usecase (#1077)
1 parent a755492 commit b580613

File tree

6 files changed

+28
-14
lines changed

6 files changed

+28
-14
lines changed

src/controllers/csi/provisioner/processmoduleconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package csiprovisioner
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
5+
"io"
66
"os"
77

88
"github.com/Dynatrace/dynatrace-operator/src/dtclient"
@@ -63,7 +63,7 @@ func (provisioner *OneAgentProvisioner) readProcessModuleConfigCache(tenantUUID
6363
return nil, err
6464
}
6565

66-
jsonBytes, err := ioutil.ReadAll(processModuleConfigCacheFile)
66+
jsonBytes, err := io.ReadAll(processModuleConfigCacheFile)
6767
if err != nil {
6868
if err := processModuleConfigCacheFile.Close(); err != nil {
6969
log.Error(errors.WithStack(err), "error closing file after trying to read it")

src/installer/url/config.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package url
22

33
import (
4-
"path/filepath"
5-
64
"github.com/Dynatrace/dynatrace-operator/src/logger"
75
)
86

97
var (
10-
log = logger.NewDTLogger().WithName("oneagent-url-installer")
11-
standaloneBinDir = filepath.Join("mnt", "bin")
8+
log = logger.NewDTLogger().WithName("oneagent-url-installer")
129
)
1310

1411
const (

src/installer/url/installer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package url
33
import (
44
"os"
55

6+
"github.com/Dynatrace/dynatrace-operator/src/config"
67
"github.com/Dynatrace/dynatrace-operator/src/controllers/csi/metadata"
78
"github.com/Dynatrace/dynatrace-operator/src/dtclient"
89
"github.com/Dynatrace/dynatrace-operator/src/installer/symlink"
@@ -92,7 +93,7 @@ func (installer UrlInstaller) installAgentFromUrl(targetDir string) error {
9293
}
9394

9495
func (installer UrlInstaller) isAlreadyDownloaded(targetDir string) bool {
95-
if standaloneBinDir == targetDir {
96+
if config.AgentBinDirMount == targetDir {
9697
return false
9798
}
9899
_, err := installer.fs.Stat(targetDir)

src/installer/url/installer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"testing"
88

99
"github.com/Dynatrace/dynatrace-operator/src/arch"
10+
"github.com/Dynatrace/dynatrace-operator/src/config"
1011
"github.com/Dynatrace/dynatrace-operator/src/controllers/csi/metadata"
1112
"github.com/Dynatrace/dynatrace-operator/src/dtclient"
1213
"github.com/Dynatrace/dynatrace-operator/src/installer/zip"
@@ -204,7 +205,7 @@ func TestIsAlreadyDownloaded(t *testing.T) {
204205
})
205206
t.Run(`false if standalone`, func(t *testing.T) {
206207
fs := afero.NewMemMapFs()
207-
targetDir := standaloneBinDir
208+
targetDir := config.AgentBinDirMount
208209
installer := &UrlInstaller{
209210
fs: fs,
210211
props: &Properties{},

src/installer/zip/zip.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/Dynatrace/dynatrace-operator/src/config"
1011
"github.com/Dynatrace/dynatrace-operator/src/installer/common"
1112
"github.com/klauspost/compress/zip"
1213
"github.com/pkg/errors"
@@ -32,12 +33,24 @@ func (extractor OneAgentExtractor) ExtractZip(sourceFile afero.File, targetDir s
3233
return errors.WithStack(err)
3334
}
3435

35-
err = extractFilesFromZip(fs, extractor.pathResolver.AgentTempUnzipDir(), reader)
36+
extractDest := extractor.pathResolver.AgentTempUnzipDir()
37+
if extractor.pathResolver.RootDir == config.AgentBinDirMount {
38+
extractDest = targetDir
39+
}
40+
41+
err = extractFilesFromZip(fs, extractDest, reader)
3642
if err != nil {
3743
log.Info("failed to extract files from zip", "err", err)
3844
return err
3945
}
40-
return extractor.moveToTargetDir(targetDir)
46+
if extractDest != targetDir {
47+
err := extractor.moveToTargetDir(targetDir)
48+
if err != nil {
49+
log.Info("failed to move file to final destination", "err", err)
50+
return err
51+
}
52+
}
53+
return nil
4154
}
4255

4356
func extractFilesFromZip(fs afero.Fs, targetDir string, reader *zip.Reader) error {

src/standalone/run.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/Dynatrace/dynatrace-operator/src/arch"
88
"github.com/Dynatrace/dynatrace-operator/src/config"
9+
"github.com/Dynatrace/dynatrace-operator/src/controllers/csi/metadata"
910
"github.com/Dynatrace/dynatrace-operator/src/dtclient"
1011
"github.com/Dynatrace/dynatrace-operator/src/installer"
1112
"github.com/Dynatrace/dynatrace-operator/src/installer/url"
@@ -29,16 +30,16 @@ func NewRunner(fs afero.Fs) (*Runner, error) {
2930
return nil, err
3031
}
3132

32-
var config *SecretConfig
33+
var secretConfig *SecretConfig
3334
var client dtclient.Client
3435
var oneAgentInstaller *url.UrlInstaller
3536
if env.OneAgentInjected {
36-
config, err = newSecretConfigViaFs(fs)
37+
secretConfig, err = newSecretConfigViaFs(fs)
3738
if err != nil {
3839
return nil, err
3940
}
4041

41-
client, err = newDTClientBuilder(config).createClient()
42+
client, err = newDTClientBuilder(secretConfig).createClient()
4243
if err != nil {
4344
return nil, err
4445
}
@@ -54,14 +55,15 @@ func NewRunner(fs afero.Fs) (*Runner, error) {
5455
Technologies: env.InstallerTech,
5556
TargetVersion: url.VersionLatest,
5657
Url: env.InstallerUrl,
58+
PathResolver: metadata.PathResolver{RootDir: config.AgentBinDirMount},
5759
},
5860
)
5961
}
6062
log.Info("standalone runner created successfully")
6163
return &Runner{
6264
fs: fs,
6365
env: env,
64-
config: config,
66+
config: secretConfig,
6567
dtclient: client,
6668
installer: oneAgentInstaller,
6769
}, nil

0 commit comments

Comments
 (0)