diff --git a/cli/config/compose/services/elastic-agent/docker-compose.yml b/cli/config/compose/services/elastic-agent/docker-compose.yml index 6ffb88e44a..471df73b48 100644 --- a/cli/config/compose/services/elastic-agent/docker-compose.yml +++ b/cli/config/compose/services/elastic-agent/docker-compose.yml @@ -10,6 +10,14 @@ services: condition: service_healthy environment: - "KIBANA_HOST=http://${kibanaHost:-kibana}:${kibanaPort:-5601}" + - "FLEET_SERVER_ENABLE=${fleetServerMode:-0}" + - "FLEET_SERVER_INSECURE_HTTP=${fleetServerMode:-0}" + - "KIBANA_FLEET_SETUP=${fleetServerMode:-0}" + - "FLEET_SERVER_HOST=0.0.0.0" + - "KIBANA_USERNAME=elastic" + - "KIBANA_PASSWORD=changeme" platform: ${elasticAgentPlatform:-linux/amd64} + ports: + - "127.0.0.1:8220:8220" volumes: - "${elasticAgentConfigFile}:/usr/share/elastic-agent/elastic-agent.yml" diff --git a/e2e/_suites/fleet/features/stand_alone_agent.feature b/e2e/_suites/fleet/features/stand_alone_agent.feature index 5842cd57cb..af05676a92 100644 --- a/e2e/_suites/fleet/features/stand_alone_agent.feature +++ b/e2e/_suites/fleet/features/stand_alone_agent.feature @@ -50,3 +50,13 @@ Examples: default Examples: Ubi8 | image | | ubi8 | + +@run_fleet_server +Scenario Outline: Deploying a stand-alone agent with fleet server mode + When a "" stand-alone agent is deployed with fleet server mode + Then the agent is listed in Fleet as "online" + +@default +Examples: default + | image | + | default | diff --git a/e2e/_suites/fleet/fleet.go b/e2e/_suites/fleet/fleet.go index cc9c3e27f4..267c01a260 100644 --- a/e2e/_suites/fleet/fleet.go +++ b/e2e/_suites/fleet/fleet.go @@ -406,6 +406,10 @@ func (fts *FleetTestSuite) setup() error { } func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus string) error { + return theAgentIsListedInFleetWithStatus(desiredStatus, fts.Hostname) +} + +func theAgentIsListedInFleetWithStatus(desiredStatus, hostname string) error { log.Tracef("Checking if agent is listed in Fleet as %s", desiredStatus) maxTimeout := time.Duration(timeoutFactor) * time.Minute * 2 @@ -414,7 +418,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin exp := e2e.GetExponentialBackOff(maxTimeout) agentOnlineFn := func() error { - agentID, err := getAgentID(fts.Hostname) + agentID, err := getAgentID(hostname) if err != nil { retryCount++ return err @@ -425,7 +429,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin if desiredStatus == "offline" || desiredStatus == "inactive" { log.WithFields(log.Fields{ "elapsedTime": exp.GetElapsedTime(), - "hostname": fts.Hostname, + "hostname": hostname, "retries": retryCount, "status": desiredStatus, }).Info("The Agent is not present in Fleet, as expected") @@ -446,7 +450,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin "agentID": agentID, "isAgentInStatus": isAgentInStatus, "elapsedTime": exp.GetElapsedTime(), - "hostname": fts.Hostname, + "hostname": hostname, "retry": retryCount, "status": desiredStatus, }).Warn(err.Error()) @@ -459,7 +463,7 @@ func (fts *FleetTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus strin log.WithFields(log.Fields{ "isAgentInStatus": isAgentInStatus, "elapsedTime": exp.GetElapsedTime(), - "hostname": fts.Hostname, + "hostname": hostname, "retries": retryCount, "status": desiredStatus, }).Info("The Agent is in the desired status") diff --git a/e2e/_suites/fleet/stand-alone.go b/e2e/_suites/fleet/stand-alone.go index 0915df4c2d..9f219ee323 100644 --- a/e2e/_suites/fleet/stand-alone.go +++ b/e2e/_suites/fleet/stand-alone.go @@ -64,12 +64,27 @@ func (sats *StandAloneTestSuite) afterScenario() { func (sats *StandAloneTestSuite) contributeSteps(s *godog.ScenarioContext) { s.Step(`^a "([^"]*)" stand-alone agent is deployed$`, sats.aStandaloneAgentIsDeployed) + s.Step(`^a "([^"]*)" stand-alone agent is deployed with fleet server mode$`, sats.aStandaloneAgentIsDeployedWithFleetServerMode) s.Step(`^there is new data in the index from agent$`, sats.thereIsNewDataInTheIndexFromAgent) s.Step(`^the "([^"]*)" docker container is stopped$`, sats.theDockerContainerIsStopped) s.Step(`^there is no new data in the index after agent shuts down$`, sats.thereIsNoNewDataInTheIndexAfterAgentShutsDown) + s.Step(`^the agent is listed in Fleet as "([^"]*)"$`, sats.theAgentIsListedInFleetWithStatus) +} + +func (sats *StandAloneTestSuite) theAgentIsListedInFleetWithStatus(desiredStatus string) error { + return theAgentIsListedInFleetWithStatus(desiredStatus, sats.Hostname) +} + +func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployedWithFleetServerMode(image string) error { + return sats.startAgent(image, map[string]string{"fleetServerMode": "1"}) } func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed(image string) error { + return sats.startAgent(image, nil) +} + +func (sats *StandAloneTestSuite) startAgent(image string, env map[string]string) error { + log.Trace("Deploying an agent to Fleet") dockerImageTag := agentVersion @@ -110,6 +125,10 @@ func (sats *StandAloneTestSuite) aStandaloneAgentIsDeployed(image string) error profileEnv["elasticAgentPlatform"] = "linux/amd64" profileEnv["elasticAgentTag"] = dockerImageTag + for k, v := range env { + profileEnv[k] = v + } + err = serviceManager.AddServicesToCompose(context.Background(), FleetProfileName, []string{ElasticAgentServiceName}, profileEnv) if err != nil { log.Error("Could not deploy the elastic-agent")