Skip to content

Skip error uninstalling system package#1315

Merged
mrodm merged 9 commits intoelastic:mainfrom
mrodm:skip_error_uninstall_system_package
Jun 21, 2023
Merged

Skip error uninstalling system package#1315
mrodm merged 9 commits intoelastic:mainfrom
mrodm:skip_error_uninstall_system_package

Conversation

@mrodm
Copy link
Copy Markdown
Contributor

@mrodm mrodm commented Jun 20, 2023

This PR has two goals:

  • skip errors when system package is uninstalled
  • fix error management in tear down process

Currently, system package is being used by default as part of another agent policy. Because of that, when system or asset tests finish and try to uninstall the package, if this package is system, this fails with this error:

[2023-06-19T09:20:47.479Z] Error: error running package system tests: could not complete test run: failed to tear down runner: failed to uninstall package: can't remove the package: could not remove package; API status code = 400; response body = {"statusCode":400,"error":"Bad Request","message":"unable to remove package with existing package policy(s) in use by agent(s)"}

As part of this PR, asset tests has also been checked and fixed since this test runner also performs the uninstallation of the package.

@mrodm mrodm self-assigned this Jun 20, 2023
@mrodm
Copy link
Copy Markdown
Contributor Author

mrodm commented Jun 20, 2023

test integrations

@elasticmachine
Copy link
Copy Markdown
Collaborator

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6619

@mrodm
Copy link
Copy Markdown
Contributor Author

mrodm commented Jun 20, 2023

Created or updated PR in integrations repostiory to test this vesrion. Check elastic/integrations#6619

system package has been fixed

Comment on lines +504 to +509
switch pkgManifest.Name {
case "system":
logger.Debugf("failed to uninstall package %q: %s", pkgManifest.Name, err.Error())
default:
logger.Warnf("failed to uninstall package %q: %s", pkgManifest.Name, err.Error())
}
Copy link
Copy Markdown
Contributor Author

@mrodm mrodm Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also show a Debug message in case system package fails ? It will always fail. Same for asset runner.

If not this code could be just changed to be something like:

		// by default system package is part of an agent policy and it cannot be uninstalled
		// https://github.com/elastic/elastic-package/blob/5f65dc29811c57454bc7142aaf73725b6d4dc8e6/internal/stack/_static/kibana.yml.tmpl#L62
		if err != nil && pkgManifest.Name != "system" {
			logger.Warnf("failed to uninstall package %q: %s", pkgManifest.Name, err.Error())
		}
		return nil

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's log the error only for other packages.

@mrodm mrodm requested a review from a team June 20, 2023 10:13
@mrodm mrodm marked this pull request as ready for review June 20, 2023 10:14
@mrodm mrodm requested a review from jsoriano June 20, 2023 11:07
// by default system package is part of an agent policy and it cannot be uninstalled
// https://github.com/elastic/elastic-package/blob/5f65dc29811c57454bc7142aaf73725b6d4dc8e6/internal/stack/_static/kibana.yml.tmpl#L62
if err != nil && pkgManifest.Name != "system" {
logger.Warnf("failed to uninstall package %q: %s", pkgManifest.Name, err.Error())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be also good to add a comment here about why we are only logging the error and not returning it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment to explain it 6e0af5e

@elasticmachine
Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

History

cc @mrodm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants