diff --git a/cmd/fleet/main_integration_test.go b/cmd/fleet/main_integration_test.go index 0d0e432465..c9a5099f0f 100644 --- a/cmd/fleet/main_integration_test.go +++ b/cmd/fleet/main_integration_test.go @@ -86,10 +86,9 @@ func (s *agentSuite) TestAgentMode(t *testing.T) { // add a real default fleet server policy policyId := uuid.Must(uuid.NewV4()).String() _, err := dl.CreatePolicy(ctx, bulker, model.Policy{ - PolicyId: policyId, - RevisionIdx: 1, - DefaultFleetServer: true, - Data: policyData, + PolicyId: policyId, + RevisionIdx: 1, + Data: policyData, }) require.NoError(t, err) diff --git a/go.mod b/go.mod index 92fdf358ad..b1619d3232 100644 --- a/go.mod +++ b/go.mod @@ -71,6 +71,7 @@ require ( github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/jcchavezs/porto v0.4.0 // indirect + github.com/jstemmer/go-junit-report v0.9.1 // indirect github.com/mattn/go-colorable v0.1.12 // indirect github.com/prometheus/procfs v0.7.3 // indirect go.elastic.co/apm/module/apmhttprouter v1.14.0 diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index 2f636792b0..d014a8299e 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -34,6 +34,7 @@ func (c *Config) InitDefaults() { c.Inputs = make([]Input, 1) c.Inputs[0].InitDefaults() c.HTTP.InitDefaults() + c.Fleet.DefaultPolicyId = "fleet-server-policy" } // Validate ensures that the configuration is valid. diff --git a/internal/pkg/config/config_test.go b/internal/pkg/config/config_test.go index 6bc42ba9fd..3dea653dca 100644 --- a/internal/pkg/config/config_test.go +++ b/internal/pkg/config/config_test.go @@ -47,6 +47,7 @@ func TestConfig(t *testing.T) { "fleet-logging": { cfg: &Config{ Fleet: Fleet{ + DefaultPolicyId: "fleet-server-policy", Agent: Agent{ ID: "1e4954ce-af37-4731-9f4a-407b08e69e42", Logging: AgentLogging{ @@ -220,6 +221,7 @@ func defaultHTTP() HTTP { func defaultFleet() Fleet { return Fleet{ + DefaultPolicyId: "fleet-server-policy", Agent: Agent{ ID: "1e4954ce-af37-4731-9f4a-407b08e69e42", Logging: AgentLogging{}, diff --git a/internal/pkg/config/fleet.go b/internal/pkg/config/fleet.go index 5cb12d8815..b20a116360 100644 --- a/internal/pkg/config/fleet.go +++ b/internal/pkg/config/fleet.go @@ -50,8 +50,9 @@ type Host struct { // Fleet is the configuration of Agent running inside of Fleet. type Fleet struct { - Agent Agent `config:"agent"` - Host Host `config:"host"` + DefaultPolicyId string `config:"default_policy_id"` + Agent Agent `config:"agent"` + Host Host `config:"host"` } func strToLevel(s string) (zerolog.Level, error) { diff --git a/internal/pkg/dl/policies_integration_test.go b/internal/pkg/dl/policies_integration_test.go index 04f78dc9d3..c0114f2294 100644 --- a/internal/pkg/dl/policies_integration_test.go +++ b/internal/pkg/dl/policies_integration_test.go @@ -23,12 +23,11 @@ import ( func createRandomPolicy(id string, revisionIdx int) model.Policy { now := time.Now().UTC() return model.Policy{ - PolicyId: id, - RevisionIdx: int64(revisionIdx), - CoordinatorIdx: 0, - Data: []byte("{}"), - DefaultFleetServer: false, - Timestamp: now.Format(time.RFC3339), + PolicyId: id, + RevisionIdx: int64(revisionIdx), + CoordinatorIdx: 0, + Data: []byte("{}"), + Timestamp: now.Format(time.RFC3339), } } diff --git a/internal/pkg/model/schema.go b/internal/pkg/model/schema.go index a688f20c28..574b3adc74 100644 --- a/internal/pkg/model/schema.go +++ b/internal/pkg/model/schema.go @@ -296,9 +296,6 @@ type Policy struct { // The opaque payload. Data json.RawMessage `json:"data"` - // True when this policy is the default policy to start Fleet Server - DefaultFleetServer bool `json:"default_fleet_server"` - // The ID of the policy PolicyId string `json:"policy_id"` diff --git a/internal/pkg/policy/self.go b/internal/pkg/policy/self.go index f1b87734e0..0ba533cfbd 100644 --- a/internal/pkg/policy/self.go +++ b/internal/pkg/policy/self.go @@ -45,9 +45,10 @@ type selfMonitorT struct { bulker bulk.Bulk monitor monitor.Monitor - policyId string - status proto.StateObserved_Status - reporter status.Reporter + policyId string + defaultPolicyId string + status proto.StateObserved_Status + reporter status.Reporter policy *model.Policy @@ -70,6 +71,7 @@ func NewSelfMonitor(fleet config.Fleet, bulker bulk.Bulk, monitor monitor.Monito bulker: bulker, monitor: monitor, policyId: policyId, + defaultPolicyId: fleet.DefaultPolicyId, status: proto.StateObserved_STARTING, reporter: reporter, policyF: dl.QueryLatestPolicies, @@ -171,7 +173,7 @@ func (m *selfMonitorT) processPolicies(ctx context.Context, policies []model.Pol if m.policyId != "" && policy.PolicyId == m.policyId { m.policy = &policy break - } else if m.policyId == "" && policy.DefaultFleetServer { + } else if m.policyId == "" && policy.PolicyId == m.defaultPolicyId { m.policy = &policy break } diff --git a/internal/pkg/policy/self_test.go b/internal/pkg/policy/self_test.go index 38dcc7b4a7..53958c7422 100644 --- a/internal/pkg/policy/self_test.go +++ b/internal/pkg/policy/self_test.go @@ -11,11 +11,12 @@ import ( "context" "encoding/json" "fmt" - "github.com/elastic/fleet-server/v7/internal/pkg/config" "sync" "testing" "time" + "github.com/elastic/fleet-server/v7/internal/pkg/config" + "github.com/elastic/elastic-agent-client/v7/pkg/proto" "github.com/gofrs/uuid" "github.com/rs/xid" @@ -33,6 +34,7 @@ func TestSelfMonitor_DefaultPolicy(t *testing.T) { defer cancel() cfg := config.Fleet{ + DefaultPolicyId: "fleet-server-policy", Agent: config.Agent{ ID: "agent-id", }, @@ -70,7 +72,7 @@ func TestSelfMonitor_DefaultPolicy(t *testing.T) { return nil }, ftesting.RetrySleep(1*time.Second)) - policyId := uuid.Must(uuid.NewV4()).String() + policyId := "fleet-server-policy" rId := xid.New().String() policyContents, err := json.Marshal(&policyData{Inputs: []policyInput{}}) if err != nil { @@ -82,11 +84,10 @@ func TestSelfMonitor_DefaultPolicy(t *testing.T) { Version: 1, SeqNo: 1, }, - PolicyId: policyId, - CoordinatorIdx: 1, - Data: policyContents, - RevisionIdx: 1, - DefaultFleetServer: true, + PolicyId: policyId, + CoordinatorIdx: 1, + Data: policyContents, + RevisionIdx: 1, } pData, err := json.Marshal(&policy) if err != nil { @@ -130,11 +131,10 @@ func TestSelfMonitor_DefaultPolicy(t *testing.T) { Version: 1, SeqNo: 1, }, - PolicyId: policyId, - CoordinatorIdx: 1, - Data: policyContents, - RevisionIdx: 2, - DefaultFleetServer: true, + PolicyId: policyId, + CoordinatorIdx: 1, + Data: policyContents, + RevisionIdx: 2, } pData, err = json.Marshal(&policy) if err != nil { @@ -175,6 +175,7 @@ func TestSelfMonitor_DefaultPolicy_Degraded(t *testing.T) { defer cancel() cfg := config.Fleet{ + DefaultPolicyId: "fleet-server-policy", Agent: config.Agent{ ID: "", }, @@ -226,7 +227,7 @@ func TestSelfMonitor_DefaultPolicy_Degraded(t *testing.T) { return nil }, ftesting.RetrySleep(1*time.Second)) - policyId := uuid.Must(uuid.NewV4()).String() + policyId := "fleet-server-policy" rId := xid.New().String() policyContents, err := json.Marshal(&policyData{Inputs: []policyInput{ { @@ -242,11 +243,10 @@ func TestSelfMonitor_DefaultPolicy_Degraded(t *testing.T) { Version: 1, SeqNo: 1, }, - PolicyId: policyId, - CoordinatorIdx: 1, - Data: policyContents, - RevisionIdx: 1, - DefaultFleetServer: true, + PolicyId: policyId, + CoordinatorIdx: 1, + Data: policyContents, + RevisionIdx: 1, } policyData, err := json.Marshal(&policy) if err != nil { @@ -392,11 +392,10 @@ func TestSelfMonitor_SpecificPolicy(t *testing.T) { Version: 1, SeqNo: 1, }, - PolicyId: policyId, - CoordinatorIdx: 1, - Data: policyContents, - RevisionIdx: 2, - DefaultFleetServer: true, + PolicyId: policyId, + CoordinatorIdx: 1, + Data: policyContents, + RevisionIdx: 2, } pData, err := json.Marshal(&policy) if err != nil { @@ -440,11 +439,10 @@ func TestSelfMonitor_SpecificPolicy(t *testing.T) { Version: 1, SeqNo: 2, }, - PolicyId: policyId, - CoordinatorIdx: 1, - Data: policyContents, - RevisionIdx: 1, - DefaultFleetServer: true, + PolicyId: policyId, + CoordinatorIdx: 1, + Data: policyContents, + RevisionIdx: 1, } pData, err = json.Marshal(&policy) if err != nil { @@ -552,11 +550,10 @@ func TestSelfMonitor_SpecificPolicy_Degraded(t *testing.T) { Version: 1, SeqNo: 1, }, - PolicyId: policyId, - CoordinatorIdx: 1, - Data: policyContents, - RevisionIdx: 1, - DefaultFleetServer: true, + PolicyId: policyId, + CoordinatorIdx: 1, + Data: policyContents, + RevisionIdx: 1, } policyData, err := json.Marshal(&policy) if err != nil {