forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Ingest Manager] Agent unenroll (elastic#19507)
- Loading branch information
1 parent
985d0eb
commit 248b1e9
Showing
20 changed files
with
213 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
x-pack/elastic-agent/pkg/agent/application/handler_action_unenroll.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package application | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/program" | ||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger" | ||
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/fleetapi" | ||
) | ||
|
||
// After running Unenroll agent is in idle state, non managed non standalone. | ||
// For it to be operational again it needs to be either enrolled or reconfigured. | ||
type handlerUnenroll struct { | ||
log *logger.Logger | ||
emitter emitterFunc | ||
dispatcher programsDispatcher | ||
closers []context.CancelFunc | ||
} | ||
|
||
func (h *handlerUnenroll) Handle(ctx context.Context, a action, acker fleetAcker) error { | ||
h.log.Debugf("handlerUnenroll: action '%+v' received", a) | ||
action, ok := a.(*fleetapi.ActionUnenroll) | ||
if !ok { | ||
return fmt.Errorf("invalid type, expected ActionUnenroll and received %T", a) | ||
} | ||
|
||
// Providing empty map will close all pipelines | ||
noPrograms := make(map[routingKey][]program.Program) | ||
h.dispatcher.Dispatch(a.ID(), noPrograms) | ||
|
||
if err := acker.Ack(ctx, action); err != nil { | ||
return err | ||
} | ||
|
||
// commit all acks before quitting. | ||
if err := acker.Commit(ctx); err != nil { | ||
return err | ||
} | ||
|
||
// close fleet gateway loop | ||
for _, c := range h.closers { | ||
c() | ||
} | ||
|
||
// clean action store | ||
// if err := os.Remove(info.AgentActionStoreFile()); err != nil && !os.IsNotExist(err) { | ||
// return errors.New(err, "failed to clear action store") | ||
// } | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.