Repository: metallb/metallb
Pull request #1852 (2023-03-02 03:00:03)

Bump sigs.k8s.io/controller-runtime from 0.14.1 to 0.14.5
Bumps [sigs.k8s.io/controller-runtime](https://github.com/kubernetes-sigs/controller-runtime) from 0.14.1 to 0.14.5.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/kubernetes-sigs/controller-runtime/releases">sigs.k8s.io/controller-runtime's releases</a>.</em></p>
<blockquote>
<h2>v0.14.5</h2>
<h2>What's Changed</h2>
<ul>
<li>🐛 Allow to set GracefulShutdownTimeout to -1, disabling timeouts in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2198">kubernetes-sigs/controller-runtime#2198</a></li>
<li>🌱 GVKForObject should handle multiple GVKs in Scheme gracefully in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2202">kubernetes-sigs/controller-runtime#2202</a></li>
<li>✨ Add rest client request duration and size metrics in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2218">kubernetes-sigs/controller-runtime#2218</a></li>
<li>🐛 Allow lazy restmapper to work with CRDs created at runtime in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2219">kubernetes-sigs/controller-runtime#2219</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.4...v0.14.5">https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.4...v0.14.5</a></p>
<h2>v0.14.4</h2>
<h2>What's Changed</h2>
<ul>
<li>✨ Provide a truly lazy restmapper by <a href="https://github.com/k8s-infra-cherrypick-robot"><code>@​k8s-infra-cherrypick-robot</code></a> in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2179">kubernetes-sigs/controller-runtime#2179</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.3...v0.14.4">https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.3...v0.14.4</a></p>
<h2>v0.14.3</h2>
<h2>What's Changed</h2>
<ul>
<li>✨ Add additional SubResource* functions for FieldOwner by <a href="https://github.com/k8s-infra-cherrypick-robot"><code>@​k8s-infra-cherrypick-robot</code></a> in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2153">kubernetes-sigs/controller-runtime#2153</a></li>
<li>🐛 Update golanci-lint script by <a href="https://github.com/k8s-infra-cherrypick-robot"><code>@​k8s-infra-cherrypick-robot</code></a> in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2152">kubernetes-sigs/controller-runtime#2152</a></li>
<li>🌱 Bump kubebuilder-release-tools to v0.3.0 by <a href="https://github.com/k8s-infra-cherrypick-robot"><code>@​k8s-infra-cherrypick-robot</code></a> in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2154">kubernetes-sigs/controller-runtime#2154</a></li>
<li>🌱 [0.14] Deprecate component configuration package by <a href="https://github.com/vincepri"><code>@​vincepri</code></a> in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2165">kubernetes-sigs/controller-runtime#2165</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.2...v0.14.3">https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.2...v0.14.3</a></p>
<h2>v0.14.2</h2>
<h2>What's Changed</h2>
<ul>
<li>[release-0.14] 🌱 Bump k8s.io/* to v0.26.1 by <a href="https://github.com/sbueringer"><code>@​sbueringer</code></a> in <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/pull/2146">kubernetes-sigs/controller-runtime#2146</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a href="https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.1...v0.14.2">https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.1...v0.14.2</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/ffb74e54a54bcb10a615c501416820e06051b9b4"><code>ffb74e5</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/issues/2219">#2219</a> from sbueringer/pr-cherry-lazy-restmapper-fix</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/66fe1a07410b0a96d75cf7fe752154ed9fedff93"><code>66fe1a0</code></a> Allow lazy restmapper to work with CRDs created in runtime</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/0b49f2e2e1506ca1ada6d51e7b5a24b1742cbc12"><code>0b49f2e</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/issues/2218">#2218</a> from k8s-infra-cherrypick-robot/cherry-pick-2217-to-...</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/96165fb31cce650e08f530b2ce3e1bc8e85f7bf7"><code>96165fb</code></a> Add rest client request duration and size metrics</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/b6fc422accf925890b9bd8832f99ecd0eba40c6c"><code>b6fc422</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/issues/2202">#2202</a> from k8s-infra-cherrypick-robot/cherry-pick-2192-to-...</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/1e00eecb19875fc0ecf3a75e3c0773e398cdf3ec"><code>1e00eec</code></a> GVKForObject should handle multiple GVKs in Scheme gracefully</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/7a19e15a6a97890398888106c2f5643c2f680c5b"><code>7a19e15</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/issues/2198">#2198</a> from k8s-infra-cherrypick-robot/cherry-pick-2169-to-...</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/d4a8a96b51954909f3918027dadcbe70d0b3e89d"><code>d4a8a96</code></a> Allow to set GracefulShutdownTimeout to -1, disabling timeouts</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/a9d61073fe2b7a399989e5cb3f6fc9dbea9eb782"><code>a9d6107</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/kubernetes-sigs/controller-runtime/issues/2190">#2190</a> from kubernetes-sigs/revert-2165-deprecate-component...</li>
<li><a href="https://github.com/kubernetes-sigs/controller-runtime/commit/5d27848e390d70cd45583df38ece5e345164b0f3"><code>5d27848</code></a> Revert &quot;🌱 [0.14] Deprecate component configuration package&quot;</li>
<li>Additional commits viewable in <a href="https://github.com/kubernetes-sigs/controller-runtime/compare/v0.14.1...v0.14.5">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=sigs.k8s.io/controller-runtime&package-manager=go_modules&previous-version=0.14.1&new-version=0.14.5)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index ae08778d..a22cb0b1 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -56,7 +56,7 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v3
 
-      - uses: actions/setup-go@v3
+      - uses: actions/setup-go@v4
         with:
           go-version-file: "go.mod"
           cache: true
@@ -96,7 +96,7 @@ jobs:
         uses: docker/setup-buildx-action@v2
 
       - name: Build and export ${{ matrix.image }}
-        uses: docker/build-push-action@v3
+        uses: docker/build-push-action@v4
         with:
           context: .
           tags: quay.io/metallb/${{ matrix.image }}:dev-amd64
diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml
index 86fe71f1..599caf3b 100644
--- a/.github/workflows/publish.yaml
+++ b/.github/workflows/publish.yaml
@@ -19,7 +19,7 @@ jobs:
       - name: Checkout
         uses: actions/checkout@v3
 
-      - uses: actions/setup-go@v3
+      - uses: actions/setup-go@v4
         with:
           go-version-file: "go.mod"
           cache: true
@@ -94,7 +94,7 @@ jobs:
             org.opencontainers.image.description=${{ matrix.image }} for metallb, a network load-balancer implementation for Kubernetes using standard routing protocols
 
       - name: Build and push ${{ matrix.image }}
-        uses: docker/build-push-action@v3
+        uses: docker/build-push-action@v4
         id: build-and-push
         with:
           context: .
diff --git a/charts/metallb/templates/servicemonitor.yaml b/charts/metallb/templates/servicemonitor.yaml
index 5c2ab422..43825b46 100644
--- a/charts/metallb/templates/servicemonitor.yaml
+++ b/charts/metallb/templates/servicemonitor.yaml
@@ -58,14 +58,6 @@ spec:
   selector:
     matchLabels:
       name: {{ template "metallb.fullname" . }}-speaker-monitor-service
-{{- if .Values.prometheus.serviceMonitor.metricRelabelings }}
-  metricRelabelings:
-{{- toYaml .Values.prometheus.serviceMonitor.metricRelabelings | nindent 4 }}
-{{- end }}
-{{- if .Values.prometheus.serviceMonitor.relabelings }}
-  relabelings:
-{{- toYaml .Values.prometheus.serviceMonitor.relabelings | nindent 4 }}
-{{- end }}      
 ---
 apiVersion: v1
 kind: Service
@@ -112,6 +104,14 @@ metadata:
 spec:
   endpoints:
     - port: {{ template "metrics.exposedportname" . }}
+      {{- if .Values.prometheus.serviceMonitor.metricRelabelings }}
+      metricRelabelings:
+      {{- toYaml .Values.prometheus.serviceMonitor.metricRelabelings | nindent 8 }}
+      {{- end -}}
+      {{- if .Values.prometheus.serviceMonitor.relabelings }}
+      relabelings:
+      {{- toYaml .Values.prometheus.serviceMonitor.relabelings | nindent 8 }}
+      {{- end }}
       {{- if .Values.prometheus.serviceMonitor.interval }}
       interval: {{ .Values.prometheus.serviceMonitor.interval }}
       {{- end }}
@@ -131,14 +131,6 @@ spec:
   selector:
     matchLabels:
       name: {{ template "metallb.fullname" . }}-controller-monitor-service
-{{- if .Values.prometheus.serviceMonitor.metricRelabelings }}
-  metricRelabelings:
-{{- toYaml .Values.prometheus.serviceMonitor.metricRelabelings | nindent 4 }}
-{{- end }}
-{{- if .Values.prometheus.serviceMonitor.relabelings }}
-  relabelings:
-{{- toYaml .Values.prometheus.serviceMonitor.relabelings | nindent 4 }}
-{{- end }}      
 ---
 apiVersion: v1
 kind: Service
diff --git a/controller/service.go b/controller/service.go
index f78f6ebc..e6ccdae7 100644
--- a/controller/service.go
+++ b/controller/service.go
@@ -96,6 +96,7 @@ func (c *controller) convergeBalancer(l log.Logger, key string, svc *v1.Service)
 		// otherwise it'll fail and tell us why.
 		if err = c.ips.Assign(key, svc, lbIPs, k8salloc.Ports(svc), k8salloc.SharingKey(svc), k8salloc.BackendKey(svc)); err != nil {
 			level.Info(l).Log("event", "clearAssignment", "error", err, "msg", "current IP not allowed by config, clearing")
+			c.client.Infof(svc, "ClearAssignment", "current IP for %q not allowed by config, will attempt for new IP assignment: %s", key, err)
 			c.clearServiceState(key, svc)
 			lbIPs = []net.IP{}
 		}
diff --git a/go.mod b/go.mod
index 9e65bd42..bbe8cade 100644
--- a/go.mod
+++ b/go.mod
@@ -27,11 +27,11 @@ require (
 	k8s.io/api v0.26.1
 	k8s.io/apiextensions-apiserver v0.26.1
 	k8s.io/apimachinery v0.26.1
-	k8s.io/client-go v1.5.2
+	k8s.io/client-go v0.26.1
 	k8s.io/klog v1.0.0
 	k8s.io/kubernetes v1.26.1
 	k8s.io/pod-security-admission v0.0.0
-	sigs.k8s.io/controller-runtime v0.14.1
+	sigs.k8s.io/controller-runtime v0.14.5
 	sigs.k8s.io/yaml v1.3.0
 )
 
diff --git a/go.sum b/go.sum
index 460a1197..0532d17f 100644
--- a/go.sum
+++ b/go.sum
@@ -1019,8 +1019,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
 rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
 sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33 h1:LYqFq+6Cj2D0gFfrJvL7iElD4ET6ir3VDdhDdTK7rgc=
 sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.33/go.mod h1:soWkSNf2tZC7aMibXEqVhCd73GOY5fJikn8qbdzemB0=
-sigs.k8s.io/controller-runtime v0.14.1 h1:vThDes9pzg0Y+UbCPY3Wj34CGIYPgdmspPm2GIpxpzM=
-sigs.k8s.io/controller-runtime v0.14.1/go.mod h1:GaRkrY8a7UZF0kqFFbUKG7n9ICiTY5T55P1RiE3UZlU=
+sigs.k8s.io/controller-runtime v0.14.5 h1:6xaWFqzT5KuAQ9ufgUaj1G/+C4Y1GRkhrxl+BJ9i+5s=
+sigs.k8s.io/controller-runtime v0.14.5/go.mod h1:WqIdsAY6JBsjfc/CqO0CORmNtoCtE4S6qbPc9s68h+0=
 sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
 sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
 sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
diff --git a/internal/config/config.go b/internal/config/config.go
index dfd2600f..83b6f67d 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -524,8 +524,22 @@ func addressPoolServiceAllocationsFromCR(p metallbv1beta1.IPAddressPool, namespa
 	if p.Spec.AllocateTo == nil {
 		return nil, nil
 	}
-	serviceAllocations := &ServiceAllocation{Priority: p.Spec.AllocateTo.Priority,
-		Namespaces: sets.New(p.Spec.AllocateTo.Namespaces...)}
+	poolNamespaces := sets.Set[string]{}
+	for _, poolNs := range p.Spec.AllocateTo.Namespaces {
+		if poolNamespaces.Has(poolNs) {
+			return nil, errors.New("duplicate definition in namespaces field")
+		}
+		poolNamespaces.Insert(poolNs)
+	}
+	err := validateLabelSelectorDuplicate(p.Spec.AllocateTo.NamespaceSelectors, "namespaceSelectors")
+	if err != nil {
+		return nil, err
+	}
+	err = validateLabelSelectorDuplicate(p.Spec.AllocateTo.ServiceSelectors, "serviceSelectors")
+	if err != nil {
+		return nil, err
+	}
+	serviceAllocations := &ServiceAllocation{Priority: p.Spec.AllocateTo.Priority, Namespaces: poolNamespaces}
 	for i := range p.Spec.AllocateTo.NamespaceSelectors {
 		l, err := metav1.LabelSelectorAsSelector(&p.Spec.AllocateTo.NamespaceSelectors[i])
 		if err != nil {


Test patch:
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index a1a66ba5..37542bbd 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -416,6 +416,70 @@ func TestParse(t *testing.T) {
 			},
 		},
 
+		{
+			desc: "ip address pool with duplicate namespace selection",
+			crs: ClusterResources{
+				Pools: []v1beta1.IPAddressPool{
+					{
+						ObjectMeta: v1.ObjectMeta{
+							Name: "pool1",
+						},
+						Spec: v1beta1.IPAddressPoolSpec{
+							Addresses: []string{
+								"10.20.0.0/16",
+								"10.50.0.0/24",
+							},
+							AvoidBuggyIPs: true,
+							AutoAssign:    pointer.BoolPtr(false),
+							AllocateTo: &v1beta1.ServiceAllocation{Priority: 1,
+								Namespaces: []string{"test-ns1", "test-ns1"}},
+						},
+					},
+				},
+				Namespaces: []corev1.Namespace{
+					{
+						ObjectMeta: v1.ObjectMeta{
+							Name: "test-ns1",
+						},
+					},
+				},
+			},
+		},
+
+		{
+			desc: "ip address pool with duplicate namespace selectors",
+			crs: ClusterResources{
+				Pools: []v1beta1.IPAddressPool{
+					{
+						ObjectMeta: v1.ObjectMeta{
+							Name: "pool1",
+						},
+						Spec: v1beta1.IPAddressPoolSpec{
+							Addresses: []string{
+								"10.20.0.0/16",
+								"10.50.0.0/24",
+							},
+							AvoidBuggyIPs: true,
+							AutoAssign:    pointer.BoolPtr(false),
+							AllocateTo: &v1beta1.ServiceAllocation{
+								Priority: 1,
+								NamespaceSelectors: []v1.LabelSelector{{MatchLabels: map[string]string{"foo": "bar"}},
+									{MatchLabels: map[string]string{"foo": "bar"}}},
+							},
+						},
+					},
+				},
+				Namespaces: []corev1.Namespace{
+					{
+						ObjectMeta: v1.ObjectMeta{
+							Name:   "test-ns1",
+							Labels: map[string]string{"foo": "bar"},
+						},
+					},
+				},
+			},
+		},
+
 		{
 			desc: "ip address pool with service selection",
 			crs: ClusterResources{
@@ -467,6 +531,32 @@ func TestParse(t *testing.T) {
 			},
 		},
 
+		{
+			desc: "ip address pool with duplicate service selection",
+			crs: ClusterResources{
+				Pools: []v1beta1.IPAddressPool{
+					{
+						ObjectMeta: v1.ObjectMeta{
+							Name: "pool1",
+						},
+						Spec: v1beta1.IPAddressPoolSpec{
+							Addresses: []string{
+								"30.0.0.0/8",
+							},
+							AllocateTo: &v1beta1.ServiceAllocation{Priority: 2,
+								ServiceSelectors: []v1.LabelSelector{{MatchExpressions: []metav1.LabelSelectorRequirement{
+									{
+										Key:      "foo",
+										Operator: metav1.LabelSelectorOpIn,
+										Values:   []string{"bar", "bar"},
+									},
+								}}}},
+						},
+					},
+				},
+			},
+		},
+
 		{
 			desc: "ip address pool with namespace and service selection",
 			crs: ClusterResources{