Skip to content

Commit 99feb0d

Browse files
committed
update by codereview
Signed-off-by: dongjiang <dongjiang1989@126.com>
1 parent 6c69d61 commit 99feb0d

File tree

19 files changed

+65
-67
lines changed

19 files changed

+65
-67
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
with:
3333
go-version: ${{ steps.vars.outputs.go_version }}
3434
- name: golangci-lint
35-
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # tag=v7.0.0
35+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0
3636
with:
37-
version: v2.0.2
38-
args: --output.text.print-linter-name=true --output.text.colors=true
37+
version: v2.1.6
38+
args: --output.text.print-linter-name=true --output.text.colors=true --timeout 10m
3939
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ linters:
8888
- name: bool-literal-in-expr
8989
- name: constant-logical-expr
9090
exclusions:
91-
generated: lax
91+
generated: strict
92+
paths:
93+
- zz_generated.*\.go$
94+
- .*conversion.*\.go$
9295
rules:
9396
- linters:
9497
- gosec
@@ -158,16 +161,14 @@ linters:
158161
# If it is decided they will not be addressed they should be moved above this comment.
159162
- path: (.+)\.go$
160163
text: Subprocess launch(ed with variable|ing should be audited)
161-
- path: (.+)\.go$
164+
- linters:
165+
- gosec
166+
path: (.+)\.go$
162167
text: (G204|G104|G307)
163-
- path: (.+)\.go$
164-
text: 'ST1000: at least one file in a package should have a package comment'
165-
paths:
166-
- zz_generated.*\.go$
167-
- .*conversion.*\.go$
168-
- third_party$
169-
- builtin$
170-
- examples$
168+
- linters:
169+
- staticcheck
170+
path: (.+)\.go$
171+
text: (ST1000|QF1008)
171172
issues:
172173
max-issues-per-linter: 0
173174
max-same-issues: 0
@@ -176,10 +177,7 @@ formatters:
176177
- gofmt
177178
- goimports
178179
exclusions:
179-
generated: lax
180+
generated: strict
180181
paths:
181182
- zz_generated.*\.go$
182183
- .*conversion.*\.go$
183-
- third_party$
184-
- builtin$
185-
- examples$

