From bce27cc91134fefea299a4e9e26b5430644f3553 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Thu, 16 Jan 2025 16:44:47 +0100 Subject: [PATCH 1/5] Configure dependabot on the release-0.19 branch Signed-off-by: Stephen Kitt --- .github/dependabot.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a6c904821..3278d869a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -45,6 +45,15 @@ updates: github-actions: patterns: - "*" + - package-ecosystem: github-actions + directory: / + target-branch: release-0.19 + schedule: + interval: monthly + groups: + github-actions: + patterns: + - "*" - package-ecosystem: gomod directory: / schedule: From 7fc648cab01b2eefe50a0a5c046ea7579e8d051e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:19:12 +0000 Subject: [PATCH 2/5] Bump k8s.io/component-helpers from 0.31.4 to 0.31.5 in the gomod group Bumps the gomod group with 1 update: [k8s.io/component-helpers](https://github.com/kubernetes/component-helpers). Updates `k8s.io/component-helpers` from 0.31.4 to 0.31.5 - [Commits](https://github.com/kubernetes/component-helpers/compare/v0.31.4...v0.31.5) --- updated-dependencies: - dependency-name: k8s.io/component-helpers dependency-type: direct:production update-type: version-update:semver-patch dependency-group: gomod ... Signed-off-by: dependabot[bot] --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 7ee2fd97e..37e4e0234 100644 --- a/go.mod +++ b/go.mod @@ -21,10 +21,10 @@ require ( golang.org/x/sys v0.29.0 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 google.golang.org/protobuf v1.36.1 - k8s.io/api v0.31.4 - k8s.io/apimachinery v0.31.4 - k8s.io/client-go v0.31.4 - k8s.io/component-helpers v0.31.4 + k8s.io/api v0.31.5 + k8s.io/apimachinery v0.31.5 + k8s.io/client-go v0.31.5 + k8s.io/component-helpers v0.31.5 k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 sigs.k8s.io/controller-runtime v0.19.3 sigs.k8s.io/knftables v0.0.18 diff --git a/go.sum b/go.sum index 00340b583..78927d001 100644 --- a/go.sum +++ b/go.sum @@ -679,28 +679,28 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= k8s.io/api v0.18.2/go.mod h1:SJCWI7OLzhZSvbY7U8zwNl9UA4o1fizoug34OV/2r78= k8s.io/api v0.18.4/go.mod h1:lOIQAKYgai1+vz9J7YcDZwC26Z0zQewYOGWdyIPUUQ4= -k8s.io/api v0.31.4 h1:I2QNzitPVsPeLQvexMEsj945QumYraqv9m74isPDKhM= -k8s.io/api v0.31.4/go.mod h1:d+7vgXLvmcdT1BCo79VEgJxHHryww3V5np2OYTr6jdw= +k8s.io/api v0.31.5 h1:7jP74egbPUOCLJV5KheUnwo9gz3zzUsMIj2EPkuYK1E= +k8s.io/api v0.31.5/go.mod h1:RMyMdZG1kJjou2ng5buEti0OHlo0uFXgSzTZ/k5LeVk= k8s.io/apiextensions-apiserver v0.18.2/go.mod h1:q3faSnRGmYimiocj6cHQ1I3WpLqmDgJFlKL37fC4ZvY= k8s.io/apiextensions-apiserver v0.18.4/go.mod h1:NYeyeYq4SIpFlPxSAB6jHPIdvu3hL0pc36wuRChybio= k8s.io/apiextensions-apiserver v0.31.0 h1:fZgCVhGwsclj3qCw1buVXCV6khjRzKC5eCFt24kyLSk= k8s.io/apiextensions-apiserver v0.31.0/go.mod h1:b9aMDEYaEe5sdK+1T0KU78ApR/5ZVp4i56VacZYEHxk= k8s.io/apimachinery v0.18.2/go.mod h1:9SnR/e11v5IbyPCGbvJViimtJ0SwHG4nfZFjU77ftcA= k8s.io/apimachinery v0.18.4/go.mod h1:OaXp26zu/5J7p0f92ASynJa1pZo06YlV9fG7BoWbCko= -k8s.io/apimachinery v0.31.4 h1:8xjE2C4CzhYVm9DGf60yohpNUh5AEBnPxCryPBECmlM= -k8s.io/apimachinery v0.31.4/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= +k8s.io/apimachinery v0.31.5 h1:NxhAVGcfrSdTMx3M2v1OnvcMS7h1ZnWyt2x2z8CJJBU= +k8s.io/apimachinery v0.31.5/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo= k8s.io/apiserver v0.18.2/go.mod h1:Xbh066NqrZO8cbsoenCwyDJ1OSi8Ag8I2lezeHxzwzw= k8s.io/apiserver v0.18.4/go.mod h1:q+zoFct5ABNnYkGIaGQ3bcbUNdmPyOCoEBcg51LChY8= k8s.io/client-go v0.18.2/go.mod h1:Xcm5wVGXX9HAA2JJ2sSBUn3tCJ+4SVlCbl2MNNv+CIU= k8s.io/client-go v0.18.4/go.mod h1:f5sXwL4yAZRkAtzOxRWUhA/N8XzGCb+nPZI8PfobZ9g= -k8s.io/client-go v0.31.4 h1:t4QEXt4jgHIkKKlx06+W3+1JOwAFU/2OPiOo7H92eRQ= -k8s.io/client-go v0.31.4/go.mod h1:kvuMro4sFYIa8sulL5Gi5GFqUPvfH2O/dXuKstbaaeg= +k8s.io/client-go v0.31.5 h1:rmDswcUaIFAJ5vJaB82pjyqc52DgHCPv0G6af3OupO0= +k8s.io/client-go v0.31.5/go.mod h1:js93IlRSzRHql9o9zP54N56rMR249uH4+srnSOcFLsU= k8s.io/code-generator v0.18.2/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc= k8s.io/code-generator v0.18.4/go.mod h1:TgNEVx9hCyPGpdtCWA34olQYLkh3ok9ar7XfSsr8b6c= k8s.io/component-base v0.18.2/go.mod h1:kqLlMuhJNHQ9lz8Z7V5bxUUtjFZnrypArGl58gmDfUM= k8s.io/component-base v0.18.4/go.mod h1:7jr/Ef5PGmKwQhyAz/pjByxJbC58mhKAhiaDu0vXfPk= -k8s.io/component-helpers v0.31.4 h1:pqokuXozyWVrVBMmx0AMcKqNWqXhR00OZvpAE5hG5NM= -k8s.io/component-helpers v0.31.4/go.mod h1:Ddq5GYRK/1uNoPNgJh9N5osPutvBweQEcIG6b8kcvgQ= +k8s.io/component-helpers v0.31.5 h1:4CGg9/+RLbeM2r5nPyoyocsAteXRGHs4yv23yBdw7KE= +k8s.io/component-helpers v0.31.5/go.mod h1:E2i3XIrLFiGUdTOTrJvKPlDs9eVja4vm+N4nDk6XTRw= k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/gengo v0.0.0-20200114144118-36b2048a9120/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= From fe74afa6cf4a5a391da4d5a8df40b576a843d83d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 20:58:04 +0000 Subject: [PATCH 3/5] Bump the github-actions group with 7 updates Bumps the github-actions group with 7 updates: | Package | From | To | | --- | --- | --- | | [github/codeql-action](https://github.com/github/codeql-action) | `3.27.5` | `3.28.1` | | [anchore/scan-action](https://github.com/anchore/scan-action) | `5.3.0` | `6.0.0` | | [docker/setup-qemu-action](https://github.com/docker/setup-qemu-action) | `3.2.0` | `3.3.0` | | [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) | `7.0.5` | `7.0.6` | | [sonarsource/sonarcloud-github-action](https://github.com/sonarsource/sonarcloud-github-action) | `3.1.0` | `4.0.0` | | [actions/stale](https://github.com/actions/stale) | `f69122271d990fd11f5594ccff2296f00ff59b49` | `fa77dfddd04682b7d96dbc4e016318e681fdc10e` | | [actions/upload-artifact](https://github.com/actions/upload-artifact) | `4.4.3` | `4.6.0` | Updates `github/codeql-action` from 3.27.5 to 3.28.1 - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/f09c1c0a94de965c15400f5634aa42fac8fb8f88...b6a472f63d85b9c78a3ac5e89422239fc15e9b3c) Updates `anchore/scan-action` from 5.3.0 to 6.0.0 - [Release notes](https://github.com/anchore/scan-action/releases) - [Changelog](https://github.com/anchore/scan-action/blob/main/RELEASE.md) - [Commits](https://github.com/anchore/scan-action/compare/869c549e657a088dc0441b08ce4fc0ecdac2bb65...abae793926ec39a78ab18002bc7fc45bbbd94342) Updates `docker/setup-qemu-action` from 3.2.0 to 3.3.0 - [Release notes](https://github.com/docker/setup-qemu-action/releases) - [Commits](https://github.com/docker/setup-qemu-action/compare/49b3bc8e6bdd4a60e6116a5414239cba5943d3cf...53851d14592bedcffcf25ea515637cff71ef929a) Updates `peter-evans/create-pull-request` from 7.0.5 to 7.0.6 - [Release notes](https://github.com/peter-evans/create-pull-request/releases) - [Commits](https://github.com/peter-evans/create-pull-request/compare/5e914681df9dc83aa4e4905692ca88beb2f9e91f...67ccf781d68cd99b580ae25a5c18a1cc84ffff1f) Updates `sonarsource/sonarcloud-github-action` from 3.1.0 to 4.0.0 - [Release notes](https://github.com/sonarsource/sonarcloud-github-action/releases) - [Commits](https://github.com/sonarsource/sonarcloud-github-action/compare/383f7e52eae3ab0510c3cb0e7d9d150bbaeab838...02ef91109b2d589e757aefcfb2854c2783fd7b19) Updates `actions/stale` from f69122271d990fd11f5594ccff2296f00ff59b49 to fa77dfddd04682b7d96dbc4e016318e681fdc10e - [Release notes](https://github.com/actions/stale/releases) - [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/stale/compare/f69122271d990fd11f5594ccff2296f00ff59b49...fa77dfddd04682b7d96dbc4e016318e681fdc10e) Updates `actions/upload-artifact` from 4.4.3 to 4.6.0 - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882...65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions - dependency-name: anchore/scan-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: docker/setup-qemu-action dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions - dependency-name: peter-evans/create-pull-request dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-actions - dependency-name: sonarsource/sonarcloud-github-action dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/stale dependency-type: direct:production dependency-group: github-actions - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-actions ... Signed-off-by: dependabot[bot] --- .github/workflows/linting.yml | 8 ++++---- .github/workflows/multiarch.yml | 2 +- .github/workflows/periodic.yml | 2 +- .github/workflows/report.yml | 10 +++++----- .github/workflows/stale.yml | 2 +- .github/workflows/unit.yml | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 434159c20..f03d2a32d 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -146,11 +146,11 @@ jobs: - name: Check out the repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Initialize CodeQL - uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 + uses: github/codeql-action/init@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c with: languages: go - name: Run CodeQL variant analysis - uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 + uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c - name: Show CodeQL scan SARIF report if: always() run: cat ../results/go.sarif @@ -162,7 +162,7 @@ jobs: - name: Check out the repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Run Anchore vulnerability scanner - uses: anchore/scan-action@869c549e657a088dc0441b08ce4fc0ecdac2bb65 + uses: anchore/scan-action@abae793926ec39a78ab18002bc7fc45bbbd94342 id: scan with: path: "." @@ -173,7 +173,7 @@ jobs: run: cat ${{ steps.scan.outputs.sarif }} - name: Upload Anchore scan SARIF report if: always() - uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 + uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c with: sarif_file: ${{ steps.scan.outputs.sarif }} diff --git a/.github/workflows/multiarch.yml b/.github/workflows/multiarch.yml index 651d94ee3..4e854c46d 100644 --- a/.github/workflows/multiarch.yml +++ b/.github/workflows/multiarch.yml @@ -14,7 +14,7 @@ jobs: - name: Check out the repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Set up QEMU (to support building on non-native architectures) - uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf + uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a - name: Build the multi-arch images run: make multiarch-images - name: Check that we actually build multi-arch images diff --git a/.github/workflows/periodic.yml b/.github/workflows/periodic.yml index 1b5a5c000..971ae5eb8 100644 --- a/.github/workflows/periodic.yml +++ b/.github/workflows/periodic.yml @@ -26,7 +26,7 @@ jobs: done - name: Create Pull Request - uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f + uses: peter-evans/create-pull-request@67ccf781d68cd99b580ae25a5c18a1cc84ffff1f with: title: Update submariner-io/* dependencies to latest body: | diff --git a/.github/workflows/report.yml b/.github/workflows/report.yml index 6cc9fab81..525536349 100644 --- a/.github/workflows/report.yml +++ b/.github/workflows/report.yml @@ -24,7 +24,7 @@ jobs: run: make unit - name: Run SonarScan, upload Go test results and coverage - uses: sonarsource/sonarcloud-github-action@383f7e52eae3ab0510c3cb0e7d9d150bbaeab838 + uses: sonarsource/sonarcloud-github-action@02ef91109b2d589e757aefcfb2854c2783fd7b19 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} @@ -38,11 +38,11 @@ jobs: - name: Check out the repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Initialize CodeQL - uses: github/codeql-action/init@f09c1c0a94de965c15400f5634aa42fac8fb8f88 + uses: github/codeql-action/init@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c with: languages: go - name: Run CodeQL variant analysis - uses: github/codeql-action/analyze@f09c1c0a94de965c15400f5634aa42fac8fb8f88 + uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c - name: Show CodeQL scan SARIF report if: always() run: cat ../results/go.sarif @@ -57,7 +57,7 @@ jobs: - name: Check out the repository uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 - name: Run Anchore vulnerability scanner - uses: anchore/scan-action@869c549e657a088dc0441b08ce4fc0ecdac2bb65 + uses: anchore/scan-action@abae793926ec39a78ab18002bc7fc45bbbd94342 id: scan with: path: "." @@ -65,6 +65,6 @@ jobs: - name: Show Anchore scan SARIF report run: cat ${{ steps.scan.outputs.sarif }} - name: Upload Anchore scan SARIF report - uses: github/codeql-action/upload-sarif@f09c1c0a94de965c15400f5634aa42fac8fb8f88 + uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c with: sarif_file: ${{ steps.scan.outputs.sarif }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 4fd6ef8e6..912a30de4 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -16,7 +16,7 @@ jobs: issues: write pull-requests: write steps: - - uses: actions/stale@f69122271d990fd11f5594ccff2296f00ff59b49 + - uses: actions/stale@fa77dfddd04682b7d96dbc4e016318e681fdc10e with: days-before-issue-stale: 120 days-before-pr-stale: 14 diff --git a/.github/workflows/unit.yml b/.github/workflows/unit.yml index 67fabb360..a52611818 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/unit.yml @@ -30,7 +30,7 @@ jobs: done - name: Upload artifacts - uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 + uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 with: name: Unit test artifacts path: artifacts From 2c0e7b5254bc5e6a3d898141b233ebd89c32a258 Mon Sep 17 00:00:00 2001 From: Tom Pantelis Date: Wed, 15 Jan 2025 14:36:53 -0500 Subject: [PATCH 4/5] Add plural IP fields to EndpointSpec ...that mirror the singular HealthCheckIP, PrivateIP and PublicIP fields to support dual-stack addresses. The singular fields are deprecated and remain to support backwards compatibility and migration with prior versions. Going forward only the plural fields will be used. Get*IP/Add*IP methods were added to EndpointSpec that handle the singular fields. On Get for IPv4, if the plural field doesn't contain an IPv4 address then retrieve the singular field. On Set for IPv4 also set the corresponding singular field. Signed-off-by: Tom Pantelis --- pkg/apis/submariner.io/v1/endpoint.go | 58 +++++ pkg/apis/submariner.io/v1/endpoint_test.go | 229 ++++++++++++++++++ pkg/apis/submariner.io/v1/string_test.go | 36 ++- pkg/apis/submariner.io/v1/types.go | 21 +- .../submariner.io/v1/zz_generated.deepcopy.go | 15 ++ .../submariner.io/v1/endpointspec.go | 53 +++- 6 files changed, 378 insertions(+), 34 deletions(-) diff --git a/pkg/apis/submariner.io/v1/endpoint.go b/pkg/apis/submariner.io/v1/endpoint.go index ff50c18f8..95ebabd8c 100644 --- a/pkg/apis/submariner.io/v1/endpoint.go +++ b/pkg/apis/submariner.io/v1/endpoint.go @@ -25,6 +25,7 @@ import ( "github.com/pkg/errors" "github.com/submariner-io/admiral/pkg/resource" "k8s.io/apimachinery/pkg/api/equality" + k8snet "k8s.io/utils/net" ) func (ep *EndpointSpec) GetBackendPort(configName string, defaultValue int32) (int32, error) { @@ -102,3 +103,60 @@ func (ep *EndpointSpec) hasSameBackendConfig(other *EndpointSpec) bool { return equality.Semantic.DeepEqual(ep.BackendConfig, other.BackendConfig) } + +func getIPFrom(family k8snet.IPFamily, ips []string, ipv4Fallback string) string { + for _, ip := range ips { + if k8snet.IPFamilyOfString(ip) == family { + return ip + } + } + + if family == k8snet.IPv4 { + return ipv4Fallback + } + + return "" +} + +func setIP(ips []string, ipv4Fallback, newIP string) ([]string, string) { + family := k8snet.IPFamilyOfString(newIP) + + if family == k8snet.IPv4 { + ipv4Fallback = newIP + } + + for i := range ips { + if k8snet.IPFamilyOfString(ips[i]) == family { + ips[i] = newIP + return ips, ipv4Fallback + } + } + + ips = append(ips, newIP) + + return ips, ipv4Fallback +} + +func (ep *EndpointSpec) GetHealthCheckIP(family k8snet.IPFamily) string { + return getIPFrom(family, ep.HealthCheckIPs, ep.HealthCheckIP) +} + +func (ep *EndpointSpec) SetHealthCheckIP(ip string) { + ep.HealthCheckIPs, ep.HealthCheckIP = setIP(ep.HealthCheckIPs, ep.HealthCheckIP, ip) +} + +func (ep *EndpointSpec) GetPublicIP(family k8snet.IPFamily) string { + return getIPFrom(family, ep.PublicIPs, ep.PublicIP) +} + +func (ep *EndpointSpec) SetPublicIP(ip string) { + ep.PublicIPs, ep.PublicIP = setIP(ep.PublicIPs, ep.PublicIP, ip) +} + +func (ep *EndpointSpec) GetPrivateIP(family k8snet.IPFamily) string { + return getIPFrom(family, ep.PrivateIPs, ep.PrivateIP) +} + +func (ep *EndpointSpec) SetPrivateIP(ip string) { + ep.PrivateIPs, ep.PrivateIP = setIP(ep.PrivateIPs, ep.PrivateIP, ip) +} diff --git a/pkg/apis/submariner.io/v1/endpoint_test.go b/pkg/apis/submariner.io/v1/endpoint_test.go index 37c4554da..13e197486 100644 --- a/pkg/apis/submariner.io/v1/endpoint_test.go +++ b/pkg/apis/submariner.io/v1/endpoint_test.go @@ -22,11 +22,23 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" v1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1" + k8snet "k8s.io/utils/net" +) + +const ( + ipV4Addr = "1.2.3.4" + ipV6Addr = "2001:db8:3333:4444:5555:6666:7777:8888" ) var _ = Describe("EndpointSpec", func() { Context("GenerateName", testGenerateName) Context("Equals", testEquals) + Context("GetHealthCheckIP", testGetHealthCheckIP) + Context("SetHealthCheckIP", testSetHealthCheckIP) + Context("GetPublicIP", testGetPublicIP) + Context("SetPublicIP", testSetPublicIP) + Context("GetPrivateIP", testGetPrivateIP) + Context("SetPrivateIP", testSetPrivateIP) }) func testGenerateName() { @@ -138,3 +150,220 @@ func testEquals() { }) }) } + +func testGetIP(ipsSetter func(*v1.EndpointSpec, []string, string), ipsGetter func(*v1.EndpointSpec, k8snet.IPFamily) string) { + var ( + spec *v1.EndpointSpec + legacyIPv4IP string + ips []string + ) + + BeforeEach(func() { + legacyIPv4IP = "" + ips = []string{} + }) + + JustBeforeEach(func() { + spec = &v1.EndpointSpec{} + ipsSetter(spec, ips, legacyIPv4IP) + }) + + Context("IPv4", func() { + When("an IPv4 address is present", func() { + BeforeEach(func() { + ips = []string{ipV6Addr, ipV4Addr} + }) + + It("should return the address", func() { + Expect(ipsGetter(spec, k8snet.IPv4)).To(Equal(ipV4Addr)) + }) + }) + + When("an IPv4 address is not present and the legacy IPv4 address is set", func() { + BeforeEach(func() { + ips = []string{ipV6Addr} + legacyIPv4IP = ipV4Addr + }) + + It("should return the legacy address", func() { + Expect(ipsGetter(spec, k8snet.IPv4)).To(Equal(ipV4Addr)) + }) + }) + + When("an IPv4 address is not present and the legacy IPv4 address is not set", func() { + It("should return empty string", func() { + Expect(ipsGetter(spec, k8snet.IPv4)).To(BeEmpty()) + }) + }) + }) + + Context("IPv6", func() { + When("an IPv6 address is present", func() { + BeforeEach(func() { + ips = []string{ipV4Addr, ipV6Addr} + }) + + It("should return the address", func() { + Expect(ipsGetter(spec, k8snet.IPv6)).To(Equal(ipV6Addr)) + }) + }) + + When("an IPv6 address is not present", func() { + BeforeEach(func() { + ips = []string{ipV4Addr} + }) + + It("should return empty string", func() { + Expect(ipsGetter(spec, k8snet.IPv6)).To(BeEmpty()) + }) + }) + }) +} + +func testSetIP(initIPs func(*v1.EndpointSpec, []string), ipsSetter func(*v1.EndpointSpec, string), + ipsGetter func(*v1.EndpointSpec) ([]string, string), +) { + var ( + spec *v1.EndpointSpec + ipToSet string + initialIPs []string + ) + + BeforeEach(func() { + spec = &v1.EndpointSpec{} + initialIPs = []string{} + ipToSet = "" + }) + + JustBeforeEach(func() { + initIPs(spec, initialIPs) + ipsSetter(spec, ipToSet) + }) + + verifyIPs := func(ips []string, legacyV4 string) { + actualIPs, actualLegacy := ipsGetter(spec) + Expect(actualIPs).To(Equal(ips)) + Expect(actualLegacy).To(Equal(legacyV4)) + } + + Context("IPv4", func() { + BeforeEach(func() { + ipToSet = ipV4Addr + }) + + When("no addresses are present", func() { + It("should add the new address", func() { + verifyIPs([]string{ipToSet}, ipToSet) + }) + }) + + When("no IPv4 address is present", func() { + BeforeEach(func() { + initialIPs = []string{ipV6Addr} + }) + + It("should add the new address", func() { + verifyIPs([]string{ipV6Addr, ipToSet}, ipToSet) + }) + }) + + When("an IPv4 address is already present", func() { + BeforeEach(func() { + initialIPs = []string{"11.22.33.44"} + }) + + It("should update address", func() { + verifyIPs([]string{ipToSet}, ipToSet) + }) + }) + }) + + Context("IPv6", func() { + BeforeEach(func() { + ipToSet = ipV6Addr + }) + + When("no addresses are present", func() { + It("should add the new address", func() { + verifyIPs([]string{ipToSet}, "") + }) + }) + + When("no IPv6 address is present", func() { + BeforeEach(func() { + initialIPs = []string{ipV4Addr} + }) + + It("should add the new address", func() { + verifyIPs([]string{ipV4Addr, ipToSet}, "") + }) + }) + + When("an IPv6 address is already present", func() { + BeforeEach(func() { + initialIPs = []string{"1234:cb9:3333:4444:5555:6666:7777:8888"} + }) + + It("should update address", func() { + verifyIPs([]string{ipToSet}, "") + }) + }) + }) +} + +func testGetHealthCheckIP() { + testGetIP(func(s *v1.EndpointSpec, ips []string, ipv4IP string) { + s.HealthCheckIPs = ips + s.HealthCheckIP = ipv4IP + }, func(s *v1.EndpointSpec, family k8snet.IPFamily) string { + return s.GetHealthCheckIP(family) + }) +} + +func testSetHealthCheckIP() { + testSetIP(func(s *v1.EndpointSpec, ips []string) { + s.HealthCheckIPs = ips + }, func(s *v1.EndpointSpec, ip string) { + s.SetHealthCheckIP(ip) + }, func(s *v1.EndpointSpec) ([]string, string) { + return s.HealthCheckIPs, s.HealthCheckIP + }) +} + +func testGetPublicIP() { + testGetIP(func(s *v1.EndpointSpec, ips []string, ipv4IP string) { + s.PublicIPs = ips + s.PublicIP = ipv4IP + }, func(s *v1.EndpointSpec, family k8snet.IPFamily) string { + return s.GetPublicIP(family) + }) +} + +func testSetPublicIP() { + testSetIP(func(s *v1.EndpointSpec, ips []string) { + s.PublicIPs = ips + }, func(s *v1.EndpointSpec, ip string) { + s.SetPublicIP(ip) + }, func(s *v1.EndpointSpec) ([]string, string) { + return s.PublicIPs, s.PublicIP + }) +} + +func testGetPrivateIP() { + testGetIP(func(s *v1.EndpointSpec, ips []string, ipv4IP string) { + s.PrivateIPs = ips + s.PrivateIP = ipv4IP + }, func(s *v1.EndpointSpec, family k8snet.IPFamily) string { + return s.GetPrivateIP(family) + }) +} + +func testSetPrivateIP() { + testSetIP(func(s *v1.EndpointSpec, ips []string) { + s.PrivateIPs = ips + }, func(s *v1.EndpointSpec, ip string) { + s.SetPrivateIP(ip) + }, func(s *v1.EndpointSpec) ([]string, string) { + return s.PrivateIPs, s.PrivateIP + }) +} diff --git a/pkg/apis/submariner.io/v1/string_test.go b/pkg/apis/submariner.io/v1/string_test.go index 18647a29d..6a22b4126 100644 --- a/pkg/apis/submariner.io/v1/string_test.go +++ b/pkg/apis/submariner.io/v1/string_test.go @@ -26,25 +26,23 @@ import ( v1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1" ) -const expectedString = `{"metadata":{"creationTimestamp":null},"spec":{"cluster_id":"cluster-id","cable_name":` + - `"cable-1","hostname":"","subnets":["10.0.0.0/24","172.0.0.0/24"],"private_ip":"1.1.1.1",` + - `"public_ip":"","nat_enabled":false,"backend":""}}` - -var _ = Describe("API v1", func() { - When("Endpoint String representation called", func() { - It("Should return a human readable string", func() { - endpoint := v1.Endpoint{ - Spec: v1.EndpointSpec{ - ClusterID: "cluster-id", - Subnets: []string{"10.0.0.0/24", "172.0.0.0/24"}, - CableName: "cable-1", - PublicIP: "", - PrivateIP: "1.1.1.1", - }, - } - - Expect(endpoint.String()).To(Equal(expectedString)) - }) +var _ = Describe("Endpoint String", func() { + It("should return a human readable string", func() { + str := (&v1.Endpoint{ + Spec: v1.EndpointSpec{ + ClusterID: "east", + Subnets: []string{"10.0.0.0/24"}, + CableName: "cable-1", + PublicIPs: []string{"1.1.1.1"}, + PrivateIPs: []string{"2.2.2.2"}, + }, + }).String() + + Expect(str).To(ContainSubstring("east")) + Expect(str).To(ContainSubstring("10.0.0.0/24")) + Expect(str).To(ContainSubstring("cable-1")) + Expect(str).To(ContainSubstring("1.1.1.1")) + Expect(str).To(ContainSubstring("2.2.2.2")) }) }) diff --git a/pkg/apis/submariner.io/v1/types.go b/pkg/apis/submariner.io/v1/types.go index a62c2d1df..2ae49310e 100644 --- a/pkg/apis/submariner.io/v1/types.go +++ b/pkg/apis/submariner.io/v1/types.go @@ -79,11 +79,22 @@ type EndpointSpec struct { ClusterID string `json:"cluster_id"` CableName string `json:"cable_name"` // +optional - HealthCheckIP string `json:"healthCheckIP,omitempty"` - Hostname string `json:"hostname"` - Subnets []string `json:"subnets"` - PrivateIP string `json:"private_ip"` - PublicIP string `json:"public_ip"` + HealthCheckIP string `json:"healthCheckIP,omitempty"` + // +kubebuilder:validation:MaxItems:=2 + // +optional + HealthCheckIPs []string `json:"healthCheckIPs,omitempty"` + Hostname string `json:"hostname"` + Subnets []string `json:"subnets"` + // +optional + PrivateIP string `json:"private_ip,omitempty"` + // +kubebuilder:validation:MaxItems:=2 + // +optional + PrivateIPs []string `json:"privateIPs,omitempty"` + // +optional + PublicIP string `json:"public_ip,omitempty"` + // +kubebuilder:validation:MaxItems:=2 + // +optional + PublicIPs []string `json:"publicIPs,omitempty"` NATEnabled bool `json:"nat_enabled"` Backend string `json:"backend"` BackendConfig map[string]string `json:"backend_config,omitempty"` diff --git a/pkg/apis/submariner.io/v1/zz_generated.deepcopy.go b/pkg/apis/submariner.io/v1/zz_generated.deepcopy.go index 8d7627979..bcab1db27 100644 --- a/pkg/apis/submariner.io/v1/zz_generated.deepcopy.go +++ b/pkg/apis/submariner.io/v1/zz_generated.deepcopy.go @@ -292,11 +292,26 @@ func (in *EndpointList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *EndpointSpec) DeepCopyInto(out *EndpointSpec) { *out = *in + if in.HealthCheckIPs != nil { + in, out := &in.HealthCheckIPs, &out.HealthCheckIPs + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Subnets != nil { in, out := &in.Subnets, &out.Subnets *out = make([]string, len(*in)) copy(*out, *in) } + if in.PrivateIPs != nil { + in, out := &in.PrivateIPs, &out.PrivateIPs + *out = make([]string, len(*in)) + copy(*out, *in) + } + if in.PublicIPs != nil { + in, out := &in.PublicIPs, &out.PublicIPs + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.BackendConfig != nil { in, out := &in.BackendConfig, &out.BackendConfig *out = make(map[string]string, len(*in)) diff --git a/pkg/client/applyconfiguration/submariner.io/v1/endpointspec.go b/pkg/client/applyconfiguration/submariner.io/v1/endpointspec.go index 60abf564d..8339f3e5b 100644 --- a/pkg/client/applyconfiguration/submariner.io/v1/endpointspec.go +++ b/pkg/client/applyconfiguration/submariner.io/v1/endpointspec.go @@ -23,16 +23,19 @@ package v1 // EndpointSpecApplyConfiguration represents a declarative configuration of the EndpointSpec type for use // with apply. type EndpointSpecApplyConfiguration struct { - ClusterID *string `json:"cluster_id,omitempty"` - CableName *string `json:"cable_name,omitempty"` - HealthCheckIP *string `json:"healthCheckIP,omitempty"` - Hostname *string `json:"hostname,omitempty"` - Subnets []string `json:"subnets,omitempty"` - PrivateIP *string `json:"private_ip,omitempty"` - PublicIP *string `json:"public_ip,omitempty"` - NATEnabled *bool `json:"nat_enabled,omitempty"` - Backend *string `json:"backend,omitempty"` - BackendConfig map[string]string `json:"backend_config,omitempty"` + ClusterID *string `json:"cluster_id,omitempty"` + CableName *string `json:"cable_name,omitempty"` + HealthCheckIP *string `json:"healthCheckIP,omitempty"` + HealthCheckIPs []string `json:"healthCheckIPs,omitempty"` + Hostname *string `json:"hostname,omitempty"` + Subnets []string `json:"subnets,omitempty"` + PrivateIP *string `json:"private_ip,omitempty"` + PrivateIPs []string `json:"privateIPs,omitempty"` + PublicIP *string `json:"public_ip,omitempty"` + PublicIPs []string `json:"publicIPs,omitempty"` + NATEnabled *bool `json:"nat_enabled,omitempty"` + Backend *string `json:"backend,omitempty"` + BackendConfig map[string]string `json:"backend_config,omitempty"` } // EndpointSpecApplyConfiguration constructs a declarative configuration of the EndpointSpec type for use with @@ -65,6 +68,16 @@ func (b *EndpointSpecApplyConfiguration) WithHealthCheckIP(value string) *Endpoi return b } +// WithHealthCheckIPs adds the given value to the HealthCheckIPs field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the HealthCheckIPs field. +func (b *EndpointSpecApplyConfiguration) WithHealthCheckIPs(values ...string) *EndpointSpecApplyConfiguration { + for i := range values { + b.HealthCheckIPs = append(b.HealthCheckIPs, values[i]) + } + return b +} + // WithHostname sets the Hostname field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the Hostname field is set to the value of the last call. @@ -91,6 +104,16 @@ func (b *EndpointSpecApplyConfiguration) WithPrivateIP(value string) *EndpointSp return b } +// WithPrivateIPs adds the given value to the PrivateIPs field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the PrivateIPs field. +func (b *EndpointSpecApplyConfiguration) WithPrivateIPs(values ...string) *EndpointSpecApplyConfiguration { + for i := range values { + b.PrivateIPs = append(b.PrivateIPs, values[i]) + } + return b +} + // WithPublicIP sets the PublicIP field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the PublicIP field is set to the value of the last call. @@ -99,6 +122,16 @@ func (b *EndpointSpecApplyConfiguration) WithPublicIP(value string) *EndpointSpe return b } +// WithPublicIPs adds the given value to the PublicIPs field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the PublicIPs field. +func (b *EndpointSpecApplyConfiguration) WithPublicIPs(values ...string) *EndpointSpecApplyConfiguration { + for i := range values { + b.PublicIPs = append(b.PublicIPs, values[i]) + } + return b +} + // WithNATEnabled sets the NATEnabled field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the NATEnabled field is set to the value of the last call. From 3c245971bc835eb3d2bda02abb77c375fc011f8d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:56:20 +0000 Subject: [PATCH 5/5] Bump k8s.io/code-generator in /tools in the gomod group Bumps the gomod group in /tools with 1 update: [k8s.io/code-generator](https://github.com/kubernetes/code-generator). Updates `k8s.io/code-generator` from 0.31.3 to 0.31.5 - [Commits](https://github.com/kubernetes/code-generator/compare/v0.31.3...v0.31.5) --- updated-dependencies: - dependency-name: k8s.io/code-generator dependency-type: direct:production update-type: version-update:semver-patch dependency-group: gomod ... Signed-off-by: dependabot[bot] --- tools/go.mod | 2 +- tools/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/go.mod b/tools/go.mod index 9e7acdbf8..830862c9d 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/uw-labs/lichen v0.1.7 - k8s.io/code-generator v0.31.3 + k8s.io/code-generator v0.31.5 ) require ( diff --git a/tools/go.sum b/tools/go.sum index cd34d02c2..1d1cb9e6e 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -109,8 +109,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/code-generator v0.31.3 h1:Pj0fYOBms+ZrsulLi4DMsCEx1jG8fWKRLy44onHsLBI= -k8s.io/code-generator v0.31.3/go.mod h1:/umCIlT84g1+Yu5ZXtP1KGSRTnGiIzzX5AzUAxsNlts= +k8s.io/code-generator v0.31.5 h1:nEvmAhA0tiaoHqS3ZsW/SjbGdzex4TzOlicVPoSVG8E= +k8s.io/code-generator v0.31.5/go.mod h1:svmu9SPsjrNeC/T/nilkqsI0KWnC8XUandi9ECMNqRo= k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70 h1:NGrVE502P0s0/1hudf8zjgwki1X/TByhmAoILTarmzo= k8s.io/gengo/v2 v2.0.0-20240228010128-51d4e06bde70/go.mod h1:VH3AT8AaQOqiGjMF9p0/IM1Dj+82ZwjfxUP1IxaHE+8= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=