Skip to content

Commit 175c6f9

Browse files
mergify[bot]Kaan Yaltiebeahan
authored
enhancement(4811): updated the errors returned from check upgrade and… (#7453) (#8563)
* enhancement(4811): updated the errors returned from check upgrade and updated the test function name * enhancement(4811): added changelog * remove issue reference --------- (cherry picked from commit 0a63787) Co-authored-by: Kaan Yalti <[email protected]> Co-authored-by: Eric Beahan <[email protected]>
1 parent 2f6566a commit 175c6f9

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: enhancement
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Updated the error messages returned for fips upgrades
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: "elastic-agent"
23+
# PR URL; optional; the PR number that added the changeset.
24+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
25+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
26+
# Please provide it if you are adding a fragment for a different PR.
27+
pr: https://github.com/elastic/elastic-agent/pull/7453
28+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
29+
# If not present is automatically filled by the tooling with the issue linked to the PR number.

internal/pkg/agent/application/upgrade/upgrade.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ var agentArtifact = artifact.Artifact{
5555
}
5656

5757
var (
58-
ErrWatcherNotStarted = errors.New("watcher did not start in time")
59-
ErrUpgradeSameVersion = errors.New("upgrade did not occur because it is the same version")
60-
ErrFipsNotUpgradedToFips = errors.New("cannot upgrade from a fips compliant agent to a non-compliant one")
58+
ErrWatcherNotStarted = errors.New("watcher did not start in time")
59+
ErrUpgradeSameVersion = errors.New("upgrade did not occur because it is the same version")
60+
ErrNonFipsToFips = errors.New("cannot switch to fips mode when upgrading")
61+
ErrFipsToNonFips = errors.New("cannot switch to non-fips mode when upgrading")
6162
)
6263

6364
// Upgrader performs an upgrade
@@ -172,15 +173,15 @@ func checkUpgrade(log *logger.Logger, currentVersion, newVersion agentVersion, m
172173
return ErrUpgradeSameVersion
173174
}
174175

175-
if currentVersion.fips && metadata.manifest.Package.Fips {
176-
return nil
176+
if currentVersion.fips && !metadata.manifest.Package.Fips {
177+
return ErrFipsToNonFips
177178
}
178179

179-
if !currentVersion.fips && !metadata.manifest.Package.Fips {
180-
return nil
180+
if !currentVersion.fips && metadata.manifest.Package.Fips {
181+
return ErrNonFipsToFips
181182
}
182183

183-
return ErrFipsNotUpgradedToFips
184+
return nil
184185
}
185186

186187
// Upgrade upgrades running agent, function returns shutdown callback that must be called by reexec.

internal/pkg/agent/application/upgrade/upgrade_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ func TestExtractVersion(t *testing.T) {
804804
}
805805
}
806806

807-
func TestIsSameVersion(t *testing.T) {
807+
func TestCheckUpgrade(t *testing.T) {
808808
type args struct {
809809
current agentVersion
810810
newVersion agentVersion
@@ -850,7 +850,7 @@ func TestIsSameVersion(t *testing.T) {
850850
},
851851
},
852852
want: want{
853-
err: ErrFipsNotUpgradedToFips,
853+
err: ErrFipsToNonFips,
854854
},
855855
},
856856
{
@@ -867,7 +867,7 @@ func TestIsSameVersion(t *testing.T) {
867867
},
868868
},
869869
want: want{
870-
err: ErrFipsNotUpgradedToFips,
870+
err: ErrNonFipsToFips,
871871
},
872872
},
873873
{

0 commit comments

Comments
 (0)