From 19afc7bb60fc4cf8a10016bc2a29ef04aab87196 Mon Sep 17 00:00:00 2001 From: Vitaliy Emporopulo Date: Wed, 29 Jul 2020 13:33:24 +0300 Subject: [PATCH] MGMT-882 Use URL instead of host and port --- deploy/bm-inventory-configmap.yaml | 3 +-- internal/bminventory/inventory.go | 22 ++++++++---------- internal/bminventory/inventory_test.go | 12 ++++++++++ internal/host/installcmd.go | 9 ++++---- internal/host/installcmd_test.go | 24 ++++++++++---------- internal/host/instructionmanager.go | 3 +-- tools/deploy_assisted_installer_configmap.py | 3 +-- 7 files changed, 41 insertions(+), 35 deletions(-) diff --git a/deploy/bm-inventory-configmap.yaml b/deploy/bm-inventory-configmap.yaml index eb05f5ec5..3e2ab2fe5 100644 --- a/deploy/bm-inventory-configmap.yaml +++ b/deploy/bm-inventory-configmap.yaml @@ -6,8 +6,7 @@ metadata: labels: app: bm-inventory data: - INVENTORY_URL: REPLACE_URL - INVENTORY_PORT: REPLACE_PORT + INVENTORY_BASE_URL: REPLACE_BASE_URL NAMESPACE: REPLACE_NAMESPACE BASE_DNS_DOMAINS: REPLACE_DOMAINS # example: name1:id1/provider1,name2:id2/provider2 OPENSHIFT_INSTALL_RELEASE_IMAGE: "quay.io/openshift-release-dev/ocp-release@sha256:eab93b4591699a5a4ff50ad3517892653f04fb840127895bb3609b3cc68f98f3" diff --git a/internal/bminventory/inventory.go b/internal/bminventory/inventory.go index 0dc7f7d66..1c9c40456 100644 --- a/internal/bminventory/inventory.go +++ b/internal/bminventory/inventory.go @@ -79,8 +79,7 @@ type Config struct { KubeconfigGenerator string `envconfig:"KUBECONFIG_GENERATE_IMAGE" default:"quay.io/ocpmetal/ignition-manifests-and-kubeconfig-generate:latest"` // TODO: update the latest once the repository has git workflow //[TODO] - change the default of Releae image to "", once everyine wll update their environment ReleaseImage string `envconfig:"OPENSHIFT_INSTALL_RELEASE_IMAGE" default:"quay.io/openshift-release-dev/ocp-release@sha256:eab93b4591699a5a4ff50ad3517892653f04fb840127895bb3609b3cc68f98f3"` - InventoryURL string `envconfig:"INVENTORY_URL" default:"10.35.59.36"` - InventoryPort string `envconfig:"INVENTORY_PORT" default:"30485"` + InventoryBaseURL string `envconfig:"INVENTORY_BASE_URL" default:"http://10.35.59.36:30485"` S3EndpointURL string `envconfig:"S3_ENDPOINT_URL" default:"http://10.35.59.36:30925"` S3Bucket string `envconfig:"S3_BUCKET" default:"test"` AwsAccessKeyID string `envconfig:"AWS_ACCESS_KEY_ID" default:"accessKey1"` @@ -114,7 +113,7 @@ const ignitionConfigFormat = `{ "units": [{ "name": "agent.service", "enabled": true, -"contents": "[Service]\nType=simple\nRestart=always\nRestartSec=3\nStartLimitIntervalSec=0\nEnvironment=HTTPS_PROXY={{.ProxyURL}}\nEnvironment=HTTP_PROXY={{.ProxyURL}}\nEnvironment=http_proxy={{.ProxyURL}}\nEnvironment=https_proxy={{.ProxyURL}}\nExecStartPre=podman run --privileged --rm -v /usr/local/bin:/hostbin {{.AgentDockerImg}} cp /usr/bin/agent /hostbin\nExecStart=/usr/local/bin/agent --host {{.InventoryURL}} --port {{.InventoryPort}} --cluster-id {{.clusterId}} --agent-version {{.AgentDockerImg}}\n\n[Install]\nWantedBy=multi-user.target" +"contents": "[Service]\nType=simple\nRestart=always\nRestartSec=3\nStartLimitIntervalSec=0\nEnvironment=HTTPS_PROXY={{.ProxyURL}}\nEnvironment=HTTP_PROXY={{.ProxyURL}}\nEnvironment=http_proxy={{.ProxyURL}}\nEnvironment=https_proxy={{.ProxyURL}}\nExecStartPre=podman run --privileged --rm -v /usr/local/bin:/hostbin {{.AgentDockerImg}} cp /usr/bin/agent /hostbin\nExecStart=/usr/local/bin/agent --url {{.InventoryBaseURL}} --cluster-id {{.clusterId}} --agent-version {{.AgentDockerImg}}\n\n[Install]\nWantedBy=multi-user.target" }] }, "storage": { @@ -293,14 +292,13 @@ func (b *bareMetalInventory) createImageJob(jobName, imgName, ignitionConfig str func (b *bareMetalInventory) formatIgnitionFile(cluster *common.Cluster, params installer.GenerateClusterISOParams) (string, error) { var ignitionParams = map[string]string{ - "userSshKey": b.getUserSshKey(params), - "AgentDockerImg": b.AgentDockerImg, - "InventoryURL": strings.TrimSpace(b.InventoryURL), - "InventoryPort": strings.TrimSpace(b.InventoryPort), - "clusterId": cluster.ID.String(), - "ProxyURL": params.ImageCreateParams.ProxyURL, - "PULL_SECRET": dataurl.EncodeBytes([]byte(cluster.PullSecret)), - "AGENT_MOTD": url.PathEscape(agentMessageOfTheDay), + "userSshKey": b.getUserSshKey(params), + "AgentDockerImg": b.AgentDockerImg, + "InventoryBaseURL": strings.TrimSpace(b.InventoryBaseURL), + "clusterId": cluster.ID.String(), + "ProxyURL": params.ImageCreateParams.ProxyURL, + "PULL_SECRET": dataurl.EncodeBytes([]byte(cluster.PullSecret)), + "AGENT_MOTD": url.PathEscape(agentMessageOfTheDay), } tmpl, err := template.New("ignitionConfig").Parse(ignitionConfigFormat) if err != nil { @@ -1598,7 +1596,7 @@ func (b *bareMetalInventory) createKubeconfigJob(cluster *common.Cluster, jobNam }, { Name: "INVENTORY_ENDPOINT", - Value: "http://" + strings.TrimSpace(b.InventoryURL) + ":" + strings.TrimSpace(b.InventoryPort) + "/api/assisted-install/v1", + Value: strings.TrimSpace(b.InventoryBaseURL) + "/api/assisted-install/v1", }, { Name: "IMAGE_NAME", diff --git a/internal/bminventory/inventory_test.go b/internal/bminventory/inventory_test.go index 8372dd276..f7188f33e 100644 --- a/internal/bminventory/inventory_test.go +++ b/internal/bminventory/inventory_test.go @@ -167,6 +167,18 @@ var _ = Describe("GenerateClusterISO", func() { }) Expect(generateReply).Should(BeAssignableToTypeOf(installer.NewGenerateClusterISOBadRequest())) }) + + It("ignition_file_contains_url", func() { + cluster := registerCluster(false) + + bm.InventoryBaseURL = "file://10.56.20.70:7878" + text, err := bm.formatIgnitionFile(cluster, installer.GenerateClusterISOParams{ + ImageCreateParams: &models.ImageCreateParams{}, + }) + + Expect(err).Should(BeNil()) + Expect(text).Should(ContainSubstring(fmt.Sprintf("--url %s", bm.InventoryBaseURL))) + }) }) var _ = Describe("RegisterHost", func() { diff --git a/internal/host/installcmd.go b/internal/host/installcmd.go index 27251171c..ef0bea0ef 100644 --- a/internal/host/installcmd.go +++ b/internal/host/installcmd.go @@ -50,13 +50,12 @@ func (i *installCmd) GetStep(ctx context.Context, host *models.Host) (*models.St } cmdArgsTmpl := "sudo podman run -v /dev:/dev:rw -v /opt:/opt:rw --privileged --pid=host --net=host " + - "-v /var/log:/var/log:rw --name assisted-installer {{.INSTALLER}} --role {{.ROLE}} --cluster-id {{.CLUSTER_ID}} --host {{.HOST}} " + - "--port {{.PORT}} --boot-device {{.BOOT_DEVICE}} --host-id {{.HOST_ID}} --openshift-version {{.OPENSHIFT_VERSION}} " + - "--controller-image {{.CONTROLLER_IMAGE}}" + "-v /var/log:/var/log:rw --name assisted-installer {{.INSTALLER}} --role {{.ROLE}} --cluster-id {{.CLUSTER_ID}} " + + "--boot-device {{.BOOT_DEVICE}} --host-id {{.HOST_ID}} --openshift-version {{.OPENSHIFT_VERSION}} " + + "--controller-image {{.CONTROLLER_IMAGE}} --url {{.BASE_URL}}" data := map[string]string{ - "HOST": strings.TrimSpace(i.instructionConfig.InventoryURL), - "PORT": strings.TrimSpace(i.instructionConfig.InventoryPort), + "BASE_URL": strings.TrimSpace(i.instructionConfig.InventoryBaseUrl), "CLUSTER_ID": string(host.ClusterID), "HOST_ID": string(*host.ID), "ROLE": string(role), diff --git a/internal/host/installcmd_test.go b/internal/host/installcmd_test.go index 20650236a..205436477 100644 --- a/internal/host/installcmd_test.go +++ b/internal/host/installcmd_test.go @@ -18,11 +18,13 @@ import ( "github.com/pkg/errors" ) +const inventoryURL = "10.35.59.36" +const inventoryPort = "30485" + var defaultInstructionConfig = InstructionConfig{ - InventoryURL: "10.35.59.36", - InventoryPort: "30485", - InstallerImage: "quay.io/ocpmetal/assisted-installer:latest", - ControllerImage: "quay.io/ocpmetal/assisted-installer-controller:latest", + InventoryBaseUrl: fmt.Sprintf("http://%s:%s", inventoryURL, inventoryPort), + InstallerImage: "quay.io/ocpmetal/assisted-installer:latest", + ControllerImage: "quay.io/ocpmetal/assisted-installer-controller:latest", } var _ = Describe("installcmd", func() { @@ -151,22 +153,20 @@ func validateInstallCommand(reply *models.Step, role models.HostRole, clusterId installCommand := "sudo podman run -v /dev:/dev:rw -v /opt:/opt:rw --privileged --pid=host " + "--net=host -v /var/log:/var/log:rw " + "--name assisted-installer quay.io/ocpmetal/assisted-installer:latest --role %s " + - "--cluster-id %s --host %s --port %s " + + "--cluster-id %s " + "--boot-device /dev/sdb --host-id %s --openshift-version 4.5 " + - "--controller-image %s --host-name %s" + "--controller-image %s --url %s --host-name %s" ExpectWithOffset(1, reply.Args[1]).Should(Equal(fmt.Sprintf(installCommand, role, clusterId, - defaultInstructionConfig.InventoryURL, defaultInstructionConfig.InventoryPort, hostId, - defaultInstructionConfig.ControllerImage, hostname))) + hostId, defaultInstructionConfig.ControllerImage, defaultInstructionConfig.InventoryBaseUrl, hostname))) } else { installCommand := "sudo podman run -v /dev:/dev:rw -v /opt:/opt:rw --privileged --pid=host " + "--net=host -v /var/log:/var/log:rw " + "--name assisted-installer quay.io/ocpmetal/assisted-installer:latest --role %s " + - "--cluster-id %s --host %s --port %s " + + "--cluster-id %s " + "--boot-device /dev/sdb --host-id %s --openshift-version 4.5 " + - "--controller-image %s" + "--controller-image %s --url %s" ExpectWithOffset(1, reply.Args[1]).Should(Equal(fmt.Sprintf(installCommand, role, clusterId, - defaultInstructionConfig.InventoryURL, defaultInstructionConfig.InventoryPort, hostId, - defaultInstructionConfig.ControllerImage))) + hostId, defaultInstructionConfig.ControllerImage, defaultInstructionConfig.InventoryBaseUrl))) } ExpectWithOffset(1, reply.StepType).To(Equal(models.StepTypeInstall)) } diff --git a/internal/host/instructionmanager.go b/internal/host/instructionmanager.go index a3b9c6cb1..ae4dd7c16 100644 --- a/internal/host/instructionmanager.go +++ b/internal/host/instructionmanager.go @@ -40,8 +40,7 @@ type InstructionManager struct { stateToSteps stateToStepsMap } type InstructionConfig struct { - InventoryURL string `envconfig:"INVENTORY_URL" default:"10.35.59.36"` - InventoryPort string `envconfig:"INVENTORY_PORT" default:"30485"` + InventoryBaseUrl string `envconfig:"INVENTORY_BASE_URL" default:"http://10.35.59.36:30485"` InstallerImage string `envconfig:"INSTALLER_IMAGE" default:"quay.io/ocpmetal/assisted-installer:latest"` ControllerImage string `envconfig:"CONTROLLER_IMAGE" default:"quay.io/ocpmetal/assisted-installer-controller:latest"` ConnectivityCheckImage string `envconfig:"CONNECTIVITY_CHECK_IMAGE" default:"quay.io/ocpmetal/connectivity_check:latest"` diff --git a/tools/deploy_assisted_installer_configmap.py b/tools/deploy_assisted_installer_configmap.py index 5be5bb9d5..1c9e7b584 100644 --- a/tools/deploy_assisted_installer_configmap.py +++ b/tools/deploy_assisted_installer_configmap.py @@ -39,9 +39,8 @@ def main(): with open(SRC_FILE, "r") as src: with open(DST_FILE, "w+") as dst: data = src.read() - data = data.replace("REPLACE_URL", '"{}"'.format(service_host)) - data = data.replace("REPLACE_PORT", '"{}"'.format(service_port)) data = data.replace("REPLACE_DOMAINS", '"{}"'.format(deploy_options.base_dns_domains)) + data = data.replace("REPLACE_BASE_URL", f'http://{service_host}:{service_port}') data = data.replace('REPLACE_NAMESPACE', deploy_options.namespace) print("Deploying {}".format(DST_FILE))