Skip to content

Commit

Permalink
[Ingest Manager] Upgrade Action: make source URI optional (#21372)
Browse files Browse the repository at this point in the history
[Ingest Manager] Upgrade Action: make source URI optional (#21372)
  • Loading branch information
michalpristas committed Oct 1, 2020
1 parent eae9f5c commit f07eeaa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
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

0 comments on commit f07eeaa

Please sign in to comment.