Skip to content

🏃 Remove usage of deprecated MatchingField list option #744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pkg/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
By("listing Pods with restartPolicyOnFailure")
listObj := &kcorev1.PodList{}
Expect(informer.List(context.Background(), listObj,
client.MatchingField("spec.restartPolicy", "OnFailure"))).To(Succeed())

client.MatchingFields{"spec.restartPolicy": "OnFailure"})).To(Succeed())
By("verifying that the returned pods have correct restart policy")
Expect(listObj.Items).NotTo(BeEmpty())
Expect(listObj.Items).Should(HaveLen(1))
Expand Down Expand Up @@ -655,7 +654,7 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
Kind: "PodList",
})
err = informer.List(context.Background(), listObj,
client.MatchingField("spec.restartPolicy", "OnFailure"))
client.MatchingFields{"spec.restartPolicy": "OnFailure"})
Expect(err).To(Succeed())

By("verifying that the returned pods have correct restart policy")
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1794,7 +1794,7 @@ var _ = Describe("Client", func() {
By("listing all Deployments with field metadata.name=deployment-backend")
deps := &appsv1.DeploymentList{}
err = cl.List(context.Background(), deps,
client.MatchingField("metadata.name", "deployment-backend"))
client.MatchingFields{"metadata.name": "deployment-backend"})
Expect(err).NotTo(HaveOccurred())

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

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

It("should be populated by MatchingField", func() {
lo := &client.ListOptions{}
client.MatchingField("field1", "bar").ApplyToList(lo)
client.MatchingFields{"field1": "bar"}.ApplyToList(lo)
Expect(lo).NotTo(BeNil())
Expect(lo.FieldSelector.String()).To(Equal("field1=bar"))
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,5 @@ func ExampleFieldIndexer_secretName() {
// elsewhere (e.g. in your reconciler)
mySecretName := "someSecret" // derived from the reconcile.Request, for instance
var podsWithSecrets corev1.PodList
_ = c.List(context.Background(), &podsWithSecrets, client.MatchingField("spec.volumes.secret.secretName", mySecretName))
_ = c.List(context.Background(), &podsWithSecrets, client.MatchingFields{"spec.volumes.secret.secretName": mySecretName})
}
4 changes: 2 additions & 2 deletions pkg/client/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ func MatchingField(name, val string) MatchingFields {
return MatchingFields{name: val}
}

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

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

Expand Down