Skip to content

Commit 6902f31

Browse files
authored
Merge pull request kubernetes#71176 from idealhack/fix-unreachable-code-and-golint-warnings
Fix go vet and golint warnings
2 parents 28b965a + 3d9e2f0 commit 6902f31

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,6 @@ staging/src/k8s.io/apimachinery/pkg/util/runtime
515515
staging/src/k8s.io/apimachinery/pkg/util/sets/types
516516
staging/src/k8s.io/apimachinery/pkg/util/strategicpatch
517517
staging/src/k8s.io/apimachinery/pkg/util/uuid
518-
staging/src/k8s.io/apimachinery/pkg/util/validation
519518
staging/src/k8s.io/apimachinery/pkg/util/wait
520519
staging/src/k8s.io/apimachinery/pkg/util/yaml
521520
staging/src/k8s.io/apimachinery/pkg/watch

staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/patch_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ testCases:
282282

283283
func TestSortMergeLists(t *testing.T) {
284284
mergeItemOpenapiSchema := PatchMetaFromOpenAPI{
285-
Schema: sptest.GetSchemaOrDie(fakeMergeItemSchema, "mergeItem"),
285+
Schema: sptest.GetSchemaOrDie(&fakeMergeItemSchema, "mergeItem"),
286286
}
287287
schemas := []LookupPatchMeta{
288288
mergeItemStructSchema,
@@ -673,7 +673,7 @@ mergingList:
673673

674674
func TestCustomStrategicMergePatch(t *testing.T) {
675675
mergeItemOpenapiSchema := PatchMetaFromOpenAPI{
676-
Schema: sptest.GetSchemaOrDie(fakeMergeItemSchema, "mergeItem"),
676+
Schema: sptest.GetSchemaOrDie(&fakeMergeItemSchema, "mergeItem"),
677677
}
678678
schemas := []LookupPatchMeta{
679679
mergeItemStructSchema,
@@ -6029,7 +6029,7 @@ func TestStrategicMergePatch(t *testing.T) {
60296029
"{}", "{}", []byte("<THIS IS NOT A STRUCT>"), mergepatch.ErrBadArgKind(struct{}{}, []byte{}))
60306030

60316031
mergeItemOpenapiSchema := PatchMetaFromOpenAPI{
6032-
Schema: sptest.GetSchemaOrDie(fakeMergeItemSchema, "mergeItem"),
6032+
Schema: sptest.GetSchemaOrDie(&fakeMergeItemSchema, "mergeItem"),
60336033
}
60346034
schemas := []LookupPatchMeta{
60356035
mergeItemStructSchema,
@@ -6413,7 +6413,7 @@ func TestNumberConversion(t *testing.T) {
64136413
}
64146414

64156415
precisionItemOpenapiSchema := PatchMetaFromOpenAPI{
6416-
Schema: sptest.GetSchemaOrDie(fakePrecisionItemSchema, "precisionItem"),
6416+
Schema: sptest.GetSchemaOrDie(&fakePrecisionItemSchema, "precisionItem"),
64176417
}
64186418
precisionItemSchemas := []LookupPatchMeta{
64196419
precisionItemStructSchema,
@@ -6623,7 +6623,7 @@ replacingItem:
66236623

66246624
func TestReplaceWithRawExtension(t *testing.T) {
66256625
mergeItemOpenapiSchema := PatchMetaFromOpenAPI{
6626-
Schema: sptest.GetSchemaOrDie(fakeMergeItemSchema, "mergeItem"),
6626+
Schema: sptest.GetSchemaOrDie(&fakeMergeItemSchema, "mergeItem"),
66276627
}
66286628
schemas := []LookupPatchMeta{
66296629
mergeItemStructSchema,
@@ -6695,7 +6695,7 @@ func TestUnknownField(t *testing.T) {
66956695
}
66966696

66976697
mergeItemOpenapiSchema := PatchMetaFromOpenAPI{
6698-
Schema: sptest.GetSchemaOrDie(fakeMergeItemSchema, "mergeItem"),
6698+
Schema: sptest.GetSchemaOrDie(&fakeMergeItemSchema, "mergeItem"),
66996699
}
67006700
schemas := []LookupPatchMeta{
67016701
mergeItemStructSchema,

staging/src/k8s.io/apimachinery/pkg/util/strategicpatch/testing/openapi.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (f *Fake) OpenAPISchema() (*openapi_v2.Document, error) {
6262
return f.document, f.err
6363
}
6464

65-
func getSchema(f Fake, model string) (openapi.Schema, error) {
65+
func getSchema(f *Fake, model string) (openapi.Schema, error) {
6666
s, err := f.OpenAPISchema()
6767
if err != nil {
6868
return nil, err
@@ -75,7 +75,7 @@ func getSchema(f Fake, model string) (openapi.Schema, error) {
7575
}
7676

7777
// GetSchemaOrDie returns the openapi schema.
78-
func GetSchemaOrDie(f Fake, model string) openapi.Schema {
78+
func GetSchemaOrDie(f *Fake, model string) openapi.Schema {
7979
s, err := getSchema(f, model)
8080
if err != nil {
8181
panic(err)

staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ func IsFullyQualifiedName(fldPath *field.Path, name string) field.ErrorList {
8787

8888
const labelValueFmt string = "(" + qualifiedNameFmt + ")?"
8989
const labelValueErrMsg string = "a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character"
90+
91+
// LabelValueMaxLength is a label's max length
9092
const LabelValueMaxLength int = 63
9193

9294
var labelValueRegexp = regexp.MustCompile("^" + labelValueFmt + "$")
@@ -107,6 +109,8 @@ func IsValidLabelValue(value string) []string {
107109

108110
const dns1123LabelFmt string = "[a-z0-9]([-a-z0-9]*[a-z0-9])?"
109111
const dns1123LabelErrMsg string = "a DNS-1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character"
112+
113+
// DNS1123LabelMaxLength is a label's max length in DNS (RFC 1123)
110114
const DNS1123LabelMaxLength int = 63
111115

112116
var dns1123LabelRegexp = regexp.MustCompile("^" + dns1123LabelFmt + "$")
@@ -126,6 +130,8 @@ func IsDNS1123Label(value string) []string {
126130

127131
const dns1123SubdomainFmt string = dns1123LabelFmt + "(\\." + dns1123LabelFmt + ")*"
128132
const dns1123SubdomainErrorMsg string = "a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character"
133+
134+
// DNS1123SubdomainMaxLength is a subdomain's max length in DNS (RFC 1123)
129135
const DNS1123SubdomainMaxLength int = 253
130136

131137
var dns1123SubdomainRegexp = regexp.MustCompile("^" + dns1123SubdomainFmt + "$")
@@ -145,6 +151,8 @@ func IsDNS1123Subdomain(value string) []string {
145151

146152
const dns1035LabelFmt string = "[a-z]([-a-z0-9]*[a-z0-9])?"
147153
const dns1035LabelErrMsg string = "a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character"
154+
155+
// DNS1035LabelMaxLength is a label's max length in DNS (RFC 1035)
148156
const DNS1035LabelMaxLength int = 63
149157

150158
var dns1035LabelRegexp = regexp.MustCompile("^" + dns1035LabelFmt + "$")
@@ -282,6 +290,7 @@ const percentErrMsg string = "a valid percent string must be a numeric string fo
282290

283291
var percentRegexp = regexp.MustCompile("^" + percentFmt + "$")
284292

293+
// IsValidPercent checks that string is in the form of a percentage
285294
func IsValidPercent(percent string) []string {
286295
if !percentRegexp.MatchString(percent) {
287296
return []string{RegexError(percentErrMsg, percentFmt, "1%", "93%")}
@@ -391,13 +400,13 @@ func hasChDirPrefix(value string) []string {
391400
return errs
392401
}
393402

394-
// IsSocketAddr checks that a string conforms is a valid socket address
403+
// IsValidSocketAddr checks that string represents a valid socket address
395404
// as defined in RFC 789. (e.g 0.0.0.0:10254 or [::]:10254))
396405
func IsValidSocketAddr(value string) []string {
397406
var errs []string
398407
ip, port, err := net.SplitHostPort(value)
399408
if err != nil {
400-
return append(errs, "must be a valid socket address format, (e.g. 0.0.0.0:10254 or [::]:10254)")
409+
errs = append(errs, "must be a valid socket address format, (e.g. 0.0.0.0:10254 or [::]:10254)")
401410
return errs
402411
}
403412
portInt, _ := strconv.Atoi(port)

staging/src/k8s.io/apiserver/pkg/endpoints/handlers/rest_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,6 @@ func TestFinishRequest(t *testing.T) {
884884
timeout: time.Second,
885885
fn: func() (runtime.Object, error) {
886886
panic("my panic")
887-
return nil, nil
888887
},
889888
expectedObj: nil,
890889
expectedErr: nil,
@@ -895,7 +894,6 @@ func TestFinishRequest(t *testing.T) {
895894
timeout: time.Second,
896895
fn: func() (runtime.Object, error) {
897896
panic("my panic")
898-
return nil, nil
899897
},
900898
expectedObj: nil,
901899
expectedErr: nil,

0 commit comments

Comments
 (0)