Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ingest Manager] Upgrade Action: make source URI optional #21372

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
)

// untar unpacks archive correctly, skips root (symlink, config...) unpacks data/*
func (u *Upgrader) unpack(ctx context.Context, version, sourceURI, archivePath string) (string, error) {
// unpack unpacks archive correctly, skips root (symlink, config...) unpacks data/*
func (u *Upgrader) unpack(ctx context.Context, version, archivePath string) (string, error) {
// unpack must occur in directory that holds the installation directory
// or the extraction will be double nested
var hash string
Expand Down
15 changes: 13 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ func (u *Upgrader) Upgrade(ctx context.Context, a *fleetapi.ActionUpgrade) error
"running under control of the systems supervisor")
}

archivePath, err := u.downloadArtifact(ctx, a.Version, a.SourceURI)
sourceURI, err := u.sourceURI(a.Version, a.SourceURI)
archivePath, err := u.downloadArtifact(ctx, a.Version, sourceURI)
if err != nil {
return err
}

newHash, err := u.unpack(ctx, a.Version, a.SourceURI, archivePath)
newHash, err := u.unpack(ctx, a.Version, archivePath)
if err != nil {
return err
}
Expand Down Expand Up @@ -147,6 +148,16 @@ func (u *Upgrader) Ack(ctx context.Context) error {

return ioutil.WriteFile(markerFile, markerBytes, 0600)
}
func (u *Upgrader) sourceURI(version, retrievedURI string) (string, error) {
if strings.HasSuffix(version, "-SNAPSHOT") && retrievedURI == "" {
return "", errors.New("snapshot upgrade requires source uri", errors.TypeConfig)
}
if retrievedURI != "" {
return retrievedURI, nil
}

return u.settings.SourceURI, nil
}

func rollbackInstall(hash string) {
os.RemoveAll(filepath.Join(paths.Data(), fmt.Sprintf("%s-%s", agentName, hash)))
Expand Down
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/pkg/fleetapi/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ActionUpgrade struct {
ActionID string `json:"id" yaml:"id"`
ActionType string `json:"type" yaml:"type"`
Version string `json:"version" yaml:"version"`
SourceURI string `json:"source_uri" yaml:"source_uri"`
SourceURI string `json:"source_uri,omitempty" yaml:"source_uri,omitempty"`
}

func (a *ActionUpgrade) String() string {
Expand Down