Fix golang-ci linter errors (#10128)

* Fix golang-ci linter errors

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix gofmt errors

Signed-off-by: z1cheng <imchench@gmail.com>

* Add nolint comment to defaults.Backend in Configuration

Signed-off-by: z1cheng <imchench@gmail.com>

* Add #nosec comment to rand.New func

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix errcheck warnings

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix gofmt check

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix unit tests and comments

Signed-off-by: z1cheng <imchench@gmail.com>

---------

Signed-off-by: z1cheng <imchench@gmail.com>
This commit is contained in:
Chen Chen 2023-07-03 20:50:52 +08:00 committed by GitHub
parent f50431a9f9
commit d44a8e0045
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 206 additions and 162 deletions

View file

@ -67,7 +67,7 @@ func TestHandleAdmission(t *testing.T) {
Checker: failTestChecker{t: t},
}
result, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
_, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
Kind: v1.GroupVersionKind{Group: "", Version: "v1", Kind: "Pod"},
},
@ -76,12 +76,12 @@ func TestHandleAdmission(t *testing.T) {
t.Fatalf("with a non ingress resource, the check should not pass")
}
result, err = adm.HandleAdmission(nil)
_, err = adm.HandleAdmission(nil)
if err == nil {
t.Fatalf("with a nil AdmissionReview request, the check should not pass")
}
result, err = adm.HandleAdmission(&admissionv1.AdmissionReview{
result, err := adm.HandleAdmission(&admissionv1.AdmissionReview{
Request: &admissionv1.AdmissionRequest{
Kind: v1.GroupVersionKind{Group: networking.GroupName, Version: "v1", Kind: "Ingress"},
Object: runtime.RawExtension{
@ -114,7 +114,9 @@ func TestHandleAdmission(t *testing.T) {
err: fmt.Errorf("this is a test error"),
}
adm.HandleAdmission(review)
if _, err := adm.HandleAdmission(review); err != nil {
t.Errorf("unexpected error: %v", err)
}
if review.Response.Allowed {
t.Fatalf("when the checker returns an error, the request should not be allowed")
}
@ -124,7 +126,9 @@ func TestHandleAdmission(t *testing.T) {
err: nil,
}
adm.HandleAdmission(review)
if _, err := adm.HandleAdmission(review); err != nil {
t.Errorf("unexpected error: %v", err)
}
if !review.Response.Allowed {
t.Fatalf("when the checker returns no error, the request should be allowed")
}

View file

@ -31,7 +31,9 @@ var (
)
func init() {
admissionv1.AddToScheme(scheme)
if err := admissionv1.AddToScheme(scheme); err != nil {
klog.ErrorS(err, "Failed to add scheme")
}
}
// AdmissionController checks if an object