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] Copy Action store on upgrade #21298

Merged
merged 5 commits into from
Sep 24, 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
2 changes: 2 additions & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- Docker container is not run as root by default. {pull}21213[21213]

==== Bugfixes
- Copy Action store on upgrade {pull}21298[21298]
- Include inputs in action store actions {pull}21298[21298]

==== New features

Expand Down
6 changes: 5 additions & 1 deletion x-pack/elastic-agent/pkg/agent/application/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"gopkg.in/yaml.v2"

"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
Expand Down Expand Up @@ -54,7 +55,10 @@ func LoadConfigFromFile(path string) (*config.Config, error) {
//
// This must be used to load the Agent configuration, so that variables defined in the inputs are not
// parsed by go-ucfg. Variables from the inputs should be parsed by the transpiler.
func LoadConfig(m map[string]interface{}) (*config.Config, error) {
func LoadConfig(in map[string]interface{}) (*config.Config, error) {
// make copy of a map so we dont affect a caller
m := common.MapStr(in).Clone()

inputs, ok := m["inputs"]
if ok {
// remove the inputs
Expand Down
23 changes: 23 additions & 0 deletions x-pack/elastic-agent/pkg/agent/application/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"gopkg.in/yaml.v2"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/artifact"
Expand Down Expand Up @@ -78,6 +79,10 @@ func (u *Upgrader) Upgrade(ctx context.Context, a *fleetapi.ActionUpgrade) error
return errors.New("upgrading to same version")
}

if err := copyActionStore(newHash); err != nil {
return errors.New(err, "failed to copy action store")
}

if err := u.changeSymlink(ctx, newHash); err != nil {
rollbackInstall(newHash)
return err
Expand Down Expand Up @@ -137,3 +142,21 @@ func isSubdir(base, target string) (bool, error) {
func rollbackInstall(hash string) {
os.RemoveAll(filepath.Join(paths.Data(), fmt.Sprintf("%s-%s", agentName, hash)))
}

func copyActionStore(newHash string) error {
currentActionStorePath := info.AgentActionStoreFile()

newHome := filepath.Join(filepath.Dir(paths.Home()), fmt.Sprintf("%s-%s", agentName, newHash))
newActionStorePath := filepath.Join(newHome, filepath.Base(currentActionStorePath))

currentActionStore, err := ioutil.ReadFile(currentActionStorePath)
if os.IsNotExist(err) {
// nothing to copy
return nil
}
if err != nil {
return err
}

return ioutil.WriteFile(newActionStorePath, currentActionStore, 0600)
}