Skip to content

Commit ab9804d

Browse files
Merge pull request #2873 from openshift-cherrypick-robot/cherry-pick-2871-to-release-4.21
[release-4.21] OCPBUGS-72556: fix(hypershift): use net.JoinHostPort for URL construction
2 parents 8d09651 + 59dff32 commit ab9804d

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

bindata/cloud-network-config-controller/managed/controller.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ spec:
8282
- -c
8383
- |
8484
kc=/var/run/secrets/hosted_cluster/kubeconfig
85-
kubectl --kubeconfig $kc config set clusters.default.server "https://[${KUBERNETES_SERVICE_HOST}]:${KUBERNETES_SERVICE_PORT}"
85+
kubectl --kubeconfig $kc config set clusters.default.server "{{.KubernetesServiceURL}}"
8686
kubectl --kubeconfig $kc config set clusters.default.certificate-authority /hosted-ca/ca.crt
8787
kubectl --kubeconfig $kc config set users.admin.tokenFile /var/run/secrets/hosted_cluster/token
8888
kubectl --kubeconfig $kc config set contexts.default.cluster default
@@ -92,11 +92,6 @@ spec:
9292
volumeMounts:
9393
- mountPath: /var/run/secrets/hosted_cluster
9494
name: hosted-cluster-api-access
95-
env:
96-
- name: KUBERNETES_SERVICE_PORT
97-
value: "{{.KubernetesServicePort}}"
98-
- name: KUBERNETES_SERVICE_HOST
99-
value: "{{.KubernetesServiceHost}}"
10095
terminationMessagePolicy: FallbackToLogsOnError
10196
containers:
10297
# hosted-cluster-token creates a token with a custom path(/var/run/secrets/hosted_cluster/token)

bindata/network/multus-admission-controller/admission-controller.yaml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ spec:
101101
- -c
102102
- |
103103
kc=/var/run/secrets/hosted_cluster/kubeconfig
104-
kubectl --kubeconfig $kc config set clusters.default.server "https://[${KUBERNETES_SERVICE_HOST}]:${KUBERNETES_SERVICE_PORT}"
104+
kubectl --kubeconfig $kc config set clusters.default.server "{{.KubernetesServiceURL}}"
105105
kubectl --kubeconfig $kc config set clusters.default.certificate-authority /hosted-ca/ca.crt
106106
kubectl --kubeconfig $kc config set users.admin.tokenFile /var/run/secrets/hosted_cluster/token
107107
kubectl --kubeconfig $kc config set contexts.default.cluster default
@@ -112,11 +112,6 @@ spec:
112112
volumeMounts:
113113
- mountPath: /var/run/secrets/hosted_cluster
114114
name: hosted-cluster-api-access
115-
env:
116-
- name: KUBERNETES_SERVICE_PORT
117-
value: "{{.KubernetesServicePort}}"
118-
- name: KUBERNETES_SERVICE_HOST
119-
value: "{{.KubernetesServiceHost}}"
120115
automountServiceAccountToken: false
121116
{{- end }}
122117
containers:

pkg/network/cloud_network.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package network
22

33
import (
4+
"net"
45
"os"
56
"path/filepath"
67

@@ -43,8 +44,8 @@ func renderCloudNetworkConfigController(conf *operv1.NetworkSpec, bootstrapResul
4344
data.Data["PlatformTypeAzure"] = v1.AzurePlatformType
4445
data.Data["PlatformTypeGCP"] = v1.GCPPlatformType
4546
data.Data["CloudNetworkConfigControllerImage"] = os.Getenv("CLOUD_NETWORK_CONFIG_CONTROLLER_IMAGE")
46-
data.Data["KubernetesServiceHost"] = cloudBootstrapResult.APIServers[bootstrap.APIServerDefaultLocal].Host
47-
data.Data["KubernetesServicePort"] = cloudBootstrapResult.APIServers[bootstrap.APIServerDefaultLocal].Port
47+
localAPIServer := cloudBootstrapResult.APIServers[bootstrap.APIServerDefaultLocal]
48+
data.Data["KubernetesServiceURL"] = "https://" + net.JoinHostPort(localAPIServer.Host, localAPIServer.Port)
4849
data.Data["ExternalControlPlane"] = cloudBootstrapResult.ControlPlaneTopology == configv1.ExternalTopologyMode
4950
data.Data["PlatformAzureEnvironment"] = ""
5051
data.Data["PlatformAWSCAPath"] = ""

pkg/network/multus_admission_controller.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/base64"
66
"fmt"
7+
"net"
78
"os"
89
"path/filepath"
910
"strings"
@@ -89,8 +90,8 @@ func renderMultusAdmissonControllerConfig(manifestDir string, externalControlPla
8990

9091
if hsc.Enabled {
9192
data.Data["AdmissionControllerNamespace"] = hsc.Namespace
92-
data.Data["KubernetesServiceHost"] = bootstrapResult.Infra.APIServers[bootstrap.APIServerDefaultLocal].Host
93-
data.Data["KubernetesServicePort"] = bootstrapResult.Infra.APIServers[bootstrap.APIServerDefaultLocal].Port
93+
localAPIServer := bootstrapResult.Infra.APIServers[bootstrap.APIServerDefaultLocal]
94+
data.Data["KubernetesServiceURL"] = "https://" + net.JoinHostPort(localAPIServer.Host, localAPIServer.Port)
9495
data.Data["CLIImage"] = os.Getenv("CLI_IMAGE")
9596
if os.Getenv("CLI_CONTROL_PLANE_IMAGE") != "" {
9697
data.Data["CLIImage"] = os.Getenv("CLI_CONTROL_PLANE_IMAGE")

0 commit comments

Comments
 (0)