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

Feature/4890 detect fail early upgrade #5864

Merged
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
57e54a0
feature(4890): added shouldUpgrade function in the upgrade cli file
kaanyalti Oct 24, 2024
94ad0c3
feature(4890): added shouldUpgrade check into the upgrade command
kaanyalti Oct 24, 2024
3a4b97c
feature(4890): ran gofmt
kaanyalti Oct 24, 2024
accbd22
feature(4890): added a "force" flag, marked it as hidden
kaanyalti Oct 24, 2024
0339dff
feature(4890): removed dpkg, rpm and container logic
kaanyalti Oct 25, 2024
36b3a23
feature(4890): ran gofmt
kaanyalti Oct 25, 2024
e9f4fb5
feature(4890): updated the function signature of the upgrade command,…
kaanyalti Oct 26, 2024
b0b9b82
feature(4890): update comments
kaanyalti Oct 26, 2024
05195ae
feature(4890): added changelog fragment
kaanyalti Oct 26, 2024
21b09af
feature(4890): added fatal log in case there is an error while markin…
kaanyalti Oct 26, 2024
7853878
feature(4890): added error checks in tests
kaanyalti Oct 26, 2024
89f3e0d
feature(4890): updated the summary in the changelog fragment
kaanyalti Oct 28, 2024
0e9b791
feature(4890): removed the shorthand flag for the force flag
kaanyalti Oct 28, 2024
621b465
feature(4890): updated synchronization in the tests
kaanyalti Oct 28, 2024
7acd42e
Update internal/pkg/agent/cmd/upgrade_test.go
kaanyalti Oct 28, 2024
7c66dd1
feature(4890): using streams err output instead of defaulting to stderr
kaanyalti Oct 28, 2024
fde8ef3
feature(4890): use EXPECT instead of On
kaanyalti Oct 28, 2024
dabd25e
feature(4890): moved unconfirmed upgrade error to a package var
kaanyalti Oct 28, 2024
54d4da3
feature(4890): removed confirmation from upgrade check for when force…
kaanyalti Oct 29, 2024
073222c
Update internal/pkg/agent/cmd/upgrade.go
kaanyalti Oct 31, 2024
f2f5691
Update internal/pkg/agent/cmd/upgrade.go
kaanyalti Oct 31, 2024
5c6d62c
feature(4890): fix errors
kaanyalti Oct 31, 2024
1c1f99a
Update internal/pkg/agent/cmd/upgrade.go
kaanyalti Nov 1, 2024
3df1347
feature(4890): update test
kaanyalti Nov 5, 2024
6d26eb2
fearure(4890): replace ageninfo with state call
kaanyalti Nov 6, 2024
6bf8867
feature(4890): updated proto, client and server implementation
kaanyalti Nov 6, 2024
7d99902
feature(4890): fix struct tag
kaanyalti Nov 6, 2024
fe3e91e
feature(4890): added skip-verify checks
kaanyalti Nov 6, 2024
c9320c8
feature(4890): ran addLicenseHeaders
kaanyalti Nov 6, 2024
4601ea3
feature(4890): ran mage clean
kaanyalti Nov 6, 2024
d5d84bc
feature(4890): fix typo
kaanyalti Nov 6, 2024
186fcb1
feature(4890): added timeout to connection
kaanyalti Nov 6, 2024
eb73c7f
feature(4890): changed condition check order
kaanyalti Nov 6, 2024
2eb6b0d
feature(4890): fix unit tests
kaanyalti Nov 7, 2024
8ade18e
feature(4890): refactored tests, using mock client
kaanyalti Nov 7, 2024
6d21a40
Update internal/pkg/agent/cmd/upgrade.go
kaanyalti Nov 7, 2024
a4b27f7
feature(4890): use lower case "f" in error messages to be more consis…
kaanyalti Nov 7, 2024
3de964e
feature(4890): remove duplicate line
kaanyalti Nov 7, 2024
52f8884
feature(4890): ran mage controlProto with correct protoc version
kaanyalti Nov 7, 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
feature(4890): ran gofmt
  • Loading branch information
kaanyalti committed Nov 7, 2024
commit 36b3a23a64cbfb007f0fcf522470edbb420556b0
48 changes: 24 additions & 24 deletions internal/pkg/agent/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func newUpgradeCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Comman
cmd.Flags().String(flagPGPBytes, "", "PGP to use for package verification")
cmd.Flags().String(flagPGPBytesURI, "", "Path to a web location containing PGP to use for package verification")
cmd.Flags().String(flagPGPBytesPath, "", "Path to a file containing PGP to use for package verification")
cmd.Flags().BoolP(flagForce, "f", false, "Advanced option to force an upgrade on a fleet managed agent")
cmd.Flags().MarkHidden(flagForce)
cmd.Flags().BoolP(flagForce, "f", false, "Advanced option to force an upgrade on a fleet managed agent")
andrzej-stencel marked this conversation as resolved.
Show resolved Hide resolved
cmd.Flags().MarkHidden(flagForce)

return cmd
}
Expand All @@ -69,39 +69,39 @@ func upgradeCmd(streams *cli.IOStreams, cmd *cobra.Command, args []string) error
func shouldUpgrade(ctx context.Context, cmd *cobra.Command) (bool, error) {
agentInfo, err := info.NewAgentInfoWithLog(ctx, "error", false)
if err != nil {
return false, fmt.Errorf("failed to retrieve agent info while tring to upgrade the agent")
return false, fmt.Errorf("failed to retrieve agent info while tring to upgrade the agent: %w", err)
}

if agentInfo.IsStandalone() {
return true, nil
}
if agentInfo.IsStandalone() {
return true, nil
}

isAdmin, err := utils.HasRoot()
if err != nil {
return false, fmt.Errorf("failed checking root/Administrator rights while trying to upgrade the agent")
return false, fmt.Errorf("failed checking root/Administrator rights while trying to upgrade the agent: %w", err)
}

if !isAdmin {
return false, fmt.Errorf("upgrade command needs to be executed as root for fleet managed agents")
}
if !isAdmin {
return false, fmt.Errorf("upgrade command needs to be executed as root for fleet managed agents")
}

force, err := cmd.Flags().GetBool(flagForce)
if err != nil {
return false, fmt.Errorf("failed to retrieve command flag information while trying to upgrade the agent")
}
force, err := cmd.Flags().GetBool(flagForce)
if err != nil {
return false, fmt.Errorf("failed to retrieve command flag information while trying to upgrade the agent: %w", err)
}

if !force {
return false, fmt.Errorf("upgrading fleet managed agents is not supported")
}
if !force {
return false, fmt.Errorf("upgrading fleet managed agents is not supported")
}

cf, err := cli.Confirm("Upgrading fleet managed agents is not supported. Would you still like to proceed?", false)
if err != nil {
return false, fmt.Errorf("failed while confirming action")
}
cf, err := cli.Confirm("Upgrading fleet managed agents is not supported. Would you still like to proceed?", false)
if err != nil {
return false, fmt.Errorf("failed while confirming action: %w", err)
}

if !cf {
return false, fmt.Errorf("upgrade not confirmed")
}
if !cf {
return false, fmt.Errorf("upgrade not confirmed")
kaanyalti marked this conversation as resolved.
Show resolved Hide resolved
}

return true, nil
}
Expand Down