|
9 | 9 | "context" |
10 | 10 | "fmt" |
11 | 11 | "io" |
| 12 | + "net" |
12 | 13 | "net/http" |
13 | 14 | "net/url" |
14 | 15 | "strings" |
@@ -170,6 +171,28 @@ func EnsureLoadBalancerService( |
170 | 171 | } |
171 | 172 | output := testServiceLoadBalancer(ctx, getClientIPURL, input.ServiceIntervals) |
172 | 173 | Expect(output).ToNot(BeEmpty()) |
| 174 | + |
| 175 | + By("Verifying that the source IP is not part of the Cluster's Service subnet") |
| 176 | + // It is not simple to get the source IP of the runner because its possible connect through a VPN. |
| 177 | + // |
| 178 | + // When source IP preservation is not enabled, |
| 179 | + // the source IP that the LoadBalancer Service responds with would be part of the Cluster's Service subnet. |
| 180 | + // In this case we test the source IP is different from the Service IP. |
| 181 | + // The output will be something like: |
| 182 | + // 192.168.1.141:32768 - when source IP preservation is not enabled. |
| 183 | + // 10.22.24.12:32768 - when source IP preservation is enabled. |
| 184 | + // Get the source IP from the output. |
| 185 | + sourceIPStr := strings.Split(output, ":")[0] |
| 186 | + sourceIP := net.ParseIP(sourceIPStr) |
| 187 | + Expect(sourceIP).ToNot(BeNil()) |
| 188 | + // Get the Cluster's Service subnet. |
| 189 | + serviceCIDRStr := input.WorkloadCluster.Spec.ClusterNetwork.Services.CIDRBlocks[0] |
| 190 | + _, serviceCIDR, err := net.ParseCIDR(serviceCIDRStr) |
| 191 | + Expect(err).ToNot(HaveOccurred()) |
| 192 | + Expect(sourceIP).ToNot(BeNil()) |
| 193 | + // Verify that the source IP is not part of the Cluster's Service subnet, |
| 194 | + // i.e. it will be the external client's IP. |
| 195 | + Expect(serviceCIDR.Contains(sourceIP)).To(BeFalse()) |
173 | 196 | } |
174 | 197 |
|
175 | 198 | func createTestService( |
|
0 commit comments