Skip to content

Commit aa084d4

Browse files
authored
Merge pull request kubernetes#92491 from BenTheElder/fuzz-only-test
compile out gofuzz from prod binaries
2 parents 67a7509 + 42acb51 commit aa084d4

File tree

9 files changed

+124
-47
lines changed

9 files changed

+124
-47
lines changed

hack/lib/golang.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ kube::golang::build_binaries() {
793793

794794
# extract tags if any specified in GOFLAGS
795795
# shellcheck disable=SC2001
796-
gotags="selinux,$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')"
796+
gotags="selinux,notest,$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')"
797797

798798
local -a targets=()
799799
local arg

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ go_library(
4747
"labels.go",
4848
"meta.go",
4949
"micro_time.go",
50+
"micro_time_fuzz.go",
5051
"micro_time_proto.go",
5152
"register.go",
5253
"time.go",
54+
"time_fuzz.go",
5355
"time_proto.go",
5456
"types.go",
5557
"types_swagger_doc_generated.go",

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/micro_time.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package v1
1919
import (
2020
"encoding/json"
2121
"time"
22-
23-
"github.com/google/gofuzz"
2422
)
2523

2624
const RFC3339Micro = "2006-01-02T15:04:05.000000Z07:00"
@@ -181,16 +179,3 @@ func (t MicroTime) MarshalQueryParameter() (string, error) {
181179

182180
return t.UTC().Format(RFC3339Micro), nil
183181
}
184-
185-
// Fuzz satisfies fuzz.Interface.
186-
func (t *MicroTime) Fuzz(c fuzz.Continue) {
187-
if t == nil {
188-
return
189-
}
190-
// Allow for about 1000 years of randomness. Accurate to a tenth of
191-
// micro second. Leave off nanoseconds because JSON doesn't
192-
// represent them so they can't round-trip properly.
193-
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 1000*c.Rand.Int63n(1000000))
194-
}
195-
196-
var _ fuzz.Interface = &MicroTime{}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// +build !notest
2+
3+
/*
4+
Copyright 2020 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package v1
20+
21+
import (
22+
"time"
23+
24+
fuzz "github.com/google/gofuzz"
25+
)
26+
27+
// Fuzz satisfies fuzz.Interface.
28+
func (t *MicroTime) Fuzz(c fuzz.Continue) {
29+
if t == nil {
30+
return
31+
}
32+
// Allow for about 1000 years of randomness. Accurate to a tenth of
33+
// micro second. Leave off nanoseconds because JSON doesn't
34+
// represent them so they can't round-trip properly.
35+
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 1000*c.Rand.Int63n(1000000))
36+
}
37+
38+
// ensure MicroTime implements fuzz.Interface
39+
var _ fuzz.Interface = &MicroTime{}

staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/time.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ package v1
1919
import (
2020
"encoding/json"
2121
"time"
22-
23-
fuzz "github.com/google/gofuzz"
2422
)
2523

2624
// Time is a wrapper around time.Time which supports correct
@@ -182,16 +180,3 @@ func (t Time) MarshalQueryParameter() (string, error) {
182180

183181
return t.UTC().Format(time.RFC3339), nil
184182
}
185-
186-
// Fuzz satisfies fuzz.Interface.
187-
func (t *Time) Fuzz(c fuzz.Continue) {
188-
if t == nil {
189-
return
190-
}
191-
// Allow for about 1000 years of randomness. Leave off nanoseconds
192-
// because JSON doesn't represent them so they can't round-trip
193-
// properly.
194-
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 0)
195-
}
196-
197-
var _ fuzz.Interface = &Time{}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// +build !notest
2+
3+
/*
4+
Copyright 2020 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package v1
20+
21+
import (
22+
"time"
23+
24+
fuzz "github.com/google/gofuzz"
25+
)
26+
27+
// Fuzz satisfies fuzz.Interface.
28+
func (t *Time) Fuzz(c fuzz.Continue) {
29+
if t == nil {
30+
return
31+
}
32+
// Allow for about 1000 years of randomness. Leave off nanoseconds
33+
// because JSON doesn't represent them so they can't round-trip
34+
// properly.
35+
t.Time = time.Unix(c.Rand.Int63n(1000*365*24*60*60), 0)
36+
}
37+
38+
// ensure Time implements fuzz.Interface
39+
var _ fuzz.Interface = &Time{}

staging/src/k8s.io/apimachinery/pkg/util/intstr/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ go_library(
1717
name = "go_default_library",
1818
srcs = [
1919
"generated.pb.go",
20+
"instr_fuzz.go",
2021
"intstr.go",
2122
],
2223
importmap = "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/intstr",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// +build !notest
2+
3+
/*
4+
Copyright 2020 The Kubernetes Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package intstr
20+
21+
import (
22+
fuzz "github.com/google/gofuzz"
23+
)
24+
25+
// Fuzz satisfies fuzz.Interface
26+
func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
27+
if intstr == nil {
28+
return
29+
}
30+
if c.RandBool() {
31+
intstr.Type = Int
32+
c.Fuzz(&intstr.IntVal)
33+
intstr.StrVal = ""
34+
} else {
35+
intstr.Type = String
36+
intstr.IntVal = 0
37+
c.Fuzz(&intstr.StrVal)
38+
}
39+
}
40+
41+
// ensure IntOrString implements fuzz.Interface
42+
var _ fuzz.Interface = &IntOrString{}

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"strconv"
2626
"strings"
2727

28-
"github.com/google/gofuzz"
2928
"k8s.io/klog/v2"
3029
)
3130

@@ -129,21 +128,6 @@ func (IntOrString) OpenAPISchemaType() []string { return []string{"string"} }
129128
// the OpenAPI spec of this type.
130129
func (IntOrString) OpenAPISchemaFormat() string { return "int-or-string" }
131130

132-
func (intstr *IntOrString) Fuzz(c fuzz.Continue) {
133-
if intstr == nil {
134-
return
135-
}
136-
if c.RandBool() {
137-
intstr.Type = Int
138-
c.Fuzz(&intstr.IntVal)
139-
intstr.StrVal = ""
140-
} else {
141-
intstr.Type = String
142-
intstr.IntVal = 0
143-
c.Fuzz(&intstr.StrVal)
144-
}
145-
}
146-
147131
func ValueOrDefault(intOrPercent *IntOrString, defaultValue IntOrString) *IntOrString {
148132
if intOrPercent == nil {
149133
return &defaultValue

0 commit comments

Comments
 (0)