Skip to content
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

Added skip audit/unenroll flag to uninstall command #6206

Merged
merged 21 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
888e63f
Added skip audit/unenroll flag to uninstall command
Rohit-code14 Dec 4, 2024
b2983da
Merge branch 'elastic:main' into main
Rohit-code14 Dec 4, 2024
b5fb853
Added tests for skip-fleet-audit flag
Rohit-code14 Dec 10, 2024
b8405a0
Merge branch 'elastic:main' into main
Rohit-code14 Dec 10, 2024
b659cc2
Added tests for skip-fleet-audit flag
Rohit-code14 Dec 10, 2024
848e325
Merge branch 'main' of https://github.com/Rohit-code14/elastic-agent
Rohit-code14 Dec 10, 2024
17bd84d
Added tests for skip-fleet-audit flag
Rohit-code14 Dec 10, 2024
a6d5bd9
Merge branch 'elastic:main' into main
Rohit-code14 Dec 11, 2024
2d1d8b4
Merge branch 'main' into main
Rohit-code14 Dec 12, 2024
8d57889
Merge branch 'main' into main
Rohit-code14 Dec 13, 2024
0e12052
ran mage fmt
Rohit-code14 Dec 14, 2024
b0b048c
Merge branch 'main' into main
Rohit-code14 Dec 14, 2024
2b8165b
Merge branch 'main' into main
Rohit-code14 Dec 17, 2024
8874f84
Resolved conflicts
Rohit-code14 Dec 18, 2024
e058a38
Merge branch 'main' into main
Rohit-code14 Dec 19, 2024
9d83f96
Test all combinations for which fleet audit/unenroll will be skipped
Rohit-code14 Dec 19, 2024
e2cfb10
Merge branch 'main' of https://github.com/Rohit-code14/elastic-agent
Rohit-code14 Dec 19, 2024
ba3eb1f
Merge branch 'main' into main
Rohit-code14 Dec 23, 2024
cd45ac2
Merge branch 'main' into main
michalpristas Dec 27, 2024
4bb8dcb
Merge branch 'main' into main
Rohit-code14 Dec 27, 2024
92c8b58
Merge branch 'main' into main
Rohit-code14 Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added tests for skip-fleet-audit flag
  • Loading branch information
Rohit-code14 committed Dec 10, 2024
commit b659cc2a83fa4f607fb262a622f912d485797f2c
12 changes: 7 additions & 5 deletions internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func Uninstall(ctx context.Context, cfgFile, topPath, uninstallToken string, log
}
}

// will only notify fleet of the uninstall command if it can gather config and agentinfo, and is not a stand-alone install
notifyFleet := false
var ai *info.AgentInfo
c, err := operations.LoadFullAgentConfig(ctx, log, cfgFile, false, unprivileged)
if err != nil {
Expand All @@ -125,7 +127,8 @@ func Uninstall(ctx context.Context, cfgFile, topPath, uninstallToken string, log
ai, err = info.NewAgentInfo(ctx, false)
if err != nil {
pt.Describe(fmt.Sprintf("unable to read agent info, Fleet will not be notified of uninstall: %v", err))
skipFleetAudit = true
} else {
notifyFleet = true
}
}

Expand All @@ -141,15 +144,14 @@ func Uninstall(ctx context.Context, cfgFile, topPath, uninstallToken string, log
}
pt.Describe("Removed install directory")

notifyFleetIfNeeded(ctx, log, pt, cfg, ai, skipFleetAudit, notifyFleetAuditUninstall)
notifyFleetIfNeeded(ctx, log, pt, cfg, ai, notifyFleet, skipFleetAudit, notifyFleetAuditUninstall)
return nil
}

func notifyFleetIfNeeded(ctx context.Context, log *logp.Logger, pt *progressbar.ProgressBar, cfg *configuration.Configuration, ai *info.AgentInfo, skipFleetAudit bool, notifyFleetAuditUninstall NotifyFleetAuditUninstall) {
// will only notify fleet of the uninstall command if it can gather config and agentinfo, and is not a stand-alone install
func notifyFleetIfNeeded(ctx context.Context, log *logp.Logger, pt *progressbar.ProgressBar, cfg *configuration.Configuration, ai *info.AgentInfo, notifyFleet, skipFleetAudit bool, notifyFleetAuditUninstall NotifyFleetAuditUninstall) {
// Skip on Windows because of https://github.com/elastic/elastic-agent/issues/5952
// Once the root-cause is identified then this can be re-enabled on Windows.
if ai != nil && cfg != nil && !skipFleetAudit && runtime.GOOS != "windows" {
if notifyFleet && runtime.GOOS != "windows" && !skipFleetAudit {
notifyFleetAuditUninstall(ctx, log, pt, cfg, ai) //nolint:errcheck // ignore the error as we can't act on it)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/agent/install/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@ func TestSkipFleetAuditUnenroll(t *testing.T) {
cfg := &configuration.Configuration{}

mockNotify := &MockNotifyFleetAuditUninstall{}
notifyFleetIfNeeded(context.Background(), log, pt, cfg, ai, true, notifyFleetAuditUninstall)
notifyFleetIfNeeded(context.Background(), log, pt, cfg, ai, true, true, notifyFleetAuditUninstall)
assert.False(t, mockNotify.Called, "NotifyFleetAuditUninstall should not be called when skipFleetAudit is true")
}