Skip to content

Commit 52277e5

Browse files
committed
Used MachineNetwork CIDR instead of RendezvousIP
1 parent 3bff072 commit 52277e5

File tree

10 files changed

+67
-23
lines changed

10 files changed

+67
-23
lines changed

cmd/openshift-install/testdata/agent/image/configurations/compact.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,4 @@ rendezvousIP: 192.168.111.20
5454
[Manager]
5555
DefaultEnvironment=HTTP_PROXY="http://192.168.111.1:8215"
5656
DefaultEnvironment=HTTPS_PROXY="http://192.168.111.1:8215"
57-
DefaultEnvironment=NO_PROXY="172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.20"
57+
DefaultEnvironment=NO_PROXY="172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24"

cmd/openshift-install/testdata/agent/image/configurations/control-plane-4-replicas.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ rendezvousIP: 192.168.111.20
5555
[Manager]
5656
DefaultEnvironment=HTTP_PROXY="http://192.168.111.1:8215"
5757
DefaultEnvironment=HTTPS_PROXY="http://192.168.111.1:8215"
58-
DefaultEnvironment=NO_PROXY="172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.20"
58+
DefaultEnvironment=NO_PROXY="172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24"
5959
-- expected/agent-cluster-install.yaml --
6060
apiVersion: extensions.hive.openshift.io/v1beta1
6161
kind: AgentClusterInstall
@@ -90,7 +90,7 @@ spec:
9090
proxy:
9191
httpProxy: http://192.168.111.1:8215
9292
httpsProxy: http://192.168.111.1:8215
93-
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org
93+
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24
9494
sshPublicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDK6UTEydcEKzuNdPaofn8Z2DwgHqdcionLZBiPf/zIRNco++etLsat7Avv7yt04DINQd5zjxIFgG8jblaUB5E5C9ClUcMwb52GO0ay2Y9v1uBv1a4WhI3peKktAzYNk0EBMQlJtXPjRMrC9ylBPh+DsBHMu+KmDnfk7PIwyN4efC8k5kSRuPWoNdme1rz2+umU8FSmaWTHIajrbspf4GQbsntA5kuKEtDbfoNCU97o2KrRnUbeg3a8hwSjfh3u6MhlnGcg5K2Ij+zivEsWGCLKYUtE1ErqwfIzwWmJ6jnV66XCQGHf4Q1iIxqF7s2a1q24cgG2Z/iDXfqXrCIfy4P7b/Ztak3bdT9jfAdVZtdO5/r7I+O5hYhF86ayFlDWzZWP/ByiSb+q4CQbfVgK3BMmiAv2MqLHdhesmD/SmIcoOWUF6rFmRKZVFFpKpt5ATNTgUJ3JRowoXrrDruVXClUGRiCS6Zabd1rZ3VmTchaPJwtzQMdfIWISXj+Ig+C4UK0=
9595
status:
9696
debugInfo:

cmd/openshift-install/testdata/agent/image/configurations/control-plane-5-replicas.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ rendezvousIP: 192.168.111.20
5555
[Manager]
5656
DefaultEnvironment=HTTP_PROXY="http://192.168.111.1:8215"
5757
DefaultEnvironment=HTTPS_PROXY="http://192.168.111.1:8215"
58-
DefaultEnvironment=NO_PROXY="172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.20"
58+
DefaultEnvironment=NO_PROXY="172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24"
5959
-- expected/agent-cluster-install.yaml --
6060
apiVersion: extensions.hive.openshift.io/v1beta1
6161
kind: AgentClusterInstall
@@ -90,7 +90,7 @@ spec:
9090
proxy:
9191
httpProxy: http://192.168.111.1:8215
9292
httpsProxy: http://192.168.111.1:8215
93-
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org
93+
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24
9494
sshPublicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDK6UTEydcEKzuNdPaofn8Z2DwgHqdcionLZBiPf/zIRNco++etLsat7Avv7yt04DINQd5zjxIFgG8jblaUB5E5C9ClUcMwb52GO0ay2Y9v1uBv1a4WhI3peKktAzYNk0EBMQlJtXPjRMrC9ylBPh+DsBHMu+KmDnfk7PIwyN4efC8k5kSRuPWoNdme1rz2+umU8FSmaWTHIajrbspf4GQbsntA5kuKEtDbfoNCU97o2KrRnUbeg3a8hwSjfh3u6MhlnGcg5K2Ij+zivEsWGCLKYUtE1ErqwfIzwWmJ6jnV66XCQGHf4Q1iIxqF7s2a1q24cgG2Z/iDXfqXrCIfy4P7b/Ztak3bdT9jfAdVZtdO5/r7I+O5hYhF86ayFlDWzZWP/ByiSb+q4CQbfVgK3BMmiAv2MqLHdhesmD/SmIcoOWUF6rFmRKZVFFpKpt5ATNTgUJ3JRowoXrrDruVXClUGRiCS6Zabd1rZ3VmTchaPJwtzQMdfIWISXj+Ig+C4UK0=
9595
status:
9696
debugInfo:

