Skip to content

Commit f8a55e9

Browse files
committed
Adapt e2e to multi-source model
Signed-off-by: Ondra Machacek <[email protected]>
1 parent 4737751 commit f8a55e9

22 files changed

+539
-526
lines changed

.github/workflows/go.yml

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ jobs:
5555
5656
- name: Prepare
5757
run: |
58+
# FIXME: Move to Makefile!
59+
go install github.com/matryer/moq@latest
60+
export PATH=$PATH:$(go env GOPATH)/bin
5861
make generate
5962
DOWNLOAD_RHCOS=false make build
6063

api/v1alpha1/openapi.yaml

+13-19
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,19 @@ paths:
122122
application/json:
123123
schema:
124124
$ref: '#/components/schemas/Error'
125-
/api/v1/sources/{id}/image:
125+
/api/v1/image:
126126
head:
127127
tags:
128-
- source
129128
- image
130-
description: head the OVA file for the source
131-
operationId: headSourceImage
129+
description: head the OVA image
130+
operationId: headImage
132131
parameters:
133-
- name: id
134-
in: path
135-
description: ID of the source
136-
required: true
132+
- name: sshKey
133+
in: query
134+
description: public SSH key
135+
required: false
137136
schema:
138137
type: string
139-
format: uuid
140138
responses:
141139
"200":
142140
description: An OVA image
@@ -150,18 +148,16 @@ paths:
150148
description: Internal Server Error
151149
get:
152150
tags:
153-
- source
154151
- image
155-
description: get the OVA file for the source
156-
operationId: getSourceImage
152+
description: get the OVA image
153+
operationId: getImage
157154
parameters:
158-
- name: id
159-
in: path
160-
description: ID of the source
161-
required: true
155+
- name: sshKey
156+
in: query
157+
description: public SSH key
158+
required: false
162159
schema:
163160
type: string
164-
format: uuid
165161
responses:
166162
"200":
167163
description: An OVA image
@@ -317,8 +313,6 @@ components:
317313
properties:
318314
name:
319315
type: string
320-
sshKey:
321-
type: string
322316
required:
323317
- name
324318

api/v1alpha1/spec.gen.go

+31-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/types.gen.go

+13-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/planner-agent/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ func NewAgentCommand() *agentCmd {
5858
}
5959

