Skip to content

Commit e95fbce

Browse files
authored
Merge pull request #2708 from vincepri/golangci-lint1562
🌱 Update golangci-lint to v1.56.2
2 parents cb5107b + 2e225f6 commit e95fbce

File tree

5 files changed

+40
-50
lines changed

5 files changed

+40
-50
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ jobs:
2222
- name: golangci-lint
2323
uses: golangci/golangci-lint-action@v4
2424
with:
25-
version: v1.54.0
25+
version: v1.56.2
2626
working-directory: ${{matrix.working-directory}}

pkg/builder/webhook_test.go

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ import (
4242
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
4343
)
4444

45+
const (
46+
admissionReviewGV = `{
47+
"kind":"AdmissionReview",
48+
"apiVersion":"admission.k8s.io/`
49+
50+
svcBaseAddr = "http://svc-name.svc-ns.svc"
51+
)
52+
4553
var _ = Describe("webhook", func() {
4654
Describe("New", func() {
4755
Context("v1 AdmissionReview", func() {
@@ -89,9 +97,7 @@ func runTests(admissionReviewVersion string) {
8997
svr := m.GetWebhookServer()
9098
ExpectWithOffset(1, svr).NotTo(BeNil())
9199

92-
reader := strings.NewReader(`{
93-
"kind":"AdmissionReview",
94-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
100+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
95101
"request":{
96102
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
97103
"kind":{
@@ -122,7 +128,7 @@ func runTests(admissionReviewVersion string) {
122128

123129
By("sending a request to a mutating webhook path")
124130
path := generateMutatePath(testDefaulterGVK)
125-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
131+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
126132
req.Header.Add("Content-Type", "application/json")
127133
w := httptest.NewRecorder()
128134
svr.WebhookMux().ServeHTTP(w, req)
@@ -136,7 +142,7 @@ func runTests(admissionReviewVersion string) {
136142
path = generateValidatePath(testDefaulterGVK)
137143
_, err = reader.Seek(0, 0)
138144
ExpectWithOffset(1, err).NotTo(HaveOccurred())
139-
req = httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
145+
req = httptest.NewRequest("POST", svcBaseAddr+path, reader)
140146
req.Header.Add("Content-Type", "application/json")
141147
w = httptest.NewRecorder()
142148
svr.WebhookMux().ServeHTTP(w, req)
@@ -162,9 +168,7 @@ func runTests(admissionReviewVersion string) {
162168
svr := m.GetWebhookServer()
163169
ExpectWithOffset(1, svr).NotTo(BeNil())
164170

165-
reader := strings.NewReader(`{
166-
"kind":"AdmissionReview",
167-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
171+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
168172
"request":{
169173
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
170174
"kind":{
@@ -196,7 +200,7 @@ func runTests(admissionReviewVersion string) {
196200

197201
By("sending a request to a mutating webhook path")
198202
path := generateMutatePath(testDefaulterGVK)
199-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
203+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
200204
req.Header.Add("Content-Type", "application/json")
201205
w := httptest.NewRecorder()
202206
svr.WebhookMux().ServeHTTP(w, req)
@@ -229,9 +233,7 @@ func runTests(admissionReviewVersion string) {
229233
svr := m.GetWebhookServer()
230234
ExpectWithOffset(1, svr).NotTo(BeNil())
231235

232-
reader := strings.NewReader(`{
233-
"kind":"AdmissionReview",
234-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
236+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
235237
"request":{
236238
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
237239
"kind":{
@@ -263,7 +265,7 @@ func runTests(admissionReviewVersion string) {
263265

264266
By("sending a request to a mutating webhook path")
265267
path := generateMutatePath(testDefaulterGVK)
266-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
268+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
267269
req.Header.Add("Content-Type", "application/json")
268270
w := httptest.NewRecorder()
269271
svr.WebhookMux().ServeHTTP(w, req)
@@ -278,7 +280,7 @@ func runTests(admissionReviewVersion string) {
278280
path = generateValidatePath(testDefaulterGVK)
279281
_, err = reader.Seek(0, 0)
280282
ExpectWithOffset(1, err).NotTo(HaveOccurred())
281-
req = httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
283+
req = httptest.NewRequest("POST", svcBaseAddr+path, reader)
282284
req.Header.Add("Content-Type", "application/json")
283285
w = httptest.NewRecorder()
284286
svr.WebhookMux().ServeHTTP(w, req)
@@ -303,9 +305,7 @@ func runTests(admissionReviewVersion string) {
303305
svr := m.GetWebhookServer()
304306
ExpectWithOffset(1, svr).NotTo(BeNil())
305307

306-
reader := strings.NewReader(`{
307-
"kind":"AdmissionReview",
308-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
308+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
309309
"request":{
310310
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
311311
"kind":{
@@ -338,7 +338,7 @@ func runTests(admissionReviewVersion string) {
338338

339339
By("sending a request to a mutating webhook path that doesn't exist")
340340
path := generateMutatePath(testValidatorGVK)
341-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
341+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
342342
req.Header.Add("Content-Type", "application/json")
343343
w := httptest.NewRecorder()
344344
svr.WebhookMux().ServeHTTP(w, req)
@@ -348,7 +348,7 @@ func runTests(admissionReviewVersion string) {
348348
path = generateValidatePath(testValidatorGVK)
349349
_, err = reader.Seek(0, 0)
350350
ExpectWithOffset(1, err).NotTo(HaveOccurred())
351-
req = httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
351+
req = httptest.NewRequest("POST", svcBaseAddr+path, reader)
352352
req.Header.Add("Content-Type", "application/json")
353353
w = httptest.NewRecorder()
354354
svr.WebhookMux().ServeHTTP(w, req)
@@ -377,9 +377,7 @@ func runTests(admissionReviewVersion string) {
377377
svr := m.GetWebhookServer()
378378
ExpectWithOffset(1, svr).NotTo(BeNil())
379379

380-
reader := strings.NewReader(`{
381-
"kind":"AdmissionReview",
382-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
380+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
383381
"request":{
384382
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
385383
"kind":{
@@ -412,7 +410,7 @@ func runTests(admissionReviewVersion string) {
412410
path := generateValidatePath(testValidatorGVK)
413411
_, err = reader.Seek(0, 0)
414412
ExpectWithOffset(1, err).NotTo(HaveOccurred())
415-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
413+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
416414
req.Header.Add("Content-Type", "application/json")
417415
w := httptest.NewRecorder()
418416
svr.WebhookMux().ServeHTTP(w, req)
@@ -445,9 +443,7 @@ func runTests(admissionReviewVersion string) {
445443
svr := m.GetWebhookServer()
446444
ExpectWithOffset(1, svr).NotTo(BeNil())
447445

448-
reader := strings.NewReader(`{
449-
"kind":"AdmissionReview",
450-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
446+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
451447
"request":{
452448
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
453449
"kind":{
@@ -481,7 +477,7 @@ func runTests(admissionReviewVersion string) {
481477

482478
By("sending a request to a mutating webhook path that doesn't exist")
483479
path := generateMutatePath(testValidatorGVK)
484-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
480+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
485481
req.Header.Add("Content-Type", "application/json")
486482
w := httptest.NewRecorder()
487483
svr.WebhookMux().ServeHTTP(w, req)
@@ -491,7 +487,7 @@ func runTests(admissionReviewVersion string) {
491487
path = generateValidatePath(testValidatorGVK)
492488
_, err = reader.Seek(0, 0)
493489
ExpectWithOffset(1, err).NotTo(HaveOccurred())
494-
req = httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
490+
req = httptest.NewRequest("POST", svcBaseAddr+path, reader)
495491
req.Header.Add("Content-Type", "application/json")
496492
w = httptest.NewRecorder()
497493
svr.WebhookMux().ServeHTTP(w, req)
@@ -520,9 +516,7 @@ func runTests(admissionReviewVersion string) {
520516
svr := m.GetWebhookServer()
521517
ExpectWithOffset(1, svr).NotTo(BeNil())
522518

523-
reader := strings.NewReader(`{
524-
"kind":"AdmissionReview",
525-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
519+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
526520
"request":{
527521
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
528522
"kind":{
@@ -553,7 +547,7 @@ func runTests(admissionReviewVersion string) {
553547

554548
By("sending a request to a mutating webhook path")
555549
path := generateMutatePath(testDefaultValidatorGVK)
556-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
550+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
557551
req.Header.Add("Content-Type", "application/json")
558552
w := httptest.NewRecorder()
559553
svr.WebhookMux().ServeHTTP(w, req)
@@ -567,7 +561,7 @@ func runTests(admissionReviewVersion string) {
567561
path = generateValidatePath(testDefaultValidatorGVK)
568562
_, err = reader.Seek(0, 0)
569563
ExpectWithOffset(1, err).NotTo(HaveOccurred())
570-
req = httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
564+
req = httptest.NewRequest("POST", svcBaseAddr+path, reader)
571565
req.Header.Add("Content-Type", "application/json")
572566
w = httptest.NewRecorder()
573567
svr.WebhookMux().ServeHTTP(w, req)
@@ -597,9 +591,7 @@ func runTests(admissionReviewVersion string) {
597591
svr := m.GetWebhookServer()
598592
ExpectWithOffset(1, svr).NotTo(BeNil())
599593

600-
reader := strings.NewReader(`{
601-
"kind":"AdmissionReview",
602-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
594+
reader := strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
603595
"request":{
604596
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
605597
"kind":{
@@ -629,7 +621,7 @@ func runTests(admissionReviewVersion string) {
629621

630622
By("sending a request to a validating webhook path to check for failed delete")
631623
path := generateValidatePath(testValidatorGVK)
632-
req := httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
624+
req := httptest.NewRequest("POST", svcBaseAddr+path, reader)
633625
req.Header.Add("Content-Type", "application/json")
634626
w := httptest.NewRecorder()
635627
svr.WebhookMux().ServeHTTP(w, req)
@@ -638,9 +630,7 @@ func runTests(admissionReviewVersion string) {
638630
ExpectWithOffset(1, w.Body).To(ContainSubstring(`"allowed":false`))
639631
ExpectWithOffset(1, w.Body).To(ContainSubstring(`"code":403`))
640632

641-
reader = strings.NewReader(`{
642-
"kind":"AdmissionReview",
643-
"apiVersion":"admission.k8s.io/` + admissionReviewVersion + `",
633+
reader = strings.NewReader(admissionReviewGV + admissionReviewVersion + `",
644634
"request":{
645635
"uid":"07e52e8d-4513-11e9-a716-42010a800270",
646636
"kind":{
@@ -663,7 +653,7 @@ func runTests(admissionReviewVersion string) {
663653
}`)
664654
By("sending a request to a validating webhook path with correct request")
665655
path = generateValidatePath(testValidatorGVK)
666-
req = httptest.NewRequest("POST", "http://svc-name.svc-ns.svc"+path, reader)
656+
req = httptest.NewRequest("POST", svcBaseAddr+path, reader)
667657
req.Header.Add("Content-Type", "application/json")
668658
w = httptest.NewRecorder()
669659
svr.WebhookMux().ServeHTTP(w, req)

pkg/internal/testing/certs/tinyca_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ var _ = Describe("TinyCA", func() {
4747
})
4848

4949
It("should be usable for signing & verifying", func() {
50-
Expect(ca.CA.Cert.KeyUsage&x509.KeyUsageCertSign).NotTo(Equal(0), "should be usable for cert signing")
51-
Expect(ca.CA.Cert.KeyUsage&x509.KeyUsageDigitalSignature).NotTo(Equal(0), "should be usable for signature verifying")
50+
Expect(ca.CA.Cert.KeyUsage&x509.KeyUsageCertSign).NotTo(BeEquivalentTo(0), "should be usable for cert signing")
51+
Expect(ca.CA.Cert.KeyUsage&x509.KeyUsageDigitalSignature).NotTo(BeEquivalentTo(0), "should be usable for signature verifying")
5252
})
5353
})
5454

@@ -141,8 +141,8 @@ var _ = Describe("TinyCA", func() {
141141
cert, err := ca.NewServingCert()
142142
Expect(err).NotTo(HaveOccurred(), "should be able to generate a serving cert")
143143

144-
Expect(cert.Cert.KeyUsage&x509.KeyUsageKeyEncipherment).NotTo(Equal(0), "should be usable for key enciphering")
145-
Expect(cert.Cert.KeyUsage&x509.KeyUsageDigitalSignature).NotTo(Equal(0), "should be usable for signature verifying")
144+
Expect(cert.Cert.KeyUsage&x509.KeyUsageKeyEncipherment).NotTo(BeEquivalentTo(0), "should be usable for key enciphering")
145+
Expect(cert.Cert.KeyUsage&x509.KeyUsageDigitalSignature).NotTo(BeEquivalentTo(0), "should be usable for signature verifying")
146146
Expect(cert.Cert.ExtKeyUsage).To(ContainElement(x509.ExtKeyUsageServerAuth), "should be usable for server auth")
147147

148148
})
@@ -172,8 +172,8 @@ var _ = Describe("TinyCA", func() {
172172
})
173173

174174
It("should be usable for client auth, verifying, and enciphering", func() {
175-
Expect(cert.Cert.KeyUsage&x509.KeyUsageKeyEncipherment).NotTo(Equal(0), "should be usable for key enciphering")
176-
Expect(cert.Cert.KeyUsage&x509.KeyUsageDigitalSignature).NotTo(Equal(0), "should be usable for signature verifying")
175+
Expect(cert.Cert.KeyUsage&x509.KeyUsageKeyEncipherment).NotTo(BeEquivalentTo(0), "should be usable for key enciphering")
176+
Expect(cert.Cert.KeyUsage&x509.KeyUsageDigitalSignature).NotTo(BeEquivalentTo(0), "should be usable for signature verifying")
177177
Expect(cert.Cert.ExtKeyUsage).To(ContainElement(x509.ExtKeyUsageClientAuth), "should be usable for client auth")
178178
})
179179

pkg/internal/testing/controlplane/apiserver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ var _ = Describe("APIServer", func() {
128128

129129
Context("when SecureServing is not set", func() {
130130
It("should be defaulted with a random port", func() {
131-
Expect(server.Port).NotTo(Equal(0))
131+
Expect(server.Port).NotTo(BeEquivalentTo(0))
132132
})
133133
})
134134
})

pkg/manager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ var _ = Describe("manger.Manager", func() {
254254
Expect(m.WebhookServer.(*webhook.DefaultServer).Options.Port).To(Equal(8080))
255255
Expect(m.WebhookServer.(*webhook.DefaultServer).Options.Host).To(Equal("example.com"))
256256
Expect(m.WebhookServer.(*webhook.DefaultServer).Options.CertDir).To(Equal("/pki"))
257-
Expect(m.WebhookServer.(*webhook.DefaultServer).Options.TLSOpts).To(Equal(optionsTlSOptsFuncs))
257+
Expect(m.WebhookServer.(*webhook.DefaultServer).Options.TLSOpts).To(BeEquivalentTo(optionsTlSOptsFuncs))
258258
})
259259

260260
It("should lazily initialize a webhook server if needed", func() {

0 commit comments

Comments
 (0)