-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#16661 from SimonRichardson/bootstrap-agent-tools
juju#16661 ~~Requires juju#16647 to land.~~ ---- Moves the bootstrap prepareTools that was previously run by the cmd/agent/bootstrap state command, to the bootstrap worker. The strategy is actually in the internal package, which gives us freedom to implement the strategy based on the dependencies. The uploading of the tools only happens on in IAAS models. There is no if isCAAS check, it's up to the dependency engine to give us the right dependencies. The code path becomes branchless on that dependency. The userdataconfig removed the tools binary after it ran, this was problematic as the worker isn't guaranteed to have run with in that window. Removing that code and pushing it into the strategy now ensures it correctly cleans up it's own concern. If the upload fails, the tools file will still be there, allowing us to retry later. Lastly, the big major change is to run the bootstrap worker only if the bootstrap-params file is available. Only once the bootstrap worker has completed do we remove that file. This should allow us to perform retries at a later time if we want to make bootstrapping more reliable. ## Checklist - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing ## QA steps ```shj $ juju bootstrap lxd test --build-agent $ juju enable-ha $ juju add-model default $ juju deploy ubuntu ``` ## Links **Jira card:** JUJU-5136
- Loading branch information
Showing
25 changed files
with
1,014 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright 2023 Canonical Ltd. | ||
// Licensed under the LGPLv3, see LICENCE file for details. | ||
|
||
package bootstrap | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/juju/errors" | ||
"github.com/juju/version/v2" | ||
|
||
agenttools "github.com/juju/juju/agent/tools" | ||
"github.com/juju/juju/core/arch" | ||
coreos "github.com/juju/juju/core/os" | ||
"github.com/juju/juju/state/binarystorage" | ||
jujuversion "github.com/juju/juju/version" | ||
) | ||
|
||
// Logger represents the logging methods called. | ||
type Logger interface { | ||
Errorf(message string, args ...any) | ||
Warningf(message string, args ...any) | ||
Infof(message string, args ...any) | ||
Debugf(message string, args ...any) | ||
} | ||
|
||
const ( | ||
// AgentCompressedBinaryName is the name of the agent binary. | ||
AgentCompressedBinaryName = "tools.tar.gz" | ||
) | ||
|
||
// AgentBinaryStorage is the interface that is used to store the agent binary. | ||
type AgentBinaryStorage interface { | ||
// Add adds the agent binary to the storage. | ||
Add(context.Context, io.Reader, binarystorage.Metadata) error | ||
} | ||
|
||
// PopulateAgentBinary is the function that is used to populate the agent | ||
// binary at bootstrap. | ||
func PopulateAgentBinary(ctx context.Context, dataDir string, storage AgentBinaryStorage, logger Logger) error { | ||
current := version.Binary{ | ||
Number: jujuversion.Current, | ||
Arch: arch.HostArch(), | ||
Release: coreos.HostOSTypeName(), | ||
} | ||
|
||
agentTools, err := agenttools.ReadTools(dataDir, current) | ||
if err != nil { | ||
return fmt.Errorf("cannot read agent binary: %w", err) | ||
} | ||
|
||
rootPath := agenttools.SharedToolsDir(dataDir, current) | ||
binaryPath := filepath.Join(rootPath, AgentCompressedBinaryName) | ||
|
||
data, err := os.ReadFile(binaryPath) | ||
if err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
metadata := binarystorage.Metadata{ | ||
Version: agentTools.Version.String(), | ||
Size: agentTools.Size, | ||
SHA256: agentTools.SHA256, | ||
} | ||
|
||
logger.Debugf("Adding agent binary: %v", agentTools.Version) | ||
if err := storage.Add(ctx, bytes.NewReader(data), metadata); err != nil { | ||
return errors.Trace(err) | ||
} | ||
|
||
// Ensure that we remove the agent binary from disk. | ||
if err := os.Remove(binaryPath); err != nil { | ||
logger.Warningf("failed to remove agent binary: %v", err) | ||
} | ||
// Remove the sha that validates the agent binary file. | ||
shaFilePath := filepath.Join(rootPath, fmt.Sprintf("juju%s.sha256", current.String())) | ||
if err := os.Remove(shaFilePath); err != nil { | ||
logger.Warningf("failed to remove agent binary sha: %v", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.