Skip to content

Commit 2dae0b0

Browse files
committed
fix review
1 parent 9727ea2 commit 2dae0b0

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

pkg/cache/cache_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,10 +1975,10 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
19751975
Expect(err).NotTo(HaveOccurred())
19761976

19771977
pod := &corev1.Pod{}
1978-
By("indexing pods with namespace before starting")
1979-
fieldName1 := "indexByNamespace"
1978+
By("indexing pods with label before starting")
1979+
fieldName1 := "indexByLabel"
19801980
indexFunc1 := func(obj client.Object) []string {
1981-
return []string{obj.(*corev1.Pod).Namespace}
1981+
return []string{obj.(*corev1.Pod).Labels["common-label"]}
19821982
}
19831983
Expect(informer.IndexField(context.TODO(), pod, fieldName1, indexFunc1)).To(Succeed())
19841984
By("indexing pods with restart policy before starting")
@@ -1995,23 +1995,23 @@ func CacheTest(createCacheFunc func(config *rest.Config, opts cache.Options) (ca
19951995
}()
19961996
Expect(informer.WaitForCacheSync(informerCacheCtx)).To(BeTrue())
19971997

1998-
By("listing pods with namespace index")
1998+
By("listing pods with label index")
19991999
listObj := &corev1.PodList{}
20002000
Expect(informer.List(context.Background(), listObj,
2001-
client.MatchingFields{fieldName1: testNamespaceTwo})).To(Succeed())
2002-
Expect(listObj.Items).To(HaveLen(3))
2001+
client.MatchingFields{fieldName1: "common"})).To(Succeed())
2002+
Expect(listObj.Items).To(HaveLen(2))
20032003

20042004
By("listing pods with restart policy index")
20052005
listObj = &corev1.PodList{}
20062006
Expect(informer.List(context.Background(), listObj,
2007-
client.MatchingFields{fieldName2: string(corev1.RestartPolicyAlways)})).To(Succeed())
2008-
Expect(listObj.Items).To(HaveLen(2))
2007+
client.MatchingFields{fieldName2: string(corev1.RestartPolicyNever)})).To(Succeed())
2008+
Expect(listObj.Items).To(HaveLen(3))
20092009

2010-
By("listing Namespaces with both fixed indexers 1 and 2")
2010+
By("listing pods with both fixed indexers 1 and 2")
20112011
listObj = &corev1.PodList{}
20122012
Expect(informer.List(context.Background(), listObj,
2013-
client.MatchingFields{fieldName1: testNamespaceTwo, fieldName2: string(corev1.RestartPolicyAlways)})).To(Succeed())
2014-
Expect(listObj.Items).To(HaveLen(2))
2013+
client.MatchingFields{fieldName1: "common", fieldName2: string(corev1.RestartPolicyNever)})).To(Succeed())
2014+
Expect(listObj.Items).To(HaveLen(1))
20152015
})
20162016
})
20172017
Context("with unstructured objects", func() {

pkg/cache/internal/cache_reader.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,23 +204,23 @@ func byIndexes(indexer cache.Indexer, requires fields.Requirements, namespace st
204204
if !exist {
205205
return nil, fmt.Errorf("index with name %s does not exist", indexName)
206206
}
207-
tObjs := make([]interface{}, 0, len(objs))
207+
filteredObjects := make([]interface{}, 0, len(objs))
208208
for _, obj := range objs {
209209
vals, err = fn(obj)
210210
if err != nil {
211211
return nil, err
212212
}
213213
for _, val := range vals {
214214
if val == indexedValue {
215-
tObjs = append(tObjs, obj)
215+
filteredObjects = append(filteredObjects, obj)
216216
break
217217
}
218218
}
219219
}
220-
if len(tObjs) == 0 {
220+
if len(filteredObjects) == 0 {
221221
return nil, nil
222222
}
223-
objs = tObjs
223+
objs = filteredObjects
224224
}
225225
return objs, nil
226226
}

pkg/client/fake/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,15 @@ func (c *fakeClient) filterWithFields(list []runtime.Object, gvk schema.GroupVer
604604

605605
filteredList := make([]runtime.Object, 0, len(list))
606606
for _, obj := range list {
607-
ok := true
607+
matches := true
608608
for _, req := range fs.Requirements() {
609609
indexExtractor := indexes[req.Field]
610610
if !c.objMatchesFieldSelector(obj, indexExtractor, req.Value) {
611-
ok = false
611+
matches = false
612612
break
613613
}
614614
}
615-
if ok {
615+
if matches {
616616
filteredList = append(filteredList, obj)
617617
}
618618
}

0 commit comments

Comments
 (0)