Skip to content

Commit 0448f7f

Browse files
ronenavopenshift-merge-bot[bot]
authored andcommitted
ECOPROJECT-4097 | feat: warning on new agent VM version released
Signed-off-by: Ronen Avraham <ravraham@redhat.com>
1 parent 6e81b63 commit 0448f7f

File tree

14 files changed

+459
-92
lines changed

14 files changed

+459
-92
lines changed

api/v1alpha1/agent/spec.gen.go

Lines changed: 45 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/openapi.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,14 @@ components:
10351035
$ref: "#/components/schemas/ValidatedSSHPublicKey"
10361036
vmNetwork:
10371037
$ref: "#/components/schemas/VmNetwork"
1038+
agentVersion:
1039+
type: string
1040+
nullable: true
1041+
description: Agent version (version tag) stored when OVA was downloaded
1042+
agentVersionWarning:
1043+
type: string
1044+
nullable: true
1045+
description: Warning message if stored agent version differs from current agent version
10381046
required:
10391047
- id
10401048
- name

api/v1alpha1/spec.gen.go

Lines changed: 44 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/types.gen.go

Lines changed: 10 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/handlers/v1alpha1/image.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"net/http"
99
"strconv"
10+
"time"
1011

1112
"github.com/golang-jwt/jwt/v4"
1213
"github.com/google/uuid"
@@ -17,6 +18,7 @@ import (
1718
"github.com/kubev2v/migration-planner/internal/store"
1819
"github.com/kubev2v/migration-planner/internal/store/model"
1920
"github.com/kubev2v/migration-planner/pkg/metrics"
21+
"github.com/kubev2v/migration-planner/pkg/version"
2022
"go.uber.org/zap"
2123
)
2224

@@ -102,6 +104,22 @@ func (h *ImageHandler) GetImageByToken(ctx context.Context, req imageServer.GetI
102104

103105
metrics.IncreaseOvaDownloadsTotalMetric("successful")
104106

107+
versionInfo := version.Get()
108+
if !version.IsValidAgentVersion(versionInfo.AgentVersionName) {
109+
zap.S().Named("image_service").Warnw("agent version not valid, skipping storage", "source_id", source.ID, "agent_version_name", versionInfo.AgentVersionName, "agent_git_commit", versionInfo.AgentGitCommit)
110+
} else {
111+
// Use detached context to ensure version persists even if client disconnects
112+
persistCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
113+
defer cancel()
114+
115+
// Use atomic update to prevent race conditions during concurrent downloads
116+
if err := h.store.ImageInfra().UpdateAgentVersion(persistCtx, source.ID.String(), versionInfo.AgentVersionName); err != nil {
117+
zap.S().Named("image_service").Warnw("failed to update agent version", "error", err, "source_id", source.ID, "agent_version", versionInfo.AgentVersionName)
118+
} else {
119+
zap.S().Named("image_service").Infow("stored agent version", "source_id", source.ID, "agent_version", versionInfo.AgentVersionName)
120+
}
121+
}
122+
105123
return imageServer.GetImageByToken200ApplicationovfResponse{Body: bytes.NewReader([]byte{})}, nil
106124
}
107125

internal/handlers/v1alpha1/info_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,26 @@ func TestGetInfo(t *testing.T) {
2929
// GitVersion should at least have the default "unknown" value
3030
assert.NotEmpty(t, successResponse.VersionName, "GitVersion should not be empty")
3131
}
32+
33+
func TestGetInfo_AgentFields(t *testing.T) {
34+
handler := &ServiceHandler{}
35+
ctx := context.Background()
36+
request := server.GetInfoRequestObject{}
37+
38+
response, err := handler.GetInfo(ctx, request)
39+
40+
assert.NoError(t, err)
41+
assert.NotNil(t, response)
42+
43+
successResponse, ok := response.(server.GetInfo200JSONResponse)
44+
assert.True(t, ok, "Response should be GetInfo200JSONResponse")
45+
46+
// Agent fields are optional - if set, they should be non-empty
47+
// If not set (nil), that's also valid (may be empty in test builds)
48+
if successResponse.AgentGitCommit != nil {
49+
assert.NotEmpty(t, *successResponse.AgentGitCommit, "AgentGitCommit should not be empty if set")
50+
}
51+
if successResponse.AgentVersionName != nil {
52+
assert.NotEmpty(t, *successResponse.AgentVersionName, "AgentVersionName should not be empty if set")
53+
}
54+
}

internal/handlers/v1alpha1/mappers/outbound.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ func SourceToApi(s model.Source) (api.Source, error) {
155155
}
156156
}
157157

158+
// Map agent version and warning (from ImageInfra, independent of agents)
159+
if s.ImageInfra.AgentVersion != nil {
160+
source.AgentVersion = s.ImageInfra.AgentVersion
161+
}
162+
if warning := service.CheckAgentVersionWarning(&s.ImageInfra); warning != nil {
163+
source.AgentVersionWarning = warning
164+
}
165+
158166
// We are mapping only the first agent based on created_at timestamp and ignore the rest for now.
159167
// TODO:
160168
// Remark: If multiple agents are deployed, we pass only the first one based on created_at timestamp

0 commit comments

Comments
 (0)