-
Notifications
You must be signed in to change notification settings - Fork 129
Add --agent-version flag for flexible Elastic Agent version configuration
#3054
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
b129fcd
3391c07
9c4c92c
f454532
48154ae
ac8ab2d
941b096
0d329d6
c2213b4
b4267a1
4c62f33
5925e0b
300ba8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ import ( | |
| type KubernetesAgentDeployer struct { | ||
| profile *profile.Profile | ||
| stackVersion string | ||
| agentVersion string | ||
| policyName string | ||
| dataStream string | ||
|
|
||
|
|
@@ -40,6 +41,7 @@ type KubernetesAgentDeployer struct { | |
| type KubernetesAgentDeployerOptions struct { | ||
| Profile *profile.Profile | ||
| StackVersion string | ||
| AgentVersion string | ||
| PolicyName string | ||
| DataStream string | ||
|
|
||
|
|
@@ -53,11 +55,12 @@ type kubernetesDeployedAgent struct { | |
| profile *profile.Profile | ||
| stackVersion string | ||
|
|
||
| agentName string | ||
| agentName string | ||
| agentVersion string | ||
| } | ||
|
|
||
| func (s kubernetesDeployedAgent) TearDown(ctx context.Context) error { | ||
| elasticAgentManagedYaml, err := getElasticAgentYAML(ctx, s.profile, s.agentInfo, s.stackVersion, s.agentName) | ||
| elasticAgentManagedYaml, err := getElasticAgentYAML(ctx, s.profile, s.agentInfo, s.stackVersion, s.agentName, s.agentVersion) | ||
| if err != nil { | ||
| return fmt.Errorf("can't retrieve Kubernetes file for Elastic Agent: %w", err) | ||
| } | ||
|
|
@@ -92,6 +95,7 @@ func NewKubernetesAgentDeployer(opts KubernetesAgentDeployerOptions) (*Kubernete | |
| return &KubernetesAgentDeployer{ | ||
| profile: opts.Profile, | ||
| stackVersion: opts.StackVersion, | ||
| agentVersion: opts.AgentVersion, | ||
| policyName: opts.PolicyName, | ||
| dataStream: opts.DataStream, | ||
| runSetup: opts.RunSetup, | ||
|
|
@@ -123,7 +127,7 @@ func (ksd *KubernetesAgentDeployer) SetUp(ctx context.Context, agentInfo AgentIn | |
| if ksd.runTearDown || ksd.runTestsOnly { | ||
| logger.Debug("Skip install Elastic Agent in cluster") | ||
| } else { | ||
| err = installElasticAgentInCluster(ctx, ksd.profile, agentInfo, ksd.stackVersion, agentName) | ||
| err = installElasticAgentInCluster(ctx, ksd.profile, agentInfo, ksd.stackVersion, agentName, ksd.agentVersion) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("can't install Elastic-Agent in the Kubernetes cluster: %w", err) | ||
| } | ||
|
|
@@ -139,6 +143,7 @@ func (ksd *KubernetesAgentDeployer) SetUp(ctx context.Context, agentInfo AgentIn | |
| profile: ksd.profile, | ||
| stackVersion: ksd.stackVersion, | ||
| agentName: agentName, | ||
| agentVersion: ksd.agentVersion, | ||
| }, nil | ||
| } | ||
|
|
||
|
|
@@ -155,10 +160,10 @@ func (ksd *KubernetesAgentDeployer) agentName() string { | |
|
|
||
| var _ AgentDeployer = new(KubernetesAgentDeployer) | ||
|
|
||
| func installElasticAgentInCluster(ctx context.Context, profile *profile.Profile, agentInfo AgentInfo, stackVersion, agentName string) error { | ||
| func installElasticAgentInCluster(ctx context.Context, profile *profile.Profile, agentInfo AgentInfo, stackVersion, agentName, agentVersion string) error { | ||
| logger.Debug("install Elastic Agent in the Kubernetes cluster") | ||
|
|
||
| elasticAgentManagedYaml, err := getElasticAgentYAML(ctx, profile, agentInfo, stackVersion, agentName) | ||
| elasticAgentManagedYaml, err := getElasticAgentYAML(ctx, profile, agentInfo, stackVersion, agentName, agentVersion) | ||
| if err != nil { | ||
| return fmt.Errorf("can't retrieve Kubernetes file for Elastic Agent: %w", err) | ||
| } | ||
|
|
@@ -176,8 +181,8 @@ func installElasticAgentInCluster(ctx context.Context, profile *profile.Profile, | |
| //go:embed _static/elastic-agent-managed.yaml.tmpl | ||
| var elasticAgentManagedYamlTmpl string | ||
|
|
||
| func getElasticAgentYAML(ctx context.Context, profile *profile.Profile, agentInfo AgentInfo, stackVersion, agentName string) ([]byte, error) { | ||
| logger.Debugf("Prepare YAML definition for Elastic Agent running in stack v%s", stackVersion) | ||
| func getElasticAgentYAML(ctx context.Context, profile *profile.Profile, agentInfo AgentInfo, stackVersion, agentName, agentVersion string) ([]byte, error) { | ||
| logger.Debugf("Prepare YAML definition for Elastic Agent (v%s) running in stack v%s", agentVersion, stackVersion) | ||
| config, err := stack.LoadConfig(profile) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to load config from profile: %w", err) | ||
|
|
@@ -191,7 +196,7 @@ func getElasticAgentYAML(ctx context.Context, profile *profile.Profile, agentInf | |
| fleetURL = url | ||
| } | ||
| if version, ok := config.Parameters[stack.ParamServerlessLocalStackVersion]; ok { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it should be the other way around, if a user is setting a flag in the command line, this value should be prioritized over the one in config files. |
||
| stackVersion = version | ||
| agentVersion = version | ||
| } | ||
|
|
||
| enrollmentToken := "" | ||
|
|
@@ -207,7 +212,7 @@ func getElasticAgentYAML(ctx context.Context, profile *profile.Profile, agentInf | |
| } | ||
| } | ||
|
|
||
| appConfig, err := install.Configuration(install.OptionWithStackVersion(stackVersion)) | ||
| appConfig, err := install.Configuration(install.OptionWithAgentVersion(agentVersion)) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("can't read application configuration: %w", err) | ||
| } | ||
|
|
@@ -228,7 +233,7 @@ func getElasticAgentYAML(ctx context.Context, profile *profile.Profile, agentInf | |
| "enrollmentToken": enrollmentToken, | ||
| "caCertPem": caCert, | ||
| "elasticAgentImage": appConfig.StackImageRefs().ElasticAgent, | ||
| "elasticAgentTokenPolicyName": getTokenPolicyName(stackVersion, agentInfo.Policy.Name), | ||
| "elasticAgentTokenPolicyName": getTokenPolicyName(agentVersion, agentInfo.Policy.Name), | ||
| "agentName": agentName, | ||
| }) | ||
| if err != nil { | ||
|
|
@@ -255,8 +260,8 @@ func readCACertBase64(profile *profile.Profile) (string, error) { | |
| // getTokenPolicyName function returns the policy name for the >= 8.x Elastic stacks. The agent's policy | ||
| // is predefined in the Kibana configuration file. The logic is not present in older stacks and it uses | ||
| // the default policy in Kibana (empty string). | ||
| func getTokenPolicyName(stackVersion, policyName string) string { | ||
| if strings.HasPrefix(stackVersion, "7.") { | ||
| func getTokenPolicyName(agentVersion, policyName string) string { | ||
| if strings.HasPrefix(agentVersion, "7.") { | ||
| return "" | ||
| } | ||
| return policyName | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
servicecmd needs an agent version definition? or the default (same as stack) is used?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess deployers that manage their own agents could use this version, though not sure if we need a different setting for stack and agent version 🤔
In any case this is internal by now, right? No change for users.