pkg/cache/informer_cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (ic *informerCache) GetInformer(ctx context.Context, obj client.Object, opt
180180

181181
func (ic *informerCache) getInformerForKind(ctx context.Context, gvk schema.GroupVersionKind, obj runtime.Object) (bool, *internal.Cache, error) {
182182
if ic.readerFailOnMissingInformer {
183-
cache, started, ok := ic.Peek(gvk, obj)
183+
cache, started, ok := ic.Informers.Peek(gvk, obj)
184184
if !ok {
185185
return false, nil, &ErrResourceNotCached{GVK: gvk}
186186
}
@@ -197,7 +197,7 @@ func (ic *informerCache) RemoveInformer(_ context.Context, obj client.Object) er
197197
return err
198198
}
199199

200-
ic.Remove(gvk, obj)
200+
ic.Informers.Remove(gvk, obj)
201201
return nil
202202
}
203203

pkg/client/apiutil/restmapper_wb_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,6 @@ type fakeAggregatedDiscoveryClient struct {
209209
}
210210

211211
func (f *fakeAggregatedDiscoveryClient) GroupsAndMaybeResources() (*metav1.APIGroupList, map[schema.GroupVersion]*metav1.APIResourceList, map[schema.GroupVersion]error, error) {
212-
groupList, err := f.ServerGroups()
212+
groupList, err := f.DiscoveryInterface.ServerGroups()
213213
return groupList, nil, nil, err
214214
}

pkg/client/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ type SubResourceUpdateOptions struct {
450450

451451
// ApplyToSubResourceUpdate updates the configuration on the given create options
452452
func (uo *SubResourceUpdateOptions) ApplyToSubResourceUpdate(o *SubResourceUpdateOptions) {
453-
uo.ApplyToUpdate(&o.UpdateOptions)
453+
uo.UpdateOptions.ApplyToUpdate(&o.UpdateOptions)
454454
if uo.SubResourceBody != nil {
455455
o.SubResourceBody = uo.SubResourceBody
456456
}
@@ -507,7 +507,7 @@ func (co *SubResourceCreateOptions) ApplyOptions(opts []SubResourceCreateOption)
507507

508508
// ApplyToSubResourceCreate applies the the configuration on the given create options.
509509
func (co *SubResourceCreateOptions) ApplyToSubResourceCreate(o *SubResourceCreateOptions) {
510-
co.ApplyToCreate(&co.CreateOptions)
510+
co.CreateOptions.ApplyToCreate(&co.CreateOptions)
511511
}
512512

513513
// SubResourcePatchOptions holds all possible configurations for a subresource patch
@@ -528,7 +528,7 @@ func (po *SubResourcePatchOptions) ApplyOptions(opts []SubResourcePatchOption) *
528528

529529
// ApplyToSubResourcePatch applies the configuration on the given patch options.
530530
func (po *SubResourcePatchOptions) ApplyToSubResourcePatch(o *SubResourcePatchOptions) {
531-
po.ApplyToPatch(&o.PatchOptions)
531+
po.PatchOptions.ApplyToPatch(&o.PatchOptions)
532532
if po.SubResourceBody != nil {
533533
o.SubResourceBody = po.SubResourceBody
534534
}

pkg/client/client_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
16981698
dep2Name := dep2.Name
16991699

17001700
By("deleting Deployments")
1701-
err = cl.DeleteAllOf(context.TODO(), dep, client.InNamespace(ns), client.MatchingLabels(dep.Labels))
1701+
err = cl.DeleteAllOf(context.TODO(), dep, client.InNamespace(ns), client.MatchingLabels(dep.ObjectMeta.Labels))
17021702
Expect(err).NotTo(HaveOccurred())
17031703

17041704
By("validating the Deployment no longer exists")
@@ -1804,7 +1804,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
18041804
Kind: "Deployment",
18051805
Version: "v1",
18061806
})
1807-
err = cl.DeleteAllOf(context.TODO(), u, client.InNamespace(ns), client.MatchingLabels(dep.Labels))
1807+
err = cl.DeleteAllOf(context.TODO(), u, client.InNamespace(ns), client.MatchingLabels(dep.ObjectMeta.Labels))
18081808
Expect(err).NotTo(HaveOccurred())
18091809

18101810
By("validating the Deployment no longer exists")
@@ -1884,7 +1884,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC
18841884

18851885
By("deleting Deployments")
18861886
metaObj := metaOnlyFromObj(dep, scheme)
1887-
err = cl.DeleteAllOf(context.TODO(), metaObj, client.InNamespace(ns), client.MatchingLabels(dep.Labels))
1887+
err = cl.DeleteAllOf(context.TODO(), metaObj, client.InNamespace(ns), client.MatchingLabels(dep.ObjectMeta.Labels))
18881888
Expect(err).NotTo(HaveOccurred())
18891889

18901890
By("validating the Deployment no longer exists")

pkg/client/fake/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ func (t versionedTracker) Patch(gvr schema.GroupVersionResource, obj runtime.Obj
411411
return err
412412
}
413413

414-
isStatus := bytes.Contains(debug.Stack(), []byte("sigs.k8s.io/controller-runtime/pkg/client/fake.(*fakeSubResourceClient).statusPatch"))
415414
// We apply patches using a client-go reaction that ends up calling the trackers Patch. As we can't change
416415
// that reaction, we use the callstack to figure out if this originated from the status client.
416+
isStatus := bytes.Contains(debug.Stack(), []byte("sigs.k8s.io/controller-runtime/pkg/client/fake.(*fakeSubResourceClient).statusPatch"))
417417

418418
obj, err = t.updateObject(gvr, obj, ns, isStatus, false, patchOptions.DryRun)
419419
if err != nil {
@@ -444,7 +444,7 @@ func (t versionedTracker) updateObject(gvr schema.GroupVersionResource, obj runt
444444
return nil, err
445445
}
446446

447-
oldObject, err := t.Get(gvr, ns, accessor.GetName())
447+
oldObject, err := t.ObjectTracker.Get(gvr, ns, accessor.GetName())
448448
if err != nil {
449449
// If the resource is not found and the resource allows create on update, issue a
450450
// create instead.
@@ -515,7 +515,7 @@ func (t versionedTracker) updateObject(gvr schema.GroupVersionResource, obj runt
515515
}
516516

517517
if !accessor.GetDeletionTimestamp().IsZero() && len(accessor.GetFinalizers()) == 0 {
518-
return nil, t.Delete(gvr, accessor.GetNamespace(), accessor.GetName(), metav1.DeleteOptions{DryRun: dryRun})
518+
return nil, t.ObjectTracker.Delete(gvr, accessor.GetNamespace(), accessor.GetName(), metav1.DeleteOptions{DryRun: dryRun})
519519
}
520520
return convertFromUnstructuredIfNecessary(t.scheme, obj)
521521
}

pkg/client/metadata_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (mc *metadataClient) DeleteAllOf(ctx context.Context, obj Object, opts ...D
7777
deleteAllOfOpts := DeleteAllOfOptions{}
7878
deleteAllOfOpts.ApplyOptions(opts)
7979

80-
resInt, err := mc.getResourceInterface(metadata.GroupVersionKind(), deleteAllOfOpts.Namespace)
80+
resInt, err := mc.getResourceInterface(metadata.GroupVersionKind(), deleteAllOfOpts.ListOptions.Namespace)
8181
if err != nil {
8282
return err
8383
}

pkg/client/watch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (w *watchingClient) metadataWatch(ctx context.Context, obj *metav1.PartialO
6767

6868
listOpts := w.listOpts(opts...)
6969

70-
resInt, err := w.metadataClient.getResourceInterface(gvk, listOpts.Namespace)
70+
resInt, err := w.client.metadataClient.getResourceInterface(gvk, listOpts.Namespace)
7171
if err != nil {
7272
return nil, err
7373
}
@@ -76,7 +76,7 @@ func (w *watchingClient) metadataWatch(ctx context.Context, obj *metav1.PartialO
7676
}
7777

7878
func (w *watchingClient) unstructuredWatch(ctx context.Context, obj runtime.Unstructured, opts ...ListOption) (watch.Interface, error) {
79-
r, err := w.unstructuredClient.resources.getResource(obj)
79+
r, err := w.client.unstructuredClient.resources.getResource(obj)
8080
if err != nil {
8181
return nil, err
8282
}
@@ -91,7 +91,7 @@ func (w *watchingClient) unstructuredWatch(ctx context.Context, obj runtime.Unst
9191
}
9292

9393
func (w *watchingClient) typedWatch(ctx context.Context, obj ObjectList, opts ...ListOption) (watch.Interface, error) {
94-
r, err := w.typedClient.resources.getResource(obj)
94+
r, err := w.client.typedClient.resources.getResource(obj)
9595
if err != nil {
9696
return nil, err
9797
}

pkg/controller/controllerutil/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func ExampleCreateOrUpdate() {
4141
op, err := controllerutil.CreateOrUpdate(context.TODO(), c, deploy, func() error {
4242
// Deployment selector is immutable so we set this value only if
4343
// a new object is going to be created
44-
if deploy.CreationTimestamp.IsZero() {
44+
if deploy.ObjectMeta.CreationTimestamp.IsZero() {
4545
deploy.Spec.Selector = &metav1.LabelSelector{
4646
MatchLabels: map[string]string{"foo": "bar"},
4747
}

0 commit comments

Comments
 (0)