Skip to content

Commit

Permalink
(fleet) backport freeze work (#25511)
Browse files Browse the repository at this point in the history
* fix(installer): Use gcr.io by default instead of public.ecr.aws (#25255)

* (fleet) fix minor issues in the installer bootstrap (#25267)

Two issues discovered during the rollout:
- `/tmp` mounted as `noexec` => this PR moves the bootstraped installer to a tmp under `/opt/datadog-installer`
- some customers are running the install script in a loop, we need to avoid re-bootstraping everytime (and later re-installing)

* (fleet) use rootTmpDir for both MkdirTemp in the bootstrap

* (fleet) use actual package size to check if we have enough disk space

This PR uses the changes in DataDog/datadog-packages#11 to properly compute the required disk space to install a package. Previously we were requiring 3GiB for any package.

* purge

* update test

* pass test

* properly remove all with go

* remove noisy warn

* (fleet) fix a warn log in telemetry

```
2024/05/03 08:04:57 Datadog Tracer v1.61.0 WARN: ddtrace/tracer: deprecated config WithServiceName should not be used with `WithService` or `DD_SERVICE`; integration service name will not be set.
```

* (fleet) default to US1 for the telemetry website when DD_SITE isn't set

* fix missing bootstrap

* quick fix

---------

Co-authored-by: Baptiste Foy <baptiste.foy@datadoghq.com>
Co-authored-by: Raphael Gavache <raphael.gavache@datadoghq.com>
  • Loading branch information
3 people committed May 11, 2024
1 parent 02baa57 commit 83418a3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 23 additions & 2 deletions pkg/fleet/bootstraper/bootstraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
const (
installerPackage = "datadog-installer"
installerBinPath = "bin/installer/installer"

hashFilePath = "/opt/datadog-installer/run/installer-hash"
rootTmpDir = "/opt/datadog-installer/run"
)

// Option are the options for the bootstraper.
Expand Down Expand Up @@ -85,6 +88,7 @@ func WithSite(site string) Option {
// 2. Export the installer image as an OCI layout on the disk.
// 3. Extract the installer image layers on the disk.
// 4. Run the installer from the extract layer with `install file://<layout-path>`.
// 5. Write a file on the disk with the hash of the installed version.
func Bootstrap(ctx context.Context, opts ...Option) error {
o := newOptions()
for _, opt := range opts {
Expand All @@ -101,9 +105,20 @@ func Bootstrap(ctx context.Context, opts ...Option) error {
if downloadedPackage.Name != installerPackage {
return fmt.Errorf("unexpected package name: %s, expected %s", downloadedPackage.Name, installerPackage)
}
hash, err := downloadedPackage.Image.Digest()
if err != nil {
return fmt.Errorf("failed to get image digest: %w", err)
}
existingHash, err := os.ReadFile(hashFilePath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to read hash file: %w", err)
}
if string(existingHash) == hash.String() {
return nil
}

// 2. Export the installer image as an OCI layout on the disk.
layoutTmpDir, err := os.MkdirTemp("", "")
layoutTmpDir, err := os.MkdirTemp(rootTmpDir, "")
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand All @@ -114,7 +129,7 @@ func Bootstrap(ctx context.Context, opts ...Option) error {
}

// 3. Extract the installer image layers on the disk.
binTmpDir, err := os.MkdirTemp("", "")
binTmpDir, err := os.MkdirTemp(rootTmpDir, "")
if err != nil {
return fmt.Errorf("failed to create temporary directory: %w", err)
}
Expand All @@ -131,5 +146,11 @@ func Bootstrap(ctx context.Context, opts ...Option) error {
if err != nil {
return fmt.Errorf("failed to run installer: %w", err)
}

// 5. Write a file on the disk with the hash of the installed version.
err = os.WriteFile(hashFilePath, []byte(hash.String()), 0644)
if err != nil {
return fmt.Errorf("failed to write hash file: %w", err)
}
return nil
}
2 changes: 2 additions & 0 deletions test/new-e2e/tests/installer/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestSuseARM(t *testing.T) {
}

func (v *installerSuite) bootstrap(remoteUpdatesEnabled bool) {
v.Env().RemoteHost.MustExecute("sudo rm /opt/datadog-installer/run/installer-hash || true")
v.Env().RemoteHost.MustExecute(
"sudo -E datadog-bootstrap bootstrap",
client.WithEnvVariables(client.EnvVar{
Expand Down Expand Up @@ -227,6 +228,7 @@ func (v *installerSuite) TestExperimentCrash() {

func (v *installerSuite) TestUninstall() {
host := v.Env().RemoteHost
v.bootstrap(false)

installAssertions := []string{
"test -d /opt/datadog-packages",
Expand Down

0 comments on commit 83418a3

Please sign in to comment.