cmd/openshift-install/testdata/agent/image/manifests/default_manifests.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ spec:
7676
proxy:
7777
httpProxy: http://192.168.111.1:8215
7878
httpsProxy: http://192.168.111.1:8215
79-
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.20
79+
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24
8080
sshPublicKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDK6UTEydcEKzuNdPaofn8Z2DwgHqdcionLZBiPf/zIRNco++etLsat7Avv7yt04DINQd5zjxIFgG8jblaUB5E5C9ClUcMwb52GO0ay2Y9v1uBv1a4WhI3peKktAzYNk0EBMQlJtXPjRMrC9ylBPh+DsBHMu+KmDnfk7PIwyN4efC8k5kSRuPWoNdme1rz2+umU8FSmaWTHIajrbspf4GQbsntA5kuKEtDbfoNCU97o2KrRnUbeg3a8hwSjfh3u6MhlnGcg5K2Ij+zivEsWGCLKYUtE1ErqwfIzwWmJ6jnV66XCQGHf4Q1iIxqF7s2a1q24cgG2Z/iDXfqXrCIfy4P7b/Ztak3bdT9jfAdVZtdO5/r7I+O5hYhF86ayFlDWzZWP/ByiSb+q4CQbfVgK3BMmiAv2MqLHdhesmD/SmIcoOWUF6rFmRKZVFFpKpt5ATNTgUJ3JRowoXrrDruVXClUGRiCS6Zabd1rZ3VmTchaPJwtzQMdfIWISXj+Ig+C4UK0=
8181
status:
8282
debugInfo:
@@ -135,7 +135,7 @@ spec:
135135
proxy:
136136
httpProxy: http://192.168.111.1:8215
137137
httpsProxy: http://192.168.111.1:8215
138-
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.20
138+
noProxy: 172.22.0.0/24,virthost.ostest.test.metalkube.org,192.168.111.0/24
139139
pullSecretRef:
140140
name: ostest-pull-secret
141141
sshAuthorizedKey: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDK6UTEydcEKzuNdPaofn8Z2DwgHqdcionLZBiPf/zIRNco++etLsat7Avv7yt04DINQd5zjxIFgG8jblaUB5E5C9ClUcMwb52GO0ay2Y9v1uBv1a4WhI3peKktAzYNk0EBMQlJtXPjRMrC9ylBPh+DsBHMu+KmDnfk7PIwyN4efC8k5kSRuPWoNdme1rz2+umU8FSmaWTHIajrbspf4GQbsntA5kuKEtDbfoNCU97o2KrRnUbeg3a8hwSjfh3u6MhlnGcg5K2Ij+zivEsWGCLKYUtE1ErqwfIzwWmJ6jnV66XCQGHf4Q1iIxqF7s2a1q24cgG2Z/iDXfqXrCIfy4P7b/Ztak3bdT9jfAdVZtdO5/r7I+O5hYhF86ayFlDWzZWP/ByiSb+q4CQbfVgK3BMmiAv2MqLHdhesmD/SmIcoOWUF6rFmRKZVFFpKpt5ATNTgUJ3JRowoXrrDruVXClUGRiCS6Zabd1rZ3VmTchaPJwtzQMdfIWISXj+Ig+C4UK0=

