Skip to content

Commit 4398cff

Browse files
authored
[fast checkin]: work around the config limitations (#11165)
1 parent 1fa0972 commit 4398cff

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

internal/pkg/agent/application/gateway/fleet/fleet_gateway.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func New(
100100
acker acker.Acker,
101101
stateStore stateStore,
102102
stateFetcher StateFetcher,
103-
cfg configuration.FleetCheckin,
103+
cfg *configuration.FleetCheckin,
104104
) (*FleetGateway, error) {
105105
scheduler := scheduler.NewPeriodicJitter(defaultGatewaySettings.Duration, defaultGatewaySettings.Jitter)
106106
st := defaultGatewaySettings
@@ -615,9 +615,13 @@ func (s *CheckinStateFetcher) FetchState(ctx context.Context) (coordinator.State
615615
func (s *CheckinStateFetcher) Done() {}
616616
func (s *CheckinStateFetcher) StartStateWatch(ctx context.Context) error { return nil }
617617

618-
func getBackoffSettings(cfg configuration.FleetCheckin) *backoffSettings {
618+
func getBackoffSettings(cfg *configuration.FleetCheckin) *backoffSettings {
619619
bo := defaultFleetBackoffSettings
620620

621+
if cfg == nil {
622+
return &defaultFleetBackoffSettings
623+
}
624+
621625
if cfg.RequestBackoffInit > 0 {
622626
bo.Init = cfg.RequestBackoffInit
623627
}

internal/pkg/agent/application/managed_mode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (m *managedConfigManager) Run(ctx context.Context) error {
175175
} else {
176176
stateFetcher = fleetgateway.NewCheckinStateFetcher(m.coord.State)
177177
}
178-
m.log.Infof("running managed config manager with checkin mode: %s", m.cfg.Fleet.Checkin.Mode)
178+
m.log.Infof("running managed config manager with checkin mode: %s", m.cfg.Fleet.Checkin.GetMode())
179179

180180
gateway, err := fleetgateway.New(
181181
m.log,

internal/pkg/agent/configuration/fleet.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type FleetAgentConfig struct {
2121
Client remote.Config `config:",inline" yaml:",inline"`
2222
Info *AgentInfo `config:"agent" yaml:"agent"`
2323
Server *FleetServerConfig `config:"server" yaml:"server,omitempty"`
24-
Checkin FleetCheckin `config:"checkin" yaml:"checkin,omitempty"`
24+
Checkin *FleetCheckin `config:"checkin" yaml:"checkin,omitempty"`
2525
}
2626

2727
// Valid validates the required fields for accessing the API.
@@ -54,13 +54,7 @@ func DefaultFleetAgentConfig() *FleetAgentConfig {
5454
Enabled: false,
5555
Client: remote.DefaultClientConfig(),
5656
Info: &AgentInfo{},
57-
Checkin: DefaultFleetCheckin(),
58-
}
59-
}
60-
61-
func DefaultFleetCheckin() FleetCheckin {
62-
return FleetCheckin{
63-
Mode: fleetCheckinModeStandard,
57+
Checkin: nil,
6458
}
6559
}
6660

@@ -71,10 +65,22 @@ type FleetCheckin struct {
7165
}
7266

7367
func (f *FleetCheckin) IsModeOnStateChanged() bool {
74-
return f.Mode == fleetCheckinModeOnStateChanged
68+
return f != nil && f.Mode == fleetCheckinModeOnStateChanged
69+
}
70+
71+
func (f *FleetCheckin) GetMode() string {
72+
if f == nil || f.Mode == "" {
73+
return fleetCheckinModeStandard
74+
}
75+
76+
return f.Mode
7577
}
7678

7779
func (f *FleetCheckin) Validate() error {
80+
if f == nil {
81+
return nil
82+
}
83+
7884
if f.Mode != "" && f.Mode != fleetCheckinModeStandard && f.Mode != fleetCheckinModeOnStateChanged {
7985
return errors.New("checkin.mode must be either 'standard' or 'on_state_change'")
8086
}

internal/pkg/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestCommaParsing(t *testing.T) {
131131
func dumpToYAML(t *testing.T, out string, in interface{}) {
132132
b, err := yaml.Marshal(in)
133133
require.NoError(t, err)
134-
err = os.WriteFile(out, b, 0600)
134+
err = os.WriteFile(out, b, 0o600)
135135
require.NoError(t, err)
136136
}
137137

0 commit comments

Comments
 (0)