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
}

pkg/envtest/komega/default_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func TestDefaultList(t *testing.T) {
3838
g.Expect(list.Items).To(HaveLen(1))
3939
depl := exampleDeployment()
4040
g.Expect(list.Items[0]).To(And(
41-
HaveField("ObjectMeta.Name", Equal(depl.Name)),
42-
HaveField("ObjectMeta.Namespace", Equal(depl.Namespace)),
41+
HaveField("ObjectMeta.Name", Equal(depl.ObjectMeta.Name)),
42+
HaveField("ObjectMeta.Namespace", Equal(depl.ObjectMeta.Namespace)),
4343
))
4444
}
4545

pkg/envtest/komega/komega_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ func TestList(t *testing.T) {
6060
g.Expect(list.Items).To(HaveLen(1))
6161
depl := exampleDeployment()
6262
g.Expect(list.Items[0]).To(And(
63-
HaveField("ObjectMeta.Name", Equal(depl.Name)),
64-
HaveField("ObjectMeta.Namespace", Equal(depl.Namespace)),
63+
HaveField("ObjectMeta.Name", Equal(depl.ObjectMeta.Name)),
64+
HaveField("ObjectMeta.Namespace", Equal(depl.ObjectMeta.Namespace)),
6565
))
6666
}
6767

pkg/internal/controller/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,16 @@ func (p *priorityQueueWrapper[request]) AddWithOpts(opts priorityqueue.AddOpts,
403403
for _, item := range items {
404404
switch {
405405
case opts.RateLimited:
406-
p.AddRateLimited(item)
406+
p.TypedRateLimitingInterface.AddRateLimited(item)
407407
case opts.After > 0:
408-
p.AddAfter(item, opts.After)
408+
p.TypedRateLimitingInterface.AddAfter(item, opts.After)
409409
default:
410-
p.Add(item)
410+
p.TypedRateLimitingInterface.Add(item)
411411
}
412412
}
413413
}
414414

415415
func (p *priorityQueueWrapper[request]) GetWithPriority() (request, int, bool) {
416-
item, shutdown := p.Get()
416+
item, shutdown := p.TypedRateLimitingInterface.Get()
417417
return item, 0, shutdown
418418
}

