Skip to content

Commit 790e761

Browse files
authored
Merge pull request #744 from rajathagasthya/matching-fields
🏃 Remove usage of deprecated MatchingField list option
2 parents 3e13646 + 4c543fd commit 790e761

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

pkg/cache/cache_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
560560
By("listing Pods with restartPolicyOnFailure")
561561
listObj := &kcorev1.PodList{}
562562
Expect(informer.List(context.Background(), listObj,
563-
client.MatchingField("spec.restartPolicy", "OnFailure"))).To(Succeed())
564-
563+
client.MatchingFields{"spec.restartPolicy": "OnFailure"})).To(Succeed())
565564
By("verifying that the returned pods have correct restart policy")
566565
Expect(listObj.Items).NotTo(BeEmpty())
567566
Expect(listObj.Items).Should(HaveLen(1))
@@ -655,7 +654,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
655654
Kind: "PodList",
656655
})
657656
err = informer.List(context.Background(), listObj,
658-
client.MatchingField("spec.restartPolicy", "OnFailure"))
657+
client.MatchingFields{"spec.restartPolicy": "OnFailure"})
659658
Expect(err).To(Succeed())
660659

661660
By("verifying that the returned pods have correct restart policy")

pkg/client/client_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ var _ = Describe("Client", func() {
17941794
By("listing all Deployments with field metadata.name=deployment-backend")
17951795
deps := &appsv1.DeploymentList{}
17961796
err = cl.List(context.Background(), deps,
1797-
client.MatchingField("metadata.name", "deployment-backend"))
1797+
client.MatchingFields{"metadata.name": "deployment-backend"})
17981798
Expect(err).NotTo(HaveOccurred())
17991799

18001800
By("only the Deployment with the backend field is returned")
@@ -2160,7 +2160,7 @@ var _ = Describe("Client", func() {
21602160
Version: "v1",
21612161
})
21622162
err = cl.List(context.Background(), deps,
2163-
client.MatchingField("metadata.name", "deployment-backend"))
2163+
client.MatchingFields{"metadata.name": "deployment-backend"})
21642164
Expect(err).NotTo(HaveOccurred())
21652165

21662166
By("only the Deployment with the backend field is returned")
@@ -2389,7 +2389,7 @@ var _ = Describe("Client", func() {
23892389
Describe("ListOptions", func() {
23902390
It("should be convertable to metav1.ListOptions", func() {
23912391
lo := (&client.ListOptions{}).ApplyOptions([]client.ListOption{
2392-
client.MatchingField("field1", "bar"),
2392+
client.MatchingFields{"field1": "bar"},
23932393
client.InNamespace("test-namespace"),
23942394
client.MatchingLabels{"foo": "bar"},
23952395
client.Limit(1),
@@ -2412,7 +2412,7 @@ var _ = Describe("Client", func() {
24122412

24132413
It("should be populated by MatchingField", func() {
24142414
lo := &client.ListOptions{}
2415-
client.MatchingField("field1", "bar").ApplyToList(lo)
2415+
client.MatchingFields{"field1": "bar"}.ApplyToList(lo)
24162416
Expect(lo).NotTo(BeNil())
24172417
Expect(lo.FieldSelector.String()).To(Equal("field1=bar"))
24182418
})

pkg/client/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,5 @@ func ExampleFieldIndexer_secretName() {
231231
// elsewhere (e.g. in your reconciler)
232232
mySecretName := "someSecret" // derived from the reconcile.Request, for instance
233233
var podsWithSecrets corev1.PodList
234-
_ = c.List(context.Background(), &podsWithSecrets, client.MatchingField("spec.volumes.secret.secretName", mySecretName))
234+
_ = c.List(context.Background(), &podsWithSecrets, client.MatchingFields{"spec.volumes.secret.secretName": mySecretName})
235235
}

pkg/client/options.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,13 @@ func MatchingField(name, val string) MatchingFields {
411411
return MatchingFields{name: val}
412412
}
413413

414-
// MatchingField filters the list/delete operation on the given field Set
414+
// MatchingFields filters the list/delete operation on the given field Set
415415
// (or index in the case of cached lists).
416416
type MatchingFields fields.Set
417417

418418
func (m MatchingFields) ApplyToList(opts *ListOptions) {
419419
// TODO(directxman12): can we avoid re-serializing this?
420-
sel := fields.SelectorFromSet(fields.Set(m))
420+
sel := fields.Set(m).AsSelector()
421421
opts.FieldSelector = sel
422422
}
423423

0 commit comments

Comments
 (0)