Skip to content

Commit b1ebd47

Browse files
committed
OCPBUGS-61668: Support IPv6 address in rendezvous-host.env template
Previously when agent-tui filled this in as a template, an IPv6 rendezvous IP was not handled correctly. Also, the Rendezvous IP needs to be canonicalized when the installer fills in the template.
1 parent 32fe754 commit b1ebd47

File tree

4 files changed

+30
-50
lines changed

4 files changed

+30
-50
lines changed

cmd/openshift-install/testdata/agent/unconfigured-ignition/configurations/interactive.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ status:
9090
debugInfo:
9191
eventsURL: ""
9292
-- expected/rendezvous-host.env --
93+
#{{ $$isIPv6 := false }}{{ $$host := .RendezvousIP }}{{ range ( len .RendezvousIP ) }}{{if eq ( index ( slice $$host . ) 0 ) ':'}}{{ $$isIPv6 = true }}{{ end }}{{ end }}
9394
NODE_ZERO_IP={{.RendezvousIP}}
94-
SERVICE_BASE_URL=http://{{.RendezvousIP}}:8090/
95-
IMAGE_SERVICE_BASE_URL=http://{{.RendezvousIP}}:8888/
95+
SERVICE_BASE_URL=http://{{ if $$isIPv6 }}{{ printf "[%s]" .RendezvousIP }}{{ else }}{{ .RendezvousIP }}{{ end }}:8090/
96+
IMAGE_SERVICE_BASE_URL=http://{{ if $$isIPv6 }}{{ printf "[%s]" .RendezvousIP }}{{ else }}{{ .RendezvousIP }}{{ end }}:8888/
9697
PULL_SECRET_TOKEN=
9798
USER_AUTH_TOKEN=
9899
WORKFLOW_TYPE=install-interactive-disconnected
99-
AIUI_APP_API_URL=http://{{.RendezvousIP}}:8090/
100-
AIUI_URL=http://{{.RendezvousIP}}:3001/
100+
AIUI_APP_API_URL=http://{{ if $$isIPv6 }}{{ printf "[%s]" .RendezvousIP }}{{ else }}{{ .RendezvousIP }}{{ end }}:8090/
101+
AIUI_URL=http://{{ if $$isIPv6 }}{{ printf "[%s]" .RendezvousIP }}{{ else }}{{ .RendezvousIP }}{{ end }}:3001/

pkg/asset/agent/image/ignition.go

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package image
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/json"
67
"fmt"
78
"html/template"
89
"net"
9-
"net/url"
1010
"path"
1111
"path/filepath"
1212
"strings"
@@ -449,7 +449,7 @@ func getTemplateData(name, pullSecret, releaseImageList, releaseImage, releaseIm
449449
}
450450

