diff --git a/pkg/proxy/apis/kubeproxyconfig/BUILD b/pkg/proxy/apis/kubeproxyconfig/BUILD index d9887d9f99..317d8b770c 100644 --- a/pkg/proxy/apis/kubeproxyconfig/BUILD +++ b/pkg/proxy/apis/kubeproxyconfig/BUILD @@ -32,6 +32,7 @@ filegroup( name = "all-srcs", srcs = [ ":package-srcs", + "//pkg/proxy/apis/kubeproxyconfig/fuzzer:all-srcs", "//pkg/proxy/apis/kubeproxyconfig/scheme:all-srcs", "//pkg/proxy/apis/kubeproxyconfig/v1alpha1:all-srcs", "//pkg/proxy/apis/kubeproxyconfig/validation:all-srcs", diff --git a/pkg/proxy/apis/kubeproxyconfig/fuzzer/BUILD b/pkg/proxy/apis/kubeproxyconfig/fuzzer/BUILD new file mode 100644 index 0000000000..04e962bbb2 --- /dev/null +++ b/pkg/proxy/apis/kubeproxyconfig/fuzzer/BUILD @@ -0,0 +1,29 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "go_default_library", + srcs = ["fuzzer.go"], + importpath = "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/fuzzer", + visibility = ["//visibility:public"], + deps = [ + "//pkg/proxy/apis/kubeproxyconfig:go_default_library", + "//pkg/util/pointer:go_default_library", + "//vendor/github.com/google/gofuzz:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], + visibility = ["//visibility:public"], +) diff --git a/pkg/proxy/apis/kubeproxyconfig/fuzzer/fuzzer.go b/pkg/proxy/apis/kubeproxyconfig/fuzzer/fuzzer.go new file mode 100644 index 0000000000..89b0207d95 --- /dev/null +++ b/pkg/proxy/apis/kubeproxyconfig/fuzzer/fuzzer.go @@ -0,0 +1,48 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package fuzzer + +import ( + "fmt" + "time" + + "github.com/google/gofuzz" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" + "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig" + utilpointer "k8s.io/kubernetes/pkg/util/pointer" +) + +// Funcs returns the fuzzer functions for the kube-proxy apis. +func Funcs(codecs runtimeserializer.CodecFactory) []interface{} { + return []interface{}{ + func(obj *kubeproxyconfig.KubeProxyConfiguration, c fuzz.Continue) { + c.FuzzNoCustom(obj) + obj.BindAddress = fmt.Sprintf("%d.%d.%d.%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256)) + obj.Conntrack.MaxPerCore = utilpointer.Int32Ptr(c.Int31()) + obj.Conntrack.Min = utilpointer.Int32Ptr(c.Int31()) + obj.Conntrack.TCPCloseWaitTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour} + obj.Conntrack.TCPEstablishedTimeout = &metav1.Duration{Duration: time.Duration(c.Int63()) * time.Hour} + obj.HealthzBindAddress = fmt.Sprintf("%d.%d.%d.%d:%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(65536)) + obj.IPTables.MasqueradeBit = utilpointer.Int32Ptr(c.Int31()) + obj.MetricsBindAddress = fmt.Sprintf("%d.%d.%d.%d:%d", c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(256), c.Intn(65536)) + obj.OOMScoreAdj = utilpointer.Int32Ptr(c.Int31()) + obj.ResourceContainer = c.RandString() + }, + } +} diff --git a/pkg/proxy/apis/kubeproxyconfig/scheme/BUILD b/pkg/proxy/apis/kubeproxyconfig/scheme/BUILD index 2e5b9e8f20..fe5599faf6 100644 --- a/pkg/proxy/apis/kubeproxyconfig/scheme/BUILD +++ b/pkg/proxy/apis/kubeproxyconfig/scheme/BUILD @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", @@ -26,3 +26,14 @@ filegroup( tags = ["automanaged"], visibility = ["//visibility:public"], ) + +go_test( + name = "go_default_test", + srcs = ["scheme_test.go"], + embed = [":go_default_library"], + importpath = "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/scheme", + deps = [ + "//pkg/proxy/apis/kubeproxyconfig/fuzzer:go_default_library", + "//vendor/k8s.io/apimachinery/pkg/api/testing/roundtrip:go_default_library", + ], +) diff --git a/pkg/proxy/apis/kubeproxyconfig/scheme/scheme_test.go b/pkg/proxy/apis/kubeproxyconfig/scheme/scheme_test.go new file mode 100644 index 0000000000..1a6702d69e --- /dev/null +++ b/pkg/proxy/apis/kubeproxyconfig/scheme/scheme_test.go @@ -0,0 +1,28 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package scheme + +import ( + "testing" + + "k8s.io/apimachinery/pkg/api/testing/roundtrip" + "k8s.io/kubernetes/pkg/proxy/apis/kubeproxyconfig/fuzzer" +) + +func TestRoundTripTypes(t *testing.T) { + roundtrip.RoundTripTestForScheme(t, Scheme, fuzzer.Funcs) +}