6060
func (a *agentCmd) Execute() error {
61+
// FIXME: !!!
62+
if agentID == "" {
63+
agentID = uuid.New().String()
64+
}
6165
agentInstance := agent.New(uuid.MustParse(agentID), a.log, a.config)
6266
if err := agentInstance.Run(context.Background()); err != nil {
6367
a.log.Fatalf("running device agent: %v", err)

data/ignition.template

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ storage:
6868
data-dir: /agent/data
6969
www-dir: /app/www
7070
log-level: debug
71-
source-id: {{.SourceId}}
7271
update-interval: 5s
7372
planner-service:
7473
service:

internal/agent/agent.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func (a *Agent) start(ctx context.Context, plannerClient client.Planner) {
107107
go a.server.Start(a.log, statusUpdater)
108108

109109
// get the credentials url
110-
a.initializeCredentialUrl()
110+
credUrl := a.initializeCredentialUrl()
111111

112112
// start the health check
113113
healthChecker, err := NewHealthChecker(
@@ -151,7 +151,7 @@ func (a *Agent) start(ctx context.Context, plannerClient client.Planner) {
151151
continue
152152
}
153153

154-
if err := statusUpdater.UpdateStatus(ctx, status, statusInfo); err != nil {
154+
if err := statusUpdater.UpdateStatus(ctx, status, statusInfo, credUrl); err != nil {
155155
if errors.Is(err, client.ErrSourceGone) {
156156
a.log.Info("Source is gone..Stop sending requests")
157157
// stop the server and the healthchecker
@@ -169,13 +169,12 @@ func (a *Agent) start(ctx context.Context, plannerClient client.Planner) {
169169
}()
170170
}
171171

172-
func (a *Agent) initializeCredentialUrl() {
172+
func (a *Agent) initializeCredentialUrl() string {
173173
// Parse the service URL
174174
parsedURL, err := url.Parse(a.config.PlannerService.Service.Server)
175175
if err != nil {
176176
a.log.Errorf("error parsing service URL: %v", err)
177-
a.credUrl = "N/A"
178-
return
177+
return "N/A"
179178
}
180179

181180
// Use either port if specified, or scheme
@@ -188,14 +187,14 @@ func (a *Agent) initializeCredentialUrl() {
188187
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%s", parsedURL.Hostname(), port))
189188
if err != nil {
190189
a.log.Errorf("failed connecting to migration planner: %v", err)
191-
a.credUrl = "N/A"
192-
return
190+
return "N/A"
193191
}
194192
defer conn.Close()
195193

196194
localAddr := conn.LocalAddr().(*net.TCPAddr)
197-
a.credUrl = fmt.Sprintf("http://%s:%d", localAddr.IP.String(), defaultAgentPort)
198-
a.log.Infof("Discovered Agent IP address: %s", a.credUrl)
195+
credUrl := fmt.Sprintf("http://%s:%d", localAddr.IP.String(), defaultAgentPort)
196+
a.log.Infof("Discovered Agent IP address: %s", credUrl)
197+
return credUrl
199198
}
200199

201200
func newPlannerClient(cfg *Config) (client.Planner, error) {

internal/agent/inventory.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
type InventoryUpdater struct {
1616
log *log.PrefixLogger
17-
sourceID uuid.UUID
1817
client client.Planner
1918
agentID uuid.UUID
2019
prevStatus []byte
@@ -37,10 +36,8 @@ func NewInventoryUpdater(log *log.PrefixLogger, agentID uuid.UUID, client client
3736

3837
func (u *InventoryUpdater) UpdateServiceWithInventory(ctx context.Context, status api.SourceStatus, statusInfo string, inventory *api.Inventory) {
3938
update := agentapi.SourceStatusUpdate{
40-
Status: string(status),
41-
StatusInfo: statusInfo,
42-
Inventory: *inventory,
43-
AgentId: u.agentID,
39+
Inventory: *inventory,
40+
AgentId: u.agentID,
4441
}
4542

4643
newContents, err := json.Marshal(update)

internal/agent/inventory_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@ var _ = Describe("Inventory", func() {
2929
UpdateSourceStatusFunc: func(ctx context.Context, id uuid.UUID, params v1alpha1.SourceStatusUpdate) error {
3030
Expect(id).To(Equal(sourceID))
3131
Expect(params.AgentId).To(Equal(agentID))
32-
Expect(params.Status).To(Equal("up-to-date"))
33-
Expect(params.StatusInfo).To(Equal("status_info"))
3432
Expect(params.Inventory).ToNot(BeNil())
3533
return nil
3634

3735
},
3836
}
3937

4038
inventory := &api.Inventory{
41-
Vms: api.VMs{Total: 2},
39+
Vms: api.VMs{Total: 2},
40+
Vcenter: api.VCenter{Id: sourceID.String()},
4241
}
4342
inventoryUpdater := agent.NewInventoryUpdater(log.NewPrefixLogger(""), agentID, &client)
4443
inventoryUpdater.UpdateServiceWithInventory(context.TODO(), api.SourceStatusUpToDate, "status_info", inventory)

internal/agent/status.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ func NewStatusUpdater(log *log.PrefixLogger, agentID uuid.UUID, version, credUrl
3939
}
4040
}
4141

42-
func (s *StatusUpdater) UpdateStatus(ctx context.Context, status api.AgentStatus, statusInfo string) error {
42+
func (s *StatusUpdater) UpdateStatus(ctx context.Context, status api.AgentStatus, statusInfo string, credUrl string) error {
4343
ctx, cancel := context.WithTimeout(ctx, defaultUpdateStatusTimeout*time.Second)
4444
defer cancel()
4545

4646
bodyParameters := agentapi.AgentStatusUpdate{
4747
Id: s.agentID.String(),
4848
Status: string(status),
4949
StatusInfo: statusInfo,
50-
CredentialUrl: s.credUrl,
50+
CredentialUrl: credUrl,
5151
Version: s.version,
5252
}
5353

internal/agent/status_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ var _ = Describe("Status", func() {
4141
}
4242

4343
statusUpdater := agent.NewStatusUpdater(log.NewPrefixLogger(""), agentID, "best_version", "www-cred-url", &agent.Config{}, &client)
44-
Expect(statusUpdater.UpdateStatus(context.TODO(), api.AgentStatusUpToDate, "status_info"))
44+
Expect(statusUpdater.UpdateStatus(context.TODO(), api.AgentStatusUpToDate, "status_info", "www-cred-url"))
4545
})
4646
})
4747

0 commit comments

Comments
 (0)