451451
func getRendezvousHostEnvTemplate(serviceProtocol, agentAuthtoken, userAuthToken string, workflowType workflow.AgentWorkflowType) string {
452-
host := "{{.RendezvousIP}}"
452+
host := "{{ if $isIPv6 }}{{ printf \"[%s]\" .RendezvousIP }}{{ else }}{{ .RendezvousIP }}{{ end }}"
453453
serviceBaseURL := fmt.Sprintf("%s://%s:8090/", serviceProtocol, host)
454454
imageServiceBaseURL := fmt.Sprintf("%s://%s:8888/", serviceProtocol, host)
455455
uiBaseURL := fmt.Sprintf("%s://%s:3001/", serviceProtocol, host)
@@ -466,7 +466,8 @@ func getRendezvousHostEnvTemplate(serviceProtocol, agentAuthtoken, userAuthToken
466466
// and ensure successful authentication.
467467
// In the absence of PULL_SECRET_TOKEN, the cluster installation will wait forever.
468468

469-
rendezvousHostEnvTemplate := fmt.Sprintf(`NODE_ZERO_IP={{.RendezvousIP}}
469+
rendezvousHostEnvTemplate := fmt.Sprintf(`#{{ $isIPv6 := false }}{{ $host := .RendezvousIP }}{{ range ( len .RendezvousIP ) }}{{if eq ( index ( slice $host . ) 0 ) ':'}}{{ $isIPv6 = true }}{{ end }}{{ end }}
470+
NODE_ZERO_IP={{.RendezvousIP}}
470471
SERVICE_BASE_URL=%s
471472
IMAGE_SERVICE_BASE_URL=%s
472473
PULL_SECRET_TOKEN=%s
@@ -479,45 +480,26 @@ AIUI_URL=%s
479480
return rendezvousHostEnvTemplate
480481
}
481482

482-
func getRendezvousHostEnv(serviceProtocol, nodeZeroIP, agentAuthtoken, userAuthToken string, workflowType workflow.AgentWorkflowType) string {
483-
serviceBaseURL := url.URL{
484-
Scheme: serviceProtocol,
485-
Host: net.JoinHostPort(nodeZeroIP, "8090"),
486-
Path: "/",
487-
}
488-
imageServiceBaseURL := url.URL{
489-
Scheme: serviceProtocol,
490-
Host: net.JoinHostPort(nodeZeroIP, "8888"),
491-
Path: "/",
483+
func getRendezvousHostEnvFromTemplate(hostEnvTemplate, nodeZeroIP string) (string, error) {
484+
tmpl, err := template.New("rendezvous-host.env").Parse(hostEnvTemplate)
485+
if err != nil {
486+
return "", err
492487
}
493-
uiBaseURL := url.URL{
494-
Scheme: serviceProtocol,
495-
Host: net.JoinHostPort(nodeZeroIP, "3001"),
496-
Path: "/",
488+
buf := &bytes.Buffer{}
489+
if err := tmpl.Execute(buf, struct{ RendezvousIP string }{nodeZeroIP}); err != nil {
490+
return "", err
497491
}
498-
// USER_AUTH_TOKEN is required to authenticate API requests against agent-installer-local auth type
499-
// and for the endpoints marked with userAuth security definition in assisted-service swagger.yaml.
500-
// PULL_SECRET_TOKEN contains the AGENT_AUTH_TOKEN and is required for the endpoints marked with agentAuth security definition in assisted-service swagger.yaml.
501-
// The name PULL_SECRET_TOKEN is used in
502-
// assisted-installer-agent, which is responsible for authenticating API requests related to agents.
503-
// Historically, PULL_SECRET_TOKEN was used solely to store the pull secrets.
504-
// However, as the authentication mechanisms have evolved, PULL_SECRET_TOKEN now
505-
// stores a JWT (JSON Web Token) in the context of local authentication.
506-
// Consequently, PULL_SECRET_TOKEN must be set with the value of AGENT_AUTH_TOKEN to maintain compatibility
507-
// and ensure successful authentication.
508-
// In the absence of PULL_SECRET_TOKEN, the cluster installation will wait forever.
509-
510-
rendezvousHostEnv := fmt.Sprintf(`NODE_ZERO_IP=%s
511-
SERVICE_BASE_URL=%s
512-
IMAGE_SERVICE_BASE_URL=%s
513-
PULL_SECRET_TOKEN=%s
514-
USER_AUTH_TOKEN=%s
515-
WORKFLOW_TYPE=%s
516-
AIUI_APP_API_URL=%s
517-
AIUI_URL=%s
518-
`, nodeZeroIP, serviceBaseURL.String(), imageServiceBaseURL.String(), agentAuthtoken, userAuthToken, workflowType, serviceBaseURL.String(), uiBaseURL.String())
492+
return buf.String(), nil
493+
}
519494

520-
return rendezvousHostEnv
495+
func getRendezvousHostEnv(serviceProtocol, nodeZeroIP, agentAuthtoken, userAuthToken string, workflowType workflow.AgentWorkflowType) string {
496+
env, err := getRendezvousHostEnvFromTemplate(
497+
getRendezvousHostEnvTemplate(serviceProtocol, agentAuthtoken, userAuthToken, workflowType),
498+
nodeZeroIP)
499+
if err != nil {
500+
panic(err)
501+
}
502+
return env
521503
}
522504

523505
func getAddNodesEnv(clusterInfo joiner.ClusterInfo, authTokenExpiry string) string {

pkg/asset/agent/image/ignition_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func TestIgnition_getRendezvousHostEnv(t *testing.T) {
126126
userAuthToken := "userAuthToken"
127127
rendezvousHostEnv := getRendezvousHostEnv("http", nodeZeroIP, agentAuthtoken, userAuthToken, workflow.AgentWorkflowTypeInstall)
128128
assert.Equal(t,
129-
"NODE_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",
129+
"#\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",
130130
rendezvousHostEnv)
131131
}
132132

pkg/asset/agent/image/unconfigured_ignition.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,9 @@ func (a *UnconfiguredIgnition) Generate(_ context.Context, dependencies asset.Pa
178178
case workflow.AgentWorkflowTypeInstallInteractiveDisconnected:
179179
// Add the rendezvous host file. Agent TUI will interact with that file in case
180180
// the rendezvous IP wasn't previously configured, by managing it as a template file.
181-
var rendezvousIP, rendezvousHostData string
182-
if agentConfig.Config != nil {
183-
rendezvousIP = agentConfig.Config.RendezvousIP
184-
}
185-
if rendezvousIP != "" {
186-
rendezvousHostData, err := getRendezvousHostEnv("http", rendezvousIP, "", "", agentWorkflow.Workflow)
181+
var rendezvousHostData string
182+
if rendezvousIP, err := RetrieveRendezvousIP(agentConfig.Config, nil, nil); err == nil {
183+
rendezvousHostData, err := getRendezvousHostEnvFromTemplate(rendezvousHostTemplateData, rendezvousIP)
187184
if err != nil {
188185
return err
189186
}

0 commit comments

Comments
 (0)