pkg/internal/testing/controlplane/apiserver.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,23 @@ func (s *APIServer) configurePorts() error {
200200

201201
// Secure: SecurePort, SecureServing
202202
if s.SecurePort != 0 {
203-
s.Port = strconv.Itoa(s.SecurePort)
203+
s.SecureServing.Port = strconv.Itoa(s.SecurePort)
204204
// if we don't have an address, try the insecure address, and otherwise
205205
// default to loopback.
206-
if s.Address == "" {
206+
if s.SecureServing.Address == "" {
207207
if s.InsecureServing != nil {
208-
s.Address = s.InsecureServing.Address
208+
s.SecureServing.Address = s.InsecureServing.Address
209209
} else {
210-
s.Address = "127.0.0.1"
210+
s.SecureServing.Address = "127.0.0.1"
211211
}
212212
}
213-
} else if s.Port == "" || s.Address == "" {
213+
} else if s.SecureServing.Port == "" || s.SecureServing.Address == "" {
214214
port, host, err := addr.Suggest("")
215215
if err != nil {
216216
return fmt.Errorf("unable to provision unused secure port: %w", err)
217217
}
218-
s.Port = strconv.Itoa(port)
219-
s.Address = host
218+
s.SecureServing.Port = strconv.Itoa(port)
219+
s.SecureServing.Address = host
220220
s.SecurePort = port
221221
}
222222

@@ -260,12 +260,12 @@ func (s *APIServer) setProcessState() error {
260260
return err
261261
}
262262

263-
if s.Authn == nil {
263+
if s.SecureServing.Authn == nil {
264264
authn, err := NewCertAuthn()
265265
if err != nil {
266266
return err
267267
}
268-
s.Authn = authn
268+
s.SecureServing.Authn = authn
269269
}
270270

271271
if err := s.Authn.Configure(s.CertDir, s.Configure()); err != nil {
@@ -337,11 +337,11 @@ func (s *APIServer) defaultArgs() map[string][]string {
337337
"disable-admission-plugins": {"ServiceAccount"},
338338
"cert-dir": {s.CertDir},
339339
"authorization-mode": {"RBAC"},
340-
"secure-port": {s.Port},
340+
"secure-port": {s.SecureServing.Port},
341341
// NB(directxman12): previously we didn't set the bind address for the secure
342342
// port. It *shouldn't* make a difference unless people are doing something really
343343
// funky, but if you start to get bug reports look here ;-)
344-
"bind-address": {s.Address},
344+
"bind-address": {s.SecureServing.Address},
345345

346346
// required on 1.20+, fine to leave on for <1.20
347347
"service-account-issuer": {s.SecureServing.URL("https", "/").String()},
@@ -391,7 +391,7 @@ func (s *APIServer) populateAPIServerCerts() error {
391391
return err
392392
}
393393

394-
s.CA = ca.CA.CertBytes()
394+
s.SecureServing.CA = ca.CA.CertBytes()
395395

396396
// service account signing files too
397397
saCA, err := certs.NewTinyCA()

pkg/internal/testing/controlplane/plane.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ func (u *AuthenticatedUser) Config() *rest.Config {
168168
if u.cfgIsComplete {
169169
return u.cfg
170170
}
171-
if len(u.plane.APIServer.CA) == 0 {
171+
if len(u.plane.APIServer.SecureServing.CA) == 0 {
172172
panic("the API server has not yet been started, please do that before accessing connection details")
173173
}
174174

175-
u.cfg.CAData = u.plane.APIServer.CA
175+
u.cfg.CAData = u.plane.APIServer.SecureServing.CA
176176
u.cfg.Host = u.plane.APIServer.SecureServing.URL("https", "/").String()
177177
u.cfgIsComplete = true
178178
return u.cfg
@@ -232,14 +232,14 @@ func (u *AuthenticatedUser) Kubectl() (*KubeCtl, error) {
232232
// guaranteed to be callable both before and after Start has been called (but, as noted in the
233233
// AuthenticatedUser docs, the given user objects are only valid after Start has been called).
234234
func (f *ControlPlane) AddUser(user User, baseConfig *rest.Config) (*AuthenticatedUser, error) {
235-
if f.GetAPIServer().Authn == nil {
235+
if f.GetAPIServer().SecureServing.Authn == nil {
236236
return nil, fmt.Errorf("no API server authentication is configured yet. The API server defaults one when Start is called, did you mean to use that?")
237237
}
238238

239239
if baseConfig == nil {
240240
baseConfig = &rest.Config{}
241241
}
242-
cfg, err := f.GetAPIServer().AddUser(user, baseConfig)
242+
cfg, err := f.GetAPIServer().SecureServing.AddUser(user, baseConfig)
243243
if err != nil {
244244
return nil, err
245245
}

pkg/webhook/admission/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,6 @@ func validationResponseFromStatus(allowed bool, status metav1.Status) Response {
119119
// WithWarnings adds the given warnings to the Response.
120120
// If any warnings were already given, they will not be overwritten.
121121
func (r Response) WithWarnings(warnings ...string) Response {
122-
r.Warnings = append(r.Warnings, warnings...)
122+
r.AdmissionResponse.Warnings = append(r.AdmissionResponse.Warnings, warnings...)
123123
return r
124124
}

pkg/webhook/authentication/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func ReviewResponse(authenticated bool, user authenticationv1.UserInfo, err stri
5757
},
5858
}
5959
if len(err) > 0 {
60-
resp.Status.Error = err
60+
resp.TokenReview.Status.Error = err
6161
}
6262
return resp
6363
}

tools/setup-envtest/env/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func (e *Env) PrintInfo(printFmt PrintFormat) {
366366
fmt.Fprintf(e.Out, "Version: %s\n", e.Version)
367367
fmt.Fprintf(e.Out, "OS/Arch: %s\n", e.Platform)
368368
if e.Platform.Hash != nil {
369-
fmt.Fprintf(e.Out, "%s: %s\n", e.Platform.Type, e.Platform.Value)
369+
fmt.Fprintf(e.Out, "%s: %s\n", e.Platform.Hash.Type, e.Platform.Hash.Value)
370370
}
371371
fmt.Fprintf(e.Out, "Path: %s\n", path)
372372
case PrintPath:

0 commit comments

Comments
 (0)