pkg/asset/agent/manifests/agentclusterinstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (a *AgentClusterInstall) Generate(_ context.Context, dependencies asset.Par
236236
rendezvousIP = agentConfig.Config.RendezvousIP
237237
}
238238

239-
agentClusterInstall.Spec.Proxy = (*hiveext.Proxy)(getProxy(installConfig.Config.Proxy, rendezvousIP))
239+
agentClusterInstall.Spec.Proxy = (*hiveext.Proxy)(getProxy(installConfig.Config.Proxy, &installConfig.Config.Networking.MachineNetwork, rendezvousIP))
240240
}
241241

242242
if installConfig.Config.Platform.BareMetal != nil {

pkg/asset/agent/manifests/agentclusterinstall_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package manifests
22

33
import (
44
"context"
5+
"net"
56
"os"
67
"testing"
78

@@ -21,6 +22,7 @@ import (
2122
"github.com/openshift/installer/pkg/asset/agent/agentconfig"
2223
"github.com/openshift/installer/pkg/asset/agent/workflow"
2324
"github.com/openshift/installer/pkg/asset/mock"
25+
"github.com/openshift/installer/pkg/ipnet"
2426
"github.com/openshift/installer/pkg/types"
2527
externaltype "github.com/openshift/installer/pkg/types/external"
2628
)
@@ -39,11 +41,18 @@ func TestAgentClusterInstall_Generate(t *testing.T) {
3941
installConfigOverrides: `{"fips":true}`,
4042
})
4143

44+
_, machineNetCidr, _ := net.ParseCIDR("192.168.122.0/16") //nolint:errcheck
45+
machineNetwork := []types.MachineNetworkEntry{
46+
{
47+
CIDR: ipnet.IPNet{IPNet: *machineNetCidr},
48+
},
49+
}
50+
4251
installConfigWithProxy := getValidOptionalInstallConfig()
43-
installConfigWithProxy.Config.Proxy = (*types.Proxy)(getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, ""))
52+
installConfigWithProxy.Config.Proxy = (*types.Proxy)(getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, &machineNetwork, "192.168.122.2"))
4453

4554
goodProxyACI := getGoodACI()
46-
goodProxyACI.Spec.Proxy = (*hiveext.Proxy)(getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, "192.168.122.2"))
55+
goodProxyACI.Spec.Proxy = (*hiveext.Proxy)(getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, &machineNetwork, "192.168.122.2"))
4756

4857
goodACIDualStackVIPs := getGoodACIDualStack()
4958
goodACIDualStackVIPs.Spec.APIVIPs = []string{"192.168.122.10", "2001:db8:1111:2222:ffff:ffff:ffff:cafe"}
@@ -280,6 +289,7 @@ func TestAgentClusterInstall_Generate(t *testing.T) {
280289
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
281290
installConfigWithTrustBundlePolicy,
282291
&agentconfig.AgentHosts{},
292+
&agentconfig.AgentConfig{},
283293
},
284294
expectedConfig: goodTrustBundlePolicyACI,
285295
},

pkg/asset/agent/manifests/common.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package manifests
22

33
import (
44
"fmt"
5+
"net"
56

67
aiv1beta1 "github.com/openshift/assisted-service/api/v1beta1"
78
"github.com/openshift/installer/pkg/asset/agent"
9+
"github.com/openshift/installer/pkg/ipnet"
810
"github.com/openshift/installer/pkg/types"
911
"github.com/openshift/installer/pkg/version"
1012
)
@@ -21,14 +23,31 @@ func getPullSecretName(clusterName string) string {
2123
return clusterName + "-pull-secret"
2224
}
2325

24-
func getProxy(proxy *types.Proxy, rendezvousIP string) *aiv1beta1.Proxy {
25-
// if proxy set add the rendezvousIP to noproxy
26+
func getProxy(proxy *types.Proxy, machineNetwork *[]types.MachineNetworkEntry, rendezvousIP string) *aiv1beta1.Proxy {
2627
noProxy := proxy.NoProxy
2728
if (proxy.HTTPProxy != "" || proxy.HTTPSProxy != "") && rendezvousIP != "" {
28-
if noProxy == "" {
29-
noProxy = rendezvousIP
30-
} else {
31-
noProxy = fmt.Sprintf("%s,%s", noProxy, rendezvousIP)
29+
// if proxy set, add the machineNetwork corresponding to rendezvousIP to noproxy
30+
cidr := ""
31+
if machineNetwork != nil {
32+
for _, mn := range *machineNetwork {
33+
ipNet, err := ipnet.ParseCIDR(mn.CIDR.String())
34+
if err != nil {
35+
continue
36+
}
37+
ip := net.ParseIP(rendezvousIP)
38+
if ipNet.Contains(ip) {
39+
cidr = mn.CIDR.String()
40+
break
41+
}
42+
}
43+
}
44+
45+
if cidr != "" {
46+
if noProxy == "" {
47+
noProxy = cidr
48+
} else {
49+
noProxy = fmt.Sprintf("%s,%s", noProxy, cidr)
50+
}
3251
}
3352
}
3453
return &aiv1beta1.Proxy{

pkg/asset/agent/manifests/infraenv.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (i *InfraEnv) Generate(_ context.Context, dependencies asset.Parents) error
6565
switch agentWorkflow.Workflow {
6666
case workflow.AgentWorkflowTypeInstall:
6767
if installConfig.Config != nil {
68-
err := i.generateManifest(installConfig.ClusterName(), installConfig.ClusterNamespace(), installConfig.Config.SSHKey, installConfig.Config.AdditionalTrustBundle, installConfig.Config.Proxy, string(installConfig.Config.ControlPlane.Architecture), rendezvousIP)
68+
err := i.generateManifest(installConfig.ClusterName(), installConfig.ClusterNamespace(), installConfig.Config.SSHKey, installConfig.Config.AdditionalTrustBundle, installConfig.Config.Proxy, string(installConfig.Config.ControlPlane.Architecture), &installConfig.Config.Networking.MachineNetwork, rendezvousIP)
6969
if err != nil {
7070
return err
7171
}
@@ -77,7 +77,7 @@ func (i *InfraEnv) Generate(_ context.Context, dependencies asset.Parents) error
7777
}
7878

7979
case workflow.AgentWorkflowTypeAddNodes:
80-
err := i.generateManifest(clusterInfo.ClusterName, clusterInfo.Namespace, clusterInfo.SSHKey, clusterInfo.UserCaBundle, clusterInfo.Proxy, clusterInfo.Architecture, rendezvousIP)
80+
err := i.generateManifest(clusterInfo.ClusterName, clusterInfo.Namespace, clusterInfo.SSHKey, clusterInfo.UserCaBundle, clusterInfo.Proxy, clusterInfo.Architecture, nil, rendezvousIP)
8181
if err != nil {
8282
return err
8383
}
@@ -89,7 +89,7 @@ func (i *InfraEnv) Generate(_ context.Context, dependencies asset.Parents) error
8989
return i.finish()
9090
}
9191

92-
func (i *InfraEnv) generateManifest(clusterName, clusterNamespace, sshKey, additionalTrustBundle string, proxy *types.Proxy, architecture, rendezvousIP string) error {
92+
func (i *InfraEnv) generateManifest(clusterName, clusterNamespace, sshKey, additionalTrustBundle string, proxy *types.Proxy, architecture string, machineNetwork *[]types.MachineNetworkEntry, rendezvousIP string) error {
9393
infraEnv := &aiv1beta1.InfraEnv{
9494
TypeMeta: metav1.TypeMeta{
9595
Kind: "InfraEnv",
@@ -122,7 +122,7 @@ func (i *InfraEnv) generateManifest(clusterName, clusterNamespace, sshKey, addit
122122
infraEnv.Spec.AdditionalTrustBundle = additionalTrustBundle
123123
}
124124
if proxy != nil {
125-
infraEnv.Spec.Proxy = getProxy(proxy, rendezvousIP)
125+
infraEnv.Spec.Proxy = getProxy(proxy, machineNetwork, rendezvousIP)
126126
}
127127

128128
i.Config = infraEnv

pkg/asset/agent/manifests/infraenv_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package manifests
33
import (
44
"context"
55
"errors"
6+
"net"
67
"os"
78
"strings"
89
"testing"
@@ -20,11 +21,19 @@ import (
2021
"github.com/openshift/installer/pkg/asset/agent/joiner"
2122
"github.com/openshift/installer/pkg/asset/agent/workflow"
2223
"github.com/openshift/installer/pkg/asset/mock"
24+
"github.com/openshift/installer/pkg/ipnet"
2325
"github.com/openshift/installer/pkg/types"
2426
)
2527

2628
func TestInfraEnv_Generate(t *testing.T) {
2729

30+
_, machineNetCidr, _ := net.ParseCIDR("10.10.11.0/24") //nolint:errcheck
31+
machineNetwork := []types.MachineNetworkEntry{
32+
{
33+
CIDR: ipnet.IPNet{IPNet: *machineNetCidr},
34+
},
35+
}
36+
2837
cases := []struct {
2938
name string
3039
dependencies []asset.Asset
@@ -79,7 +88,7 @@ func TestInfraEnv_Generate(t *testing.T) {
7988
&workflow.AgentWorkflow{Workflow: workflow.AgentWorkflowTypeInstall},
8089
&joiner.ClusterInfo{},
8190
getProxyValidOptionalInstallConfig(),
82-
getValidAgentConfig(),
91+
getValidAgentConfigProxy(),
8392
},
8493
expectedConfig: &aiv1beta1.InfraEnv{
8594
TypeMeta: metav1.TypeMeta{
@@ -91,7 +100,7 @@ func TestInfraEnv_Generate(t *testing.T) {
91100
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
92101
},
93102
Spec: aiv1beta1.InfraEnvSpec{
94-
Proxy: getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, "192.168.122.2"),
103+
Proxy: getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, &machineNetwork, "10.10.11.1"),
95104
SSHAuthorizedKey: strings.Trim(testSSHKey, "|\n\t"),
96105
PullSecretRef: &corev1.LocalObjectReference{
97106
Name: getPullSecretName(getProxyValidOptionalInstallConfig().ClusterName()),
@@ -124,7 +133,7 @@ func TestInfraEnv_Generate(t *testing.T) {
124133
Namespace: getProxyValidOptionalInstallConfig().ClusterNamespace(),
125134
},
126135
Spec: aiv1beta1.InfraEnvSpec{
127-
Proxy: getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, "192.168.122.2"),
136+
Proxy: getProxy(getProxyValidOptionalInstallConfig().Config.Proxy, &machineNetwork, "192.168.122.2"),
128137
SSHAuthorizedKey: strings.Trim(testSSHKey, "|\n\t"),
129138
PullSecretRef: &corev1.LocalObjectReference{
130139
Name: getPullSecretName(getProxyValidOptionalInstallConfig().ClusterName()),

pkg/asset/agent/manifests/util_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ func getValidAgentConfig() *agentconfig.AgentConfig {
243243
}
244244
}
245245

246+
func getValidAgentConfigProxy() *agentconfig.AgentConfig {
247+
agentConfig := getValidAgentConfig()
248+
agentConfig.Config.RendezvousIP = "10.10.11.1"
249+
return agentConfig
250+
}
251+
246252
func getValidAgentHostsConfig() *agentconfig.AgentHosts {
247253
return &agentconfig.AgentHosts{
248254
Hosts: []agenttypes.Host{

0 commit comments

Comments
 (0)