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 2 commits
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
32 changes: 32 additions & 0 deletions changelog/fragments/1733248787-flag-to-skip-fleet-audit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: enhancement

# Change summary; a 80ish characters long description of the change.
summary: Add a flag to skip audit/unenroll call to fleet server during uninstall

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
description: This change adds a flag to skip audit/unenroll call to fleet server. While uninstalling elastic-agent it tries to notify fleet server about the uninstallation. But in somecases users might know that the fleet server is unreachable and this notification logs multiple failures continuously. Adding this flag skips this call.

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: "elastic-agent"

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: https://github.com/owner/repo/1234
4 changes: 2 additions & 2 deletions internal/pkg/agent/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
return err
}
} else {
err := install.Uninstall(cmd.Context(), cfgFile, topPath, "", log, progBar)
err := install.Uninstall(cmd.Context(), cfgFile, topPath, "", log, progBar, false)
if err != nil {
progBar.Describe("Uninstall from binary failed")
return err
Expand All @@ -276,7 +276,7 @@ func installCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
defer func() {
if err != nil {
progBar.Describe("Uninstalling")
innerErr := install.Uninstall(cmd.Context(), cfgFile, topPath, "", log, progBar)
innerErr := install.Uninstall(cmd.Context(), cfgFile, topPath, "", log, progBar, false)
if innerErr != nil {
progBar.Describe("Failed to Uninstall")
} else {
Expand Down
4 changes: 3 additions & 1 deletion internal/pkg/agent/cmd/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Unless -f is used this command will ask confirmation before performing removal.

cmd.Flags().BoolP("force", "f", false, "Force overwrite the current and do not prompt for confirmation")
cmd.Flags().String("uninstall-token", "", "Uninstall token required for protected agent uninstall")
cmd.Flags().Bool("skip-fleet-audit", false, "Skip fleet audit/unenroll")

return cmd
}
Expand All @@ -60,6 +61,7 @@ func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command) error {

force, _ := cmd.Flags().GetBool("force")
uninstallToken, _ := cmd.Flags().GetString("uninstall-token")
skipFleetAudit, _ := cmd.Flags().GetBool("skip-fleet-audit")
if status == install.Broken {
if !force {
fmt.Fprintf(streams.Out, "Elastic Agent is installed but currently broken: %s\n", reason)
Expand Down Expand Up @@ -94,7 +96,7 @@ func uninstallCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
fmt.Fprint(os.Stderr, logBuff.String())
}()

err = install.Uninstall(cmd.Context(), paths.ConfigFile(), paths.Top(), uninstallToken, log, progBar)
err = install.Uninstall(cmd.Context(), paths.ConfigFile(), paths.Top(), uninstallToken, log, progBar, skipFleetAudit)
if err != nil {
progBar.Describe("Failed to uninstall agent")
return fmt.Errorf("error uninstalling agent: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
)

// Uninstall uninstalls persistently Elastic Agent on the system.
func Uninstall(ctx context.Context, cfgFile, topPath, uninstallToken string, log *logp.Logger, pt *progressbar.ProgressBar) error {
func Uninstall(ctx context.Context, cfgFile, topPath, uninstallToken string, log *logp.Logger, pt *progressbar.ProgressBar, skipFleetAudit bool) error {
cwd, err := os.Getwd()
if err != nil {
return fmt.Errorf("unable to get current working directory")
Expand Down Expand Up @@ -146,7 +146,7 @@ func Uninstall(ctx context.Context, cfgFile, topPath, uninstallToken string, log

// 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 notifyFleet && 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
Loading