Skip to content

Commit 5c8393c

Browse files
committed
Pass all template data to getRendezvousHostEnv()
This way arguments can't get mixed up.
1 parent b1ebd47 commit 5c8393c

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

pkg/asset/agent/image/ignition.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ func (a *Ignition) Generate(ctx context.Context, dependencies asset.Parents) err
306306

307307
rendezvousHostFile := ignition.FileFromString(rendezvousHostEnvPath,
308308
"root", 0644,
309-
getRendezvousHostEnv(agentTemplateData.ServiceProtocol, a.RendezvousIP, authConfig.AgentAuthToken, authConfig.UserAuthToken, agentWorkflow.Workflow))
309+
getRendezvousHostEnv(agentTemplateData, a.RendezvousIP, agentWorkflow.Workflow))
310310
config.Storage.Files = append(config.Storage.Files, rendezvousHostFile)
311311

312312
err = addBootstrapScripts(&config, agentManifests.ClusterImageSet.Spec.ReleaseImage)
@@ -448,11 +448,11 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage, releaseIm
448448
}
449449
}
450450

451-
func getRendezvousHostEnvTemplate(serviceProtocol, agentAuthtoken, userAuthToken string, workflowType workflow.AgentWorkflowType) string {
451+
func getRendezvousHostEnvTemplate(data *agentTemplateData, workflowType workflow.AgentWorkflowType) string {
452452
host := "{{ if $isIPv6 }}{{ printf \"[%s]\" .RendezvousIP }}{{ else }}{{ .RendezvousIP }}{{ end }}"
453-
serviceBaseURL := fmt.Sprintf("%s://%s:8090/", serviceProtocol, host)
454-
imageServiceBaseURL := fmt.Sprintf("%s://%s:8888/", serviceProtocol, host)
455-
uiBaseURL := fmt.Sprintf("%s://%s:3001/", serviceProtocol, host)
453+
serviceBaseURL := fmt.Sprintf("%s://%s:8090/", data.ServiceProtocol, host)
454+
imageServiceBaseURL := fmt.Sprintf("%s://%s:8888/", data.ServiceProtocol, host)
455+
uiBaseURL := fmt.Sprintf("%s://%s:3001/", data.ServiceProtocol, host)
456456

457457
// USER_AUTH_TOKEN is required to authenticate API requests against agent-installer-local auth type
458458
// and for the endpoints marked with userAuth security definition in assisted-service swagger.yaml.
@@ -475,7 +475,7 @@ USER_AUTH_TOKEN=%s
475475
WORKFLOW_TYPE=%s
476476
AIUI_APP_API_URL=%s
477477
AIUI_URL=%s
478-
`, serviceBaseURL, imageServiceBaseURL, agentAuthtoken, userAuthToken, workflowType, serviceBaseURL, uiBaseURL)
478+
`, serviceBaseURL, imageServiceBaseURL, data.AgentAuthToken, data.UserAuthToken, workflowType, serviceBaseURL, uiBaseURL)
479479

480480
return rendezvousHostEnvTemplate
481481
}
@@ -492,9 +492,9 @@ func getRendezvousHostEnvFromTemplate(hostEnvTemplate, nodeZeroIP string) (strin
492492
return buf.String(), nil
493493
}
494494

495-
func getRendezvousHostEnv(serviceProtocol, nodeZeroIP, agentAuthtoken, userAuthToken string, workflowType workflow.AgentWorkflowType) string {
495+
func getRendezvousHostEnv(data *agentTemplateData, nodeZeroIP string, workflowType workflow.AgentWorkflowType) string {
496496
env, err := getRendezvousHostEnvFromTemplate(
497-
getRendezvousHostEnvTemplate(serviceProtocol, agentAuthtoken, userAuthToken, workflowType),
497+
getRendezvousHostEnvTemplate(data, workflowType),
498498
nodeZeroIP)
499499
if err != nil {
500500
panic(err)

pkg/asset/agent/image/ignition_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ func TestIgnition_getRendezvousHostEnv(t *testing.T) {
124124
nodeZeroIP := "2001:db8::dead:beef"
125125
agentAuthtoken := "agentAuthtoken"
126126
userAuthToken := "userAuthToken"
127-
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, agentAuthtoken, userAuthToken, workflow.AgentWorkflowTypeInstall)
127+
rendezvousHostEnv := getRendezvousHostEnv(&agentTemplateData{
128+
ServiceProtocol: "http",
129+
AgentAuthToken: agentAuthtoken,
130+
UserAuthToken: userAuthToken,
131+
}, nodeZeroIP, workflow.AgentWorkflowTypeInstall)
128132
assert.Equal(t,
129133
"#\nNODE_ZERO_IP="+nodeZeroIP+"\nSERVICE_BASE_URL=http://["+nodeZeroIP+"]:8090/\nIMAGE_SERVICE_BASE_URL=http://["+nodeZeroIP+"]:8888/\nPULL_SECRET_TOKEN="+agentAuthtoken+"\nUSER_AUTH_TOKEN="+userAuthToken+"\nWORKFLOW_TYPE=install\nAIUI_APP_API_URL=http://["+nodeZeroIP+"]:8090/\nAIUI_URL=http://["+nodeZeroIP+"]:3001/\n",
130134
rendezvousHostEnv)

pkg/asset/agent/image/unconfigured_ignition.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (a *UnconfiguredIgnition) Generate(_ context.Context, dependencies asset.Pa
151151
a.CPUArch = *osImage.CPUArchitecture
152152

153153
agentTemplateData := &agentTemplateData{
154+
ServiceProtocol: "http",
154155
PullSecret: pullSecretAsset.GetPullSecretData(),
155156
ReleaseImages: releaseImageList,
156157
ReleaseImage: clusterImageSet.Spec.ReleaseImage,
@@ -164,7 +165,7 @@ func (a *UnconfiguredIgnition) Generate(_ context.Context, dependencies asset.Pa
164165

165166
enabledServices := getDefaultEnabledServices()
166167

167-
rendezvousHostTemplateData := getRendezvousHostEnvTemplate("http", "", "", agentWorkflow.Workflow)
168+
rendezvousHostTemplateData := getRendezvousHostEnvTemplate(agentTemplateData, agentWorkflow.Workflow)
168169
rendezvousHostTemplateFile := ignition.FileFromString(fmt.Sprintf("%s.template", rendezvousHostEnvPath), "root", 0644, rendezvousHostTemplateData)
169170
config.Storage.Files = append(config.Storage.Files, rendezvousHostTemplateFile)
170171

0 commit comments

Comments
 (0)