Compare commits

...

46 Commits

Author SHA1 Message Date
Kubernetes Publisher
21300e3e11 sync(k8s.io/kubernetes) 313fd317f96265658831a576fafdd6ed85aaf428 2017-07-05 23:56:09 +00:00
Anthony Yeh
1bf6994c7c Kubernetes version v1.6.8-beta.0 file updates
Kubernetes-commit: 313fd317f96265658831a576fafdd6ed85aaf428
2017-07-05 23:56:09 +00:00
Anthony Yeh
c32e4dfc5d Kubernetes version v1.6.7 file updates
Kubernetes-commit: 095136c3078ccf887b9034b7ce598a0a1faff769
2017-07-05 23:56:08 +00:00
Kubernetes Publisher
99c1992389 sync(k8s.io/kubernetes) fdeb9d4426ee71892e95421fbe3abcca94c66ee4 2017-06-28 00:11:22 +00:00
Tomas Nozicka
e28ebe6126 Fix standardFinalizers - add missing metav1.FinalizerDeleteDependents
Kubernetes-commit: fdeb9d4426ee71892e95421fbe3abcca94c66ee4
2017-06-28 00:11:21 +00:00
Kubernetes Publisher
18fe241720 sync(k8s.io/kubernetes) 7c3906a4eccd5a7cad245de0bd65337927a60bef 2017-06-16 22:08:55 +00:00
Anthony Yeh
936b386bc7 Kubernetes version v1.6.7-beta.0 file updates
Kubernetes-commit: 7c3906a4eccd5a7cad245de0bd65337927a60bef
2017-06-16 22:08:55 +00:00
Anthony Yeh
836838f447 Kubernetes version v1.6.6 file updates
Kubernetes-commit: 7fa1c1756d8bc963f1a389f4a6937dc71f08ada2
2017-06-16 22:08:55 +00:00
Kubernetes Publisher
a8d5b7ee85 sync(k8s.io/kubernetes) b90e25a03b263752154c68fc3c09ef9921cf1dae 2017-06-14 22:09:51 +00:00
Anthony Yeh
9e35ef7520 Kubernetes version v1.6.6-beta.0 file updates
Kubernetes-commit: b90e25a03b263752154c68fc3c09ef9921cf1dae
2017-06-14 22:09:51 +00:00
Anthony Yeh
7a26c9599d Kubernetes version v1.6.5 file updates
Kubernetes-commit: 490c6f13df1cb6612e0993c4c14f2ff90f8cdbf3
2017-06-14 22:09:51 +00:00
Kubernetes Publisher
14ff8c69a1 sync: resync vendor folder 2017-06-13 20:44:21 +00:00
Kubernetes Publisher
117378eef3 sync(k8s.io/kubernetes) f222688fc46617553e9e3982b7e2081e746de68e 2017-05-17 17:25:19 +00:00
Anthony Yeh
35b898845e update-all.sh
Kubernetes-commit: f222688fc46617553e9e3982b7e2081e746de68e
2017-05-17 17:25:18 +00:00
Kubernetes Publisher
1e2deb5008 sync: resync vendor folder 2017-05-13 17:25:27 +00:00
Kubernetes Publisher
9679848f28 sync(k8s.io/kubernetes) 4b11d9e95a50535787f03d8afc88ee0364104ffb 2017-05-13 17:25:07 +00:00
Anthony Yeh
e2272dfdf5 update-all.sh
Kubernetes-commit: 4b11d9e95a50535787f03d8afc88ee0364104ffb
2017-05-13 17:25:07 +00:00
Anthony Yeh
bf7e376fe1 update-all.sh
Kubernetes-commit: 60f87370780f19f05d25b8b8fdba23a200396954
2017-05-13 17:25:07 +00:00
Kubernetes Publisher
eb79b53964 sync: reset Godeps.json 2017-05-13 17:25:07 +00:00
Kubernetes Publisher
2622726a58 sync: resync vendor folder 2017-05-12 17:27:08 +00:00
Kubernetes Publisher
f13d806547 sync(k8s.io/kubernetes) 9ac920be27d1e8d6dc0cd61028612eb0de9028c5 2017-05-12 17:26:52 +00:00
gmarek
aafe6e0f59 Make Daemons tolerate NoExecute taints correctly
Kubernetes-commit: 9ac920be27d1e8d6dc0cd61028612eb0de9028c5
2017-05-12 17:26:51 +00:00
Kubernetes Publisher
66e13efc6b sync: resync vendor folder 2017-04-28 20:34:02 +00:00
Kubernetes Publisher
1e64882b98 sync(k8s.io/kubernetes) bd54bbb8b64d8e27f67c37c84d9e14b57b599813 2017-04-25 20:33:24 +00:00
Jordan Liggitt
a0dd3f74e8 Stop treating in-cluster-config namespace as an override
Kubernetes-commit: bd54bbb8b64d8e27f67c37c84d9e14b57b599813
2017-04-25 20:33:24 +00:00
Jordan Liggitt
e8d7cc3840 Explicit namespace from kubeconfig should override in-cluster config
Kubernetes-commit: 9e07463e55108ef609df6178dc97a4f113d35b9a
2017-04-25 20:33:24 +00:00
Kubernetes Publisher
df2bb22315 sync(k8s.io/kubernetes) 0199cd4779cb0565e56974d7293cd034936e683e 2017-04-20 20:32:57 +00:00
Anthony Yeh
06387e8a4d update-all.sh.
Kubernetes-commit: 0199cd4779cb0565e56974d7293cd034936e683e
2017-04-20 20:32:57 +00:00
Kubernetes Publisher
d257309ce8 sync(k8s.io/kubernetes) a26452b2da054b1326eb809e08b6ae8a6096e758 2017-04-18 20:33:08 +00:00
Jeffrey Regan
845ec4da7b Patchable version of mainline PR #44423 for 1.6 release branch.
The original full PR
  https://github.com/kubernetes/kubernetes/pull/44423
came after a large PR
  https://github.com/kubernetes/kubernetes/pull/40777
that split /vendor/BUILD into hundreds of BUILD files.

Thus PR 44423's version of rest/BUILD does not exist
in the 1.6 release branch, and had to be tweaked here.

Kubernetes-commit: a26452b2da054b1326eb809e08b6ae8a6096e758
2017-04-18 20:33:08 +00:00
Kubernetes Publisher
35748ed7f1 sync(k8s.io/kubernetes) 26104036d1239297f6b63dab886afb4ec2bb59b4 2017-04-14 20:33:01 +00:00
Maciej Szulik
e216037602 Staging client changes for defaults updates
Kubernetes-commit: 26104036d1239297f6b63dab886afb4ec2bb59b4
2017-04-14 20:33:01 +00:00
Kubernetes Publisher
fab6dd31b8 sync: resync vendor folder 2017-04-07 20:33:04 +00:00
Kubernetes Publisher
d55bff0e8b sync(k8s.io/kubernetes) 5a18a32a33762315da75ebe5ed97c073ce925e7b 2017-04-04 20:32:46 +00:00
Anthony Yeh
630b262f11 update-all.sh
Kubernetes-commit: 5a18a32a33762315da75ebe5ed97c073ce925e7b
2017-04-04 20:32:46 +00:00
Kubernetes Publisher
3627aeb7d4 sync: resync vendor folder 2017-03-31 20:34:26 +00:00
Kubernetes Publisher
abf9b83bc2 sync(k8s.io/kubernetes) f6401c041202cea4ef7d882730ff1b282b25aaf0 2017-03-31 20:34:06 +00:00
Anthony Yeh
46f4236624 update-all.sh
Kubernetes-commit: f6401c041202cea4ef7d882730ff1b282b25aaf0
2017-03-31 20:34:06 +00:00
Anthony Yeh
d72c2305ba update-all.sh.
Kubernetes-commit: f2eb144dd7bdbe1672e640adc2784a5436447dca
2017-03-31 20:34:06 +00:00
Avesh Agarwal
196d103cc9 Auto generated stuff.
Kubernetes-commit: 0f65df66e68d9fbd4c1cb4a84ef30c751c0588fa
2017-03-31 20:34:05 +00:00
Jordan Liggitt
f0985967e7 Update client-go
Kubernetes-commit: 7ceeee8665a80dca701bada1d85b4edbc8d8a281
2017-03-31 20:34:05 +00:00
Anthony Yeh
2da1ffdb38 update-staging-client-go.sh
Kubernetes-commit: e0d310a84cd16f18a3d6bb9c5b59203626d88b68
2017-03-31 20:34:05 +00:00
Anthony Yeh
fd59eaee0f update-all.sh.
Kubernetes-commit: 5c6a7318a1b093b4ad0c9a32513ed9cfb774ffb7
2017-03-31 20:34:05 +00:00
Anthony Yeh
9efa3fc488 update-all.sh.
Kubernetes-commit: d6f604d37a88a6ac8f431a849b32992fbfa73d85
2017-03-31 20:34:05 +00:00
Anthony Yeh
52cbe06e49 update-staging-client-go.sh
Kubernetes-commit: 6a2d09c9c826b4ad6d22665b699dd7e18a3f520f
2017-03-31 20:34:05 +00:00
Anthony Yeh
a6ed9d14b5 update-all.sh.
Kubernetes-commit: b877536df3c6f242c2d502fa7fc83f4df3ea42fd
2017-03-31 20:34:05 +00:00
33 changed files with 493 additions and 967 deletions

90
Godeps/Godeps.json generated
View File

@@ -1,6 +1,6 @@
{
"ImportPath": "k8s.io/client-go",
"GoVersion": "go1.7",
"GoVersion": "go1.8",
"GodepVersion": "v79",
"Packages": [
"./..."
@@ -316,179 +316,179 @@
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/equality",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/errors",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/meta",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/api/resource",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/announced",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apimachinery/registered",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/conversion/queryparams",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/fields",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/labels",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/openapi",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/schema",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/json",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/protobuf",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/recognizer",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/streaming",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/runtime/serializer/versioning",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/selection",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/types",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/diff",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/errors",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/framer",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/httpstream",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/intstr",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/json",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/mergepatch",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/net",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/rand",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/runtime",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/sets",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/strategicpatch",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/validation",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/validation/field",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/wait",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/util/yaml",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/version",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/pkg/watch",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/json",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
},
{
"ImportPath": "k8s.io/apimachinery/third_party/forked/golang/reflect",
"Rev": "c1c4a7fe832857c75cc1d79c8e40d71d5da15fc6"
"Rev": "85ace5365f33b16fc735c866a12e3c765b9700f2"
}
]
}

View File

@@ -1 +1 @@
9497139cb62015905ba5b3d11836f2b0c117ff80
313fd317f96265658831a576fafdd6ed85aaf428

View File

@@ -18,6 +18,7 @@ package api
import (
"crypto/md5"
"encoding/json"
"fmt"
"reflect"
"strings"
@@ -245,6 +246,7 @@ func IsServiceIPRequested(service *Service) bool {
var standardFinalizers = sets.NewString(
string(FinalizerKubernetes),
metav1.FinalizerOrphanDependents,
metav1.FinalizerDeleteDependents,
)
// HasAnnotation returns a bool if passed in annotation exists
@@ -429,6 +431,14 @@ func NodeSelectorRequirementsAsSelector(nsm []NodeSelectorRequirement) (labels.S
}
const (
// TolerationsAnnotationKey represents the key of tolerations data (json serialized)
// in the Annotations of a Pod.
TolerationsAnnotationKey string = "scheduler.alpha.kubernetes.io/tolerations"
// TaintsAnnotationKey represents the key of taints data (json serialized)
// in the Annotations of a Node.
TaintsAnnotationKey string = "scheduler.alpha.kubernetes.io/taints"
// SeccompPodAnnotationKey represents the key of a seccomp profile applied
// to all containers of a pod.
SeccompPodAnnotationKey string = "seccomp.security.alpha.kubernetes.io/pod"
@@ -463,8 +473,26 @@ const (
// an object (e.g. secret, config map) before fetching it again from apiserver.
// This annotation can be attached to node.
ObjectTTLAnnotationKey string = "node.alpha.kubernetes.io/ttl"
// AffinityAnnotationKey represents the key of affinity data (json serialized)
// in the Annotations of a Pod.
// TODO: remove when alpha support for affinity is removed
AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity"
)
// GetTolerationsFromPodAnnotations gets the json serialized tolerations data from Pod.Annotations
// and converts it to the []Toleration type in api.
func GetTolerationsFromPodAnnotations(annotations map[string]string) ([]Toleration, error) {
var tolerations []Toleration
if len(annotations) > 0 && annotations[TolerationsAnnotationKey] != "" {
err := json.Unmarshal([]byte(annotations[TolerationsAnnotationKey]), &tolerations)
if err != nil {
return tolerations, err
}
}
return tolerations, nil
}
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) {
@@ -548,6 +576,19 @@ func (t *Taint) ToString() string {
return fmt.Sprintf("%v=%v:%v", t.Key, t.Value, t.Effect)
}
// GetTaintsFromNodeAnnotations gets the json serialized taints data from Pod.Annotations
// and converts it to the []Taint type in api.
func GetTaintsFromNodeAnnotations(annotations map[string]string) ([]Taint, error) {
var taints []Taint
if len(annotations) > 0 && annotations[TaintsAnnotationKey] != "" {
err := json.Unmarshal([]byte(annotations[TaintsAnnotationKey]), &taints)
if err != nil {
return []Taint{}, err
}
}
return taints, nil
}
// SysctlsFromPodAnnotations parses the sysctl annotations into a slice of safe Sysctls
// and a slice of unsafe Sysctls. This is only a convenience wrapper around
// SysctlsFromPodAnnotation.
@@ -596,6 +637,21 @@ func PodAnnotationsFromSysctls(sysctls []Sysctl) string {
return strings.Join(kvs, ",")
}
// GetAffinityFromPodAnnotations gets the json serialized affinity data from Pod.Annotations
// and converts it to the Affinity type in api.
// TODO: remove when alpha support for affinity is removed
func GetAffinityFromPodAnnotations(annotations map[string]string) (*Affinity, error) {
if len(annotations) > 0 && annotations[AffinityAnnotationKey] != "" {
var affinity Affinity
err := json.Unmarshal([]byte(annotations[AffinityAnnotationKey]), &affinity)
if err != nil {
return nil, err
}
return &affinity, nil
}
return nil, nil
}
// GetPersistentVolumeClass returns StorageClassName.
func GetPersistentVolumeClass(volume *PersistentVolume) string {
// Use beta annotation first

View File

@@ -276,10 +276,10 @@ const (
AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity"
)
// Tries to add a toleration to annotations list. Returns true if something was updated
// false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) {
podTolerations := pod.Spec.Tolerations
// AddOrUpdateTolerationInPodSpec tries to add a toleration to the toleration list in PodSpec.
// Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPodSpec(spec *PodSpec, toleration *Toleration) (bool, error) {
podTolerations := spec.Tolerations
var newTolerations []Toleration
updated := false
@@ -300,10 +300,16 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
newTolerations = append(newTolerations, *toleration)
}
pod.Spec.Tolerations = newTolerations
spec.Tolerations = newTolerations
return true, nil
}
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) {
return AddOrUpdateTolerationInPodSpec(&pod.Spec, toleration)
}
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
// if the two tolerations have same <key,effect,operator,value> combination, regard as they match.
// TODO: uniqueness check for tolerations in api validations.

View File

@@ -565,7 +565,11 @@ func Convert_v1_CephFSVolumeSource_To_api_CephFSVolumeSource(in *CephFSVolumeSou
}
func autoConvert_api_CephFSVolumeSource_To_v1_CephFSVolumeSource(in *api.CephFSVolumeSource, out *CephFSVolumeSource, s conversion.Scope) error {
out.Monitors = *(*[]string)(unsafe.Pointer(&in.Monitors))
if in.Monitors == nil {
out.Monitors = make([]string, 0)
} else {
out.Monitors = *(*[]string)(unsafe.Pointer(&in.Monitors))
}
out.Path = in.Path
out.User = in.User
out.SecretFile = in.SecretFile
@@ -656,7 +660,11 @@ func Convert_v1_ComponentStatusList_To_api_ComponentStatusList(in *ComponentStat
func autoConvert_api_ComponentStatusList_To_v1_ComponentStatusList(in *api.ComponentStatusList, out *ComponentStatusList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ComponentStatus)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ComponentStatus, 0)
} else {
out.Items = *(*[]ComponentStatus)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -746,7 +754,11 @@ func Convert_v1_ConfigMapList_To_api_ConfigMapList(in *ConfigMapList, out *api.C
func autoConvert_api_ConfigMapList_To_v1_ConfigMapList(in *api.ConfigMapList, out *ConfigMapList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ConfigMap)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ConfigMap, 0)
} else {
out.Items = *(*[]ConfigMap)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -879,7 +891,11 @@ func Convert_v1_ContainerImage_To_api_ContainerImage(in *ContainerImage, out *ap
}
func autoConvert_api_ContainerImage_To_v1_ContainerImage(in *api.ContainerImage, out *ContainerImage, s conversion.Scope) error {
out.Names = *(*[]string)(unsafe.Pointer(&in.Names))
if in.Names == nil {
out.Names = make([]string, 0)
} else {
out.Names = *(*[]string)(unsafe.Pointer(&in.Names))
}
out.SizeBytes = in.SizeBytes
return nil
}
@@ -1246,7 +1262,11 @@ func Convert_v1_Endpoints_To_api_Endpoints(in *Endpoints, out *api.Endpoints, s
func autoConvert_api_Endpoints_To_v1_Endpoints(in *api.Endpoints, out *Endpoints, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Subsets = *(*[]EndpointSubset)(unsafe.Pointer(&in.Subsets))
if in.Subsets == nil {
out.Subsets = make([]EndpointSubset, 0)
} else {
out.Subsets = *(*[]EndpointSubset)(unsafe.Pointer(&in.Subsets))
}
return nil
}
@@ -1266,7 +1286,11 @@ func Convert_v1_EndpointsList_To_api_EndpointsList(in *EndpointsList, out *api.E
func autoConvert_api_EndpointsList_To_v1_EndpointsList(in *api.EndpointsList, out *EndpointsList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Endpoints)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Endpoints, 0)
} else {
out.Items = *(*[]Endpoints)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -1396,7 +1420,11 @@ func Convert_v1_EventList_To_api_EventList(in *EventList, out *api.EventList, s
func autoConvert_api_EventList_To_v1_EventList(in *api.EventList, out *EventList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Event)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Event, 0)
} else {
out.Items = *(*[]Event)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -1455,7 +1483,11 @@ func Convert_v1_FCVolumeSource_To_api_FCVolumeSource(in *FCVolumeSource, out *ap
}
func autoConvert_api_FCVolumeSource_To_v1_FCVolumeSource(in *api.FCVolumeSource, out *FCVolumeSource, s conversion.Scope) error {
out.TargetWWNs = *(*[]string)(unsafe.Pointer(&in.TargetWWNs))
if in.TargetWWNs == nil {
out.TargetWWNs = make([]string, 0)
} else {
out.TargetWWNs = *(*[]string)(unsafe.Pointer(&in.TargetWWNs))
}
out.Lun = (*int32)(unsafe.Pointer(in.Lun))
out.FSType = in.FSType
out.ReadOnly = in.ReadOnly
@@ -1802,7 +1834,11 @@ func Convert_v1_LimitRangeList_To_api_LimitRangeList(in *LimitRangeList, out *ap
func autoConvert_api_LimitRangeList_To_v1_LimitRangeList(in *api.LimitRangeList, out *LimitRangeList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]LimitRange)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]LimitRange, 0)
} else {
out.Items = *(*[]LimitRange)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -1820,7 +1856,11 @@ func Convert_v1_LimitRangeSpec_To_api_LimitRangeSpec(in *LimitRangeSpec, out *ap
}
func autoConvert_api_LimitRangeSpec_To_v1_LimitRangeSpec(in *api.LimitRangeSpec, out *LimitRangeSpec, s conversion.Scope) error {
out.Limits = *(*[]LimitRangeItem)(unsafe.Pointer(&in.Limits))
if in.Limits == nil {
out.Limits = make([]LimitRangeItem, 0)
} else {
out.Limits = *(*[]LimitRangeItem)(unsafe.Pointer(&in.Limits))
}
return nil
}
@@ -1859,7 +1899,7 @@ func autoConvert_api_List_To_v1_List(in *api.List, out *List, s conversion.Scope
}
}
} else {
out.Items = nil
out.Items = make([]runtime.RawExtension, 0)
}
return nil
}
@@ -2022,7 +2062,11 @@ func Convert_v1_NamespaceList_To_api_NamespaceList(in *NamespaceList, out *api.N
func autoConvert_api_NamespaceList_To_v1_NamespaceList(in *api.NamespaceList, out *NamespaceList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Namespace)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Namespace, 0)
} else {
out.Items = *(*[]Namespace)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -2198,7 +2242,11 @@ func Convert_v1_NodeList_To_api_NodeList(in *NodeList, out *api.NodeList, s conv
func autoConvert_api_NodeList_To_v1_NodeList(in *api.NodeList, out *NodeList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Node)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Node, 0)
} else {
out.Items = *(*[]Node)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -2252,7 +2300,11 @@ func Convert_v1_NodeSelector_To_api_NodeSelector(in *NodeSelector, out *api.Node
}
func autoConvert_api_NodeSelector_To_v1_NodeSelector(in *api.NodeSelector, out *NodeSelector, s conversion.Scope) error {
out.NodeSelectorTerms = *(*[]NodeSelectorTerm)(unsafe.Pointer(&in.NodeSelectorTerms))
if in.NodeSelectorTerms == nil {
out.NodeSelectorTerms = make([]NodeSelectorTerm, 0)
} else {
out.NodeSelectorTerms = *(*[]NodeSelectorTerm)(unsafe.Pointer(&in.NodeSelectorTerms))
}
return nil
}
@@ -2292,7 +2344,11 @@ func Convert_v1_NodeSelectorTerm_To_api_NodeSelectorTerm(in *NodeSelectorTerm, o
}
func autoConvert_api_NodeSelectorTerm_To_v1_NodeSelectorTerm(in *api.NodeSelectorTerm, out *NodeSelectorTerm, s conversion.Scope) error {
out.MatchExpressions = *(*[]NodeSelectorRequirement)(unsafe.Pointer(&in.MatchExpressions))
if in.MatchExpressions == nil {
out.MatchExpressions = make([]NodeSelectorRequirement, 0)
} else {
out.MatchExpressions = *(*[]NodeSelectorRequirement)(unsafe.Pointer(&in.MatchExpressions))
}
return nil
}
@@ -2574,7 +2630,11 @@ func Convert_v1_PersistentVolumeClaimList_To_api_PersistentVolumeClaimList(in *P
func autoConvert_api_PersistentVolumeClaimList_To_v1_PersistentVolumeClaimList(in *api.PersistentVolumeClaimList, out *PersistentVolumeClaimList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]PersistentVolumeClaim)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]PersistentVolumeClaim, 0)
} else {
out.Items = *(*[]PersistentVolumeClaim)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -2685,7 +2745,7 @@ func autoConvert_api_PersistentVolumeList_To_v1_PersistentVolumeList(in *api.Per
}
}
} else {
out.Items = nil
out.Items = make([]PersistentVolume, 0)
}
return nil
}
@@ -2980,7 +3040,11 @@ func autoConvert_api_PodExecOptions_To_v1_PodExecOptions(in *api.PodExecOptions,
out.Stderr = in.Stderr
out.TTY = in.TTY
out.Container = in.Container
out.Command = *(*[]string)(unsafe.Pointer(&in.Command))
if in.Command == nil {
out.Command = make([]string, 0)
} else {
out.Command = *(*[]string)(unsafe.Pointer(&in.Command))
}
return nil
}
@@ -3019,7 +3083,7 @@ func autoConvert_api_PodList_To_v1_PodList(in *api.PodList, out *PodList, s conv
}
}
} else {
out.Items = nil
out.Items = make([]Pod, 0)
}
return nil
}
@@ -3192,7 +3256,11 @@ func autoConvert_api_PodSpec_To_v1_PodSpec(in *api.PodSpec, out *PodSpec, s conv
out.Volumes = nil
}
out.InitContainers = *(*[]Container)(unsafe.Pointer(&in.InitContainers))
out.Containers = *(*[]Container)(unsafe.Pointer(&in.Containers))
if in.Containers == nil {
out.Containers = make([]Container, 0)
} else {
out.Containers = *(*[]Container)(unsafe.Pointer(&in.Containers))
}
out.RestartPolicy = RestartPolicy(in.RestartPolicy)
out.TerminationGracePeriodSeconds = (*int64)(unsafe.Pointer(in.TerminationGracePeriodSeconds))
out.ActiveDeadlineSeconds = (*int64)(unsafe.Pointer(in.ActiveDeadlineSeconds))
@@ -3326,7 +3394,7 @@ func autoConvert_api_PodTemplateList_To_v1_PodTemplateList(in *api.PodTemplateLi
}
}
} else {
out.Items = nil
out.Items = make([]PodTemplate, 0)
}
return nil
}
@@ -3486,7 +3554,11 @@ func Convert_v1_ProjectedVolumeSource_To_api_ProjectedVolumeSource(in *Projected
}
func autoConvert_api_ProjectedVolumeSource_To_v1_ProjectedVolumeSource(in *api.ProjectedVolumeSource, out *ProjectedVolumeSource, s conversion.Scope) error {
out.Sources = *(*[]VolumeProjection)(unsafe.Pointer(&in.Sources))
if in.Sources == nil {
out.Sources = make([]VolumeProjection, 0)
} else {
out.Sources = *(*[]VolumeProjection)(unsafe.Pointer(&in.Sources))
}
out.DefaultMode = (*int32)(unsafe.Pointer(in.DefaultMode))
return nil
}
@@ -3538,7 +3610,11 @@ func Convert_v1_RBDVolumeSource_To_api_RBDVolumeSource(in *RBDVolumeSource, out
}
func autoConvert_api_RBDVolumeSource_To_v1_RBDVolumeSource(in *api.RBDVolumeSource, out *RBDVolumeSource, s conversion.Scope) error {
out.CephMonitors = *(*[]string)(unsafe.Pointer(&in.CephMonitors))
if in.CephMonitors == nil {
out.CephMonitors = make([]string, 0)
} else {
out.CephMonitors = *(*[]string)(unsafe.Pointer(&in.CephMonitors))
}
out.RBDImage = in.RBDImage
out.FSType = in.FSType
out.RBDPool = in.RBDPool
@@ -3567,7 +3643,11 @@ func Convert_v1_RangeAllocation_To_api_RangeAllocation(in *RangeAllocation, out
func autoConvert_api_RangeAllocation_To_v1_RangeAllocation(in *api.RangeAllocation, out *RangeAllocation, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Range = in.Range
out.Data = *(*[]byte)(unsafe.Pointer(&in.Data))
if in.Data == nil {
out.Data = make([]byte, 0)
} else {
out.Data = *(*[]byte)(unsafe.Pointer(&in.Data))
}
return nil
}
@@ -3662,7 +3742,7 @@ func autoConvert_api_ReplicationControllerList_To_v1_ReplicationControllerList(i
}
}
} else {
out.Items = nil
out.Items = make([]ReplicationController, 0)
}
return nil
}
@@ -3799,7 +3879,11 @@ func Convert_v1_ResourceQuotaList_To_api_ResourceQuotaList(in *ResourceQuotaList
func autoConvert_api_ResourceQuotaList_To_v1_ResourceQuotaList(in *api.ResourceQuotaList, out *ResourceQuotaList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ResourceQuota)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ResourceQuota, 0)
} else {
out.Items = *(*[]ResourceQuota)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -4027,7 +4111,7 @@ func autoConvert_api_SecretList_To_v1_SecretList(in *api.SecretList, out *Secret
}
}
} else {
out.Items = nil
out.Items = make([]Secret, 0)
}
return nil
}
@@ -4202,7 +4286,11 @@ func Convert_v1_ServiceAccountList_To_api_ServiceAccountList(in *ServiceAccountL
func autoConvert_api_ServiceAccountList_To_v1_ServiceAccountList(in *api.ServiceAccountList, out *ServiceAccountList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ServiceAccount)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ServiceAccount, 0)
} else {
out.Items = *(*[]ServiceAccount)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -4241,7 +4329,7 @@ func autoConvert_api_ServiceList_To_v1_ServiceList(in *api.ServiceList, out *Ser
}
}
} else {
out.Items = nil
out.Items = make([]Service, 0)
}
return nil
}

View File

@@ -110,7 +110,7 @@ func autoConvert_apps_StatefulSetList_To_v1beta1_StatefulSetList(in *apps.Statef
}
}
} else {
out.Items = nil
out.Items = make([]StatefulSet, 0)
}
return nil
}

View File

@@ -149,7 +149,7 @@ func autoConvert_autoscaling_HorizontalPodAutoscalerList_To_v1_HorizontalPodAuto
}
}
} else {
out.Items = nil
out.Items = make([]HorizontalPodAutoscaler, 0)
}
return nil
}

View File

@@ -132,7 +132,11 @@ func Convert_v2alpha1_HorizontalPodAutoscalerList_To_autoscaling_HorizontalPodAu
func autoConvert_autoscaling_HorizontalPodAutoscalerList_To_v2alpha1_HorizontalPodAutoscalerList(in *autoscaling.HorizontalPodAutoscalerList, out *HorizontalPodAutoscalerList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]HorizontalPodAutoscaler)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]HorizontalPodAutoscaler, 0)
} else {
out.Items = *(*[]HorizontalPodAutoscaler)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -186,7 +190,11 @@ func autoConvert_autoscaling_HorizontalPodAutoscalerStatus_To_v2alpha1_Horizonta
out.LastScaleTime = (*v1.Time)(unsafe.Pointer(in.LastScaleTime))
out.CurrentReplicas = in.CurrentReplicas
out.DesiredReplicas = in.DesiredReplicas
out.CurrentMetrics = *(*[]MetricStatus)(unsafe.Pointer(&in.CurrentMetrics))
if in.CurrentMetrics == nil {
out.CurrentMetrics = make([]MetricStatus, 0)
} else {
out.CurrentMetrics = *(*[]MetricStatus)(unsafe.Pointer(&in.CurrentMetrics))
}
return nil
}

View File

@@ -233,6 +233,7 @@ type CronJobSpec struct {
StartingDeadlineSeconds *int64
// ConcurrencyPolicy specifies how to treat concurrent executions of a Job.
// Defaults to Allow.
// +optional
ConcurrencyPolicy ConcurrencyPolicy

View File

@@ -140,7 +140,7 @@ func autoConvert_batch_JobList_To_v1_JobList(in *batch.JobList, out *JobList, s
}
}
} else {
out.Items = nil
out.Items = make([]Job, 0)
}
return nil
}

View File

@@ -72,6 +72,7 @@ message CronJobSpec {
optional int64 startingDeadlineSeconds = 2;
// ConcurrencyPolicy specifies how to treat concurrent executions of a Job.
// Defaults to Allow.
// +optional
optional string concurrencyPolicy = 3;

View File

@@ -94,6 +94,7 @@ type CronJobSpec struct {
StartingDeadlineSeconds *int64 `json:"startingDeadlineSeconds,omitempty" protobuf:"varint,2,opt,name=startingDeadlineSeconds"`
// ConcurrencyPolicy specifies how to treat concurrent executions of a Job.
// Defaults to Allow.
// +optional
ConcurrencyPolicy ConcurrencyPolicy `json:"concurrencyPolicy,omitempty" protobuf:"bytes,3,opt,name=concurrencyPolicy,casttype=ConcurrencyPolicy"`

View File

@@ -52,7 +52,7 @@ var map_CronJobSpec = map[string]string{
"": "CronJobSpec describes how the job execution will look like and when it will actually run.",
"schedule": "Schedule contains the schedule in Cron format, see https://en.wikipedia.org/wiki/Cron.",
"startingDeadlineSeconds": "Optional deadline in seconds for starting the job if it misses scheduled time for any reason. Missed jobs executions will be counted as failed ones.",
"concurrencyPolicy": "ConcurrencyPolicy specifies how to treat concurrent executions of a Job.",
"concurrencyPolicy": "ConcurrencyPolicy specifies how to treat concurrent executions of a Job. Defaults to Allow.",
"suspend": "Suspend flag tells the controller to suspend subsequent executions, it does not apply to already started executions. Defaults to false.",
"jobTemplate": "JobTemplate is the object that describes the job that will be created when executing a CronJob.",
"successfulJobsHistoryLimit": "The number of successful finished jobs to retain. This is a pointer to distinguish between explicit zero and not specified.",

View File

@@ -115,7 +115,7 @@ func autoConvert_batch_CronJobList_To_v2alpha1_CronJobList(in *batch.CronJobList
}
}
} else {
out.Items = nil
out.Items = make([]CronJob, 0)
}
return nil
}

View File

@@ -114,7 +114,11 @@ func Convert_v1beta1_CertificateSigningRequestList_To_certificates_CertificateSi
func autoConvert_certificates_CertificateSigningRequestList_To_v1beta1_CertificateSigningRequestList(in *certificates.CertificateSigningRequestList, out *CertificateSigningRequestList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]CertificateSigningRequest)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]CertificateSigningRequest, 0)
} else {
out.Items = *(*[]CertificateSigningRequest)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -137,7 +141,11 @@ func Convert_v1beta1_CertificateSigningRequestSpec_To_certificates_CertificateSi
}
func autoConvert_certificates_CertificateSigningRequestSpec_To_v1beta1_CertificateSigningRequestSpec(in *certificates.CertificateSigningRequestSpec, out *CertificateSigningRequestSpec, s conversion.Scope) error {
out.Request = *(*[]byte)(unsafe.Pointer(&in.Request))
if in.Request == nil {
out.Request = make([]byte, 0)
} else {
out.Request = *(*[]byte)(unsafe.Pointer(&in.Request))
}
out.Usages = *(*[]KeyUsage)(unsafe.Pointer(&in.Usages))
out.Username = in.Username
out.UID = in.UID

View File

@@ -206,7 +206,11 @@ func Convert_v1beta1_CustomMetricCurrentStatusList_To_extensions_CustomMetricCur
}
func autoConvert_extensions_CustomMetricCurrentStatusList_To_v1beta1_CustomMetricCurrentStatusList(in *extensions.CustomMetricCurrentStatusList, out *CustomMetricCurrentStatusList, s conversion.Scope) error {
out.Items = *(*[]CustomMetricCurrentStatus)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]CustomMetricCurrentStatus, 0)
} else {
out.Items = *(*[]CustomMetricCurrentStatus)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -244,7 +248,11 @@ func Convert_v1beta1_CustomMetricTargetList_To_extensions_CustomMetricTargetList
}
func autoConvert_extensions_CustomMetricTargetList_To_v1beta1_CustomMetricTargetList(in *extensions.CustomMetricTargetList, out *CustomMetricTargetList, s conversion.Scope) error {
out.Items = *(*[]CustomMetricTarget)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]CustomMetricTarget, 0)
} else {
out.Items = *(*[]CustomMetricTarget)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -313,7 +321,7 @@ func autoConvert_extensions_DaemonSetList_To_v1beta1_DaemonSetList(in *extension
}
}
} else {
out.Items = nil
out.Items = make([]DaemonSet, 0)
}
return nil
}
@@ -513,7 +521,7 @@ func autoConvert_extensions_DeploymentList_To_v1beta1_DeploymentList(in *extensi
}
}
} else {
out.Items = nil
out.Items = make([]Deployment, 0)
}
return nil
}
@@ -698,7 +706,11 @@ func Convert_v1beta1_HTTPIngressRuleValue_To_extensions_HTTPIngressRuleValue(in
}
func autoConvert_extensions_HTTPIngressRuleValue_To_v1beta1_HTTPIngressRuleValue(in *extensions.HTTPIngressRuleValue, out *HTTPIngressRuleValue, s conversion.Scope) error {
out.Paths = *(*[]HTTPIngressPath)(unsafe.Pointer(&in.Paths))
if in.Paths == nil {
out.Paths = make([]HTTPIngressPath, 0)
} else {
out.Paths = *(*[]HTTPIngressPath)(unsafe.Pointer(&in.Paths))
}
return nil
}
@@ -808,7 +820,11 @@ func Convert_v1beta1_IngressList_To_extensions_IngressList(in *IngressList, out
func autoConvert_extensions_IngressList_To_v1beta1_IngressList(in *extensions.IngressList, out *IngressList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Ingress)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Ingress, 0)
} else {
out.Items = *(*[]Ingress)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -980,7 +996,11 @@ func Convert_v1beta1_NetworkPolicyList_To_extensions_NetworkPolicyList(in *Netwo
func autoConvert_extensions_NetworkPolicyList_To_v1beta1_NetworkPolicyList(in *extensions.NetworkPolicyList, out *NetworkPolicyList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]NetworkPolicy)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]NetworkPolicy, 0)
} else {
out.Items = *(*[]NetworkPolicy)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -1103,7 +1123,7 @@ func autoConvert_extensions_PodSecurityPolicyList_To_v1beta1_PodSecurityPolicyLi
}
}
} else {
out.Items = nil
out.Items = make([]PodSecurityPolicy, 0)
}
return nil
}
@@ -1279,7 +1299,7 @@ func autoConvert_extensions_ReplicaSetList_To_v1beta1_ReplicaSetList(in *extensi
}
}
} else {
out.Items = nil
out.Items = make([]ReplicaSet, 0)
}
return nil
}
@@ -1571,7 +1591,11 @@ func Convert_v1beta1_ThirdPartyResourceDataList_To_extensions_ThirdPartyResource
func autoConvert_extensions_ThirdPartyResourceDataList_To_v1beta1_ThirdPartyResourceDataList(in *extensions.ThirdPartyResourceDataList, out *ThirdPartyResourceDataList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ThirdPartyResourceData)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ThirdPartyResourceData, 0)
} else {
out.Items = *(*[]ThirdPartyResourceData)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -1591,7 +1615,11 @@ func Convert_v1beta1_ThirdPartyResourceList_To_extensions_ThirdPartyResourceList
func autoConvert_extensions_ThirdPartyResourceList_To_v1beta1_ThirdPartyResourceList(in *extensions.ThirdPartyResourceList, out *ThirdPartyResourceList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ThirdPartyResource)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ThirdPartyResource, 0)
} else {
out.Items = *(*[]ThirdPartyResource)(unsafe.Pointer(&in.Items))
}
return nil
}

View File

@@ -111,7 +111,11 @@ func Convert_v1beta1_PodDisruptionBudgetList_To_policy_PodDisruptionBudgetList(i
func autoConvert_policy_PodDisruptionBudgetList_To_v1beta1_PodDisruptionBudgetList(in *policy.PodDisruptionBudgetList, out *PodDisruptionBudgetList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]PodDisruptionBudget)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]PodDisruptionBudget, 0)
} else {
out.Items = *(*[]PodDisruptionBudget)(unsafe.Pointer(&in.Items))
}
return nil
}

View File

@@ -76,7 +76,11 @@ func Convert_v1alpha1_ClusterRole_To_rbac_ClusterRole(in *ClusterRole, out *rbac
func autoConvert_rbac_ClusterRole_To_v1alpha1_ClusterRole(in *rbac.ClusterRole, out *ClusterRole, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
if in.Rules == nil {
out.Rules = make([]PolicyRule, 0)
} else {
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
}
return nil
}
@@ -118,7 +122,7 @@ func autoConvert_rbac_ClusterRoleBinding_To_v1alpha1_ClusterRoleBinding(in *rbac
}
}
} else {
out.Subjects = nil
out.Subjects = make([]Subject, 0)
}
if err := Convert_rbac_RoleRef_To_v1alpha1_RoleRef(&in.RoleRef, &out.RoleRef, s); err != nil {
return err
@@ -183,7 +187,7 @@ func autoConvert_rbac_ClusterRoleBindingList_To_v1alpha1_ClusterRoleBindingList(
}
}
} else {
out.Items = nil
out.Items = make([]ClusterRoleBinding, 0)
}
return nil
}
@@ -204,7 +208,11 @@ func Convert_v1alpha1_ClusterRoleList_To_rbac_ClusterRoleList(in *ClusterRoleLis
func autoConvert_rbac_ClusterRoleList_To_v1alpha1_ClusterRoleList(in *rbac.ClusterRoleList, out *ClusterRoleList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ClusterRole)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ClusterRole, 0)
} else {
out.Items = *(*[]ClusterRole)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -226,7 +234,11 @@ func Convert_v1alpha1_PolicyRule_To_rbac_PolicyRule(in *PolicyRule, out *rbac.Po
}
func autoConvert_rbac_PolicyRule_To_v1alpha1_PolicyRule(in *rbac.PolicyRule, out *PolicyRule, s conversion.Scope) error {
out.Verbs = *(*[]string)(unsafe.Pointer(&in.Verbs))
if in.Verbs == nil {
out.Verbs = make([]string, 0)
} else {
out.Verbs = *(*[]string)(unsafe.Pointer(&in.Verbs))
}
out.APIGroups = *(*[]string)(unsafe.Pointer(&in.APIGroups))
out.Resources = *(*[]string)(unsafe.Pointer(&in.Resources))
out.ResourceNames = *(*[]string)(unsafe.Pointer(&in.ResourceNames))
@@ -272,7 +284,11 @@ func Convert_v1alpha1_Role_To_rbac_Role(in *Role, out *rbac.Role, s conversion.S
func autoConvert_rbac_Role_To_v1alpha1_Role(in *rbac.Role, out *Role, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
if in.Rules == nil {
out.Rules = make([]PolicyRule, 0)
} else {
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
}
return nil
}
@@ -314,7 +330,7 @@ func autoConvert_rbac_RoleBinding_To_v1alpha1_RoleBinding(in *rbac.RoleBinding,
}
}
} else {
out.Subjects = nil
out.Subjects = make([]Subject, 0)
}
if err := Convert_rbac_RoleRef_To_v1alpha1_RoleRef(&in.RoleRef, &out.RoleRef, s); err != nil {
return err
@@ -357,7 +373,7 @@ func autoConvert_rbac_RoleBindingList_To_v1alpha1_RoleBindingList(in *rbac.RoleB
}
}
} else {
out.Items = nil
out.Items = make([]RoleBinding, 0)
}
return nil
}
@@ -378,7 +394,11 @@ func Convert_v1alpha1_RoleList_To_rbac_RoleList(in *RoleList, out *rbac.RoleList
func autoConvert_rbac_RoleList_To_v1alpha1_RoleList(in *rbac.RoleList, out *RoleList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Role)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Role, 0)
} else {
out.Items = *(*[]Role)(unsafe.Pointer(&in.Items))
}
return nil
}

View File

@@ -76,7 +76,11 @@ func Convert_v1beta1_ClusterRole_To_rbac_ClusterRole(in *ClusterRole, out *rbac.
func autoConvert_rbac_ClusterRole_To_v1beta1_ClusterRole(in *rbac.ClusterRole, out *ClusterRole, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
if in.Rules == nil {
out.Rules = make([]PolicyRule, 0)
} else {
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
}
return nil
}
@@ -99,7 +103,11 @@ func Convert_v1beta1_ClusterRoleBinding_To_rbac_ClusterRoleBinding(in *ClusterRo
func autoConvert_rbac_ClusterRoleBinding_To_v1beta1_ClusterRoleBinding(in *rbac.ClusterRoleBinding, out *ClusterRoleBinding, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Subjects = *(*[]Subject)(unsafe.Pointer(&in.Subjects))
if in.Subjects == nil {
out.Subjects = make([]Subject, 0)
} else {
out.Subjects = *(*[]Subject)(unsafe.Pointer(&in.Subjects))
}
if err := Convert_rbac_RoleRef_To_v1beta1_RoleRef(&in.RoleRef, &out.RoleRef, s); err != nil {
return err
}
@@ -144,7 +152,11 @@ func Convert_v1beta1_ClusterRoleBindingList_To_rbac_ClusterRoleBindingList(in *C
func autoConvert_rbac_ClusterRoleBindingList_To_v1beta1_ClusterRoleBindingList(in *rbac.ClusterRoleBindingList, out *ClusterRoleBindingList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ClusterRoleBinding)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ClusterRoleBinding, 0)
} else {
out.Items = *(*[]ClusterRoleBinding)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -164,7 +176,11 @@ func Convert_v1beta1_ClusterRoleList_To_rbac_ClusterRoleList(in *ClusterRoleList
func autoConvert_rbac_ClusterRoleList_To_v1beta1_ClusterRoleList(in *rbac.ClusterRoleList, out *ClusterRoleList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]ClusterRole)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]ClusterRole, 0)
} else {
out.Items = *(*[]ClusterRole)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -186,7 +202,11 @@ func Convert_v1beta1_PolicyRule_To_rbac_PolicyRule(in *PolicyRule, out *rbac.Pol
}
func autoConvert_rbac_PolicyRule_To_v1beta1_PolicyRule(in *rbac.PolicyRule, out *PolicyRule, s conversion.Scope) error {
out.Verbs = *(*[]string)(unsafe.Pointer(&in.Verbs))
if in.Verbs == nil {
out.Verbs = make([]string, 0)
} else {
out.Verbs = *(*[]string)(unsafe.Pointer(&in.Verbs))
}
out.APIGroups = *(*[]string)(unsafe.Pointer(&in.APIGroups))
out.Resources = *(*[]string)(unsafe.Pointer(&in.Resources))
out.ResourceNames = *(*[]string)(unsafe.Pointer(&in.ResourceNames))
@@ -232,7 +252,11 @@ func Convert_v1beta1_Role_To_rbac_Role(in *Role, out *rbac.Role, s conversion.Sc
func autoConvert_rbac_Role_To_v1beta1_Role(in *rbac.Role, out *Role, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
if in.Rules == nil {
out.Rules = make([]PolicyRule, 0)
} else {
out.Rules = *(*[]PolicyRule)(unsafe.Pointer(&in.Rules))
}
return nil
}
@@ -255,7 +279,11 @@ func Convert_v1beta1_RoleBinding_To_rbac_RoleBinding(in *RoleBinding, out *rbac.
func autoConvert_rbac_RoleBinding_To_v1beta1_RoleBinding(in *rbac.RoleBinding, out *RoleBinding, s conversion.Scope) error {
out.ObjectMeta = in.ObjectMeta
out.Subjects = *(*[]Subject)(unsafe.Pointer(&in.Subjects))
if in.Subjects == nil {
out.Subjects = make([]Subject, 0)
} else {
out.Subjects = *(*[]Subject)(unsafe.Pointer(&in.Subjects))
}
if err := Convert_rbac_RoleRef_To_v1beta1_RoleRef(&in.RoleRef, &out.RoleRef, s); err != nil {
return err
}
@@ -278,7 +306,11 @@ func Convert_v1beta1_RoleBindingList_To_rbac_RoleBindingList(in *RoleBindingList
func autoConvert_rbac_RoleBindingList_To_v1beta1_RoleBindingList(in *rbac.RoleBindingList, out *RoleBindingList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]RoleBinding)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]RoleBinding, 0)
} else {
out.Items = *(*[]RoleBinding)(unsafe.Pointer(&in.Items))
}
return nil
}
@@ -298,7 +330,11 @@ func Convert_v1beta1_RoleList_To_rbac_RoleList(in *RoleList, out *rbac.RoleList,
func autoConvert_rbac_RoleList_To_v1beta1_RoleList(in *rbac.RoleList, out *RoleList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]Role)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]Role, 0)
} else {
out.Items = *(*[]Role)(unsafe.Pointer(&in.Items))
}
return nil
}

View File

@@ -101,7 +101,7 @@ func autoConvert_settings_PodPresetList_To_v1alpha1_PodPresetList(in *settings.P
}
}
} else {
out.Items = nil
out.Items = make([]PodPreset, 0)
}
return nil
}

View File

@@ -76,7 +76,11 @@ func Convert_v1_StorageClassList_To_storage_StorageClassList(in *StorageClassLis
func autoConvert_storage_StorageClassList_To_v1_StorageClassList(in *storage.StorageClassList, out *StorageClassList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]StorageClass)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]StorageClass, 0)
} else {
out.Items = *(*[]StorageClass)(unsafe.Pointer(&in.Items))
}
return nil
}

View File

@@ -76,7 +76,11 @@ func Convert_v1beta1_StorageClassList_To_storage_StorageClassList(in *StorageCla
func autoConvert_storage_StorageClassList_To_v1beta1_StorageClassList(in *storage.StorageClassList, out *StorageClassList, s conversion.Scope) error {
out.ListMeta = in.ListMeta
out.Items = *(*[]StorageClass)(unsafe.Pointer(&in.Items))
if in.Items == nil {
out.Items = make([]StorageClass, 0)
} else {
out.Items = *(*[]StorageClass)(unsafe.Pointer(&in.Items))
}
return nil
}

View File

@@ -39,8 +39,8 @@ var (
// them irrelevant. (Next we'll take it out, which may muck with
// scripts consuming the kubectl version output - but most of
// these should be looking at gitVersion already anyways.)
gitMajor string = "" // major version, always numeric
gitMinor string = "" // minor version, numeric possibly followed by "+"
gitMajor string = "1" // major version, always numeric
gitMinor string = "6+" // minor version, numeric possibly followed by "+"
// semantic version, derived by build scripts (see
// https://github.com/kubernetes/kubernetes/blob/master/docs/design/versioning.md
@@ -51,7 +51,7 @@ var (
// semantic version is a git hash, but the version itself is no
// longer the direct output of "git describe", but a slight
// translation to be semver compliant.
gitVersion string = "v0.0.0-master+$Format:%h$"
gitVersion string = "v1.6.8-beta.0+$Format:%h$"
gitCommit string = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
gitTreeState string = "not a git tree" // state of git tree, either "clean" or "dirty"

View File

@@ -22,7 +22,7 @@ import (
"net"
"net/http"
"os"
"path"
"path/filepath"
gruntime "runtime"
"strings"
"time"
@@ -255,19 +255,51 @@ func SetKubernetesDefaults(config *Config) error {
return nil
}
// DefaultKubernetesUserAgent returns the default user agent that clients can use.
// adjustCommit returns sufficient significant figures of the commit's git hash.
func adjustCommit(c string) string {
if len(c) == 0 {
return "unknown"
}
if len(c) > 7 {
return c[:7]
}
return c
}
// adjustVersion strips "alpha", "beta", etc. from version in form
// major.minor.patch-[alpha|beta|etc].
func adjustVersion(v string) string {
if len(v) == 0 {
return "unknown"
}
seg := strings.SplitN(v, "-", 2)
return seg[0]
}
// adjustCommand returns the last component of the
// OS-specific command path for use in User-Agent.
func adjustCommand(p string) string {
// Unlikely, but better than returning "".
if len(p) == 0 {
return "unknown"
}
return filepath.Base(p)
}
// buildUserAgent builds a User-Agent string from given args.
func buildUserAgent(command, version, os, arch, commit string) string {
return fmt.Sprintf(
"%s/%s (%s/%s) kubernetes/%s", command, version, os, arch, commit)
}
// DefaultKubernetesUserAgent returns a User-Agent string built from static global vars.
func DefaultKubernetesUserAgent() string {
commit := version.Get().GitCommit
if len(commit) > 7 {
commit = commit[:7]
}
if len(commit) == 0 {
commit = "unknown"
}
version := version.Get().GitVersion
seg := strings.SplitN(version, "-", 2)
version = seg[0]
return fmt.Sprintf("%s/%s (%s/%s) kubernetes/%s", path.Base(os.Args[0]), version, gruntime.GOOS, gruntime.GOARCH, commit)
return buildUserAgent(
adjustCommand(os.Args[0]),
adjustVersion(version.Get().GitVersion),
gruntime.GOOS,
gruntime.GOARCH,
adjustCommit(version.Get().GitCommit))
}
// InClusterConfig returns a config object which uses the service account

View File

@@ -19,6 +19,7 @@ package rest
import (
"io"
"net/http"
"path/filepath"
"reflect"
"strings"
"testing"
@@ -32,6 +33,7 @@ import (
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
"k8s.io/client-go/util/flowcontrol"
"github.com/stretchr/testify/assert"
_ "k8s.io/client-go/pkg/api/install"
)
@@ -100,6 +102,42 @@ func TestSetKubernetesDefaultsUserAgent(t *testing.T) {
}
}
func TestAdjustVersion(t *testing.T) {
assert := assert.New(t)
assert.Equal("1.2.3", adjustVersion("1.2.3-alpha4"))
assert.Equal("1.2.3", adjustVersion("1.2.3-alpha"))
assert.Equal("1.2.3", adjustVersion("1.2.3"))
assert.Equal("unknown", adjustVersion(""))
}
func TestAdjustCommit(t *testing.T) {
assert := assert.New(t)
assert.Equal("1234567", adjustCommit("1234567890"))
assert.Equal("123456", adjustCommit("123456"))
assert.Equal("unknown", adjustCommit(""))
}
func TestAdjustCommand(t *testing.T) {
assert := assert.New(t)
assert.Equal("beans", adjustCommand(filepath.Join("home", "bob", "Downloads", "beans")))
assert.Equal("beans", adjustCommand(filepath.Join(".", "beans")))
assert.Equal("beans", adjustCommand("beans"))
assert.Equal("unknown", adjustCommand(""))
}
func TestBuildUserAgent(t *testing.T) {
assert.New(t).Equal(
"lynx/nicest (beos/itanium) kubernetes/baaaaaaaaad",
buildUserAgent(
"lynx", "nicest",
"beos", "itanium", "baaaaaaaaad"))
}
// This function untestable since it doesn't accept arguments.
func TestDefaultKubernetesUserAgent(t *testing.T) {
assert.New(t).Contains(DefaultKubernetesUserAgent(), "kubernetes")
}
func TestRESTClientRequires(t *testing.T) {
if _, err := RESTClientFor(&Config{Host: "127.0.0.1", ContentConfig: ContentConfig{NegotiatedSerializer: api.Codecs}}); err == nil {
t.Errorf("unexpected non-error")

View File

@@ -482,13 +482,13 @@ func (config *inClusterClientConfig) Namespace() (string, bool, error) {
// This way assumes you've set the POD_NAMESPACE environment variable using the downward API.
// This check has to be done first for backwards compatibility with the way InClusterConfig was originally set up
if ns := os.Getenv("POD_NAMESPACE"); ns != "" {
return ns, true, nil
return ns, false, nil
}
// Fall back to the namespace associated with the service account token, if available
if data, err := ioutil.ReadFile("/var/run/secrets/kubernetes.io/serviceaccount/namespace"); err == nil {
if ns := strings.TrimSpace(string(data)); len(ns) > 0 {
return ns, true, nil
return ns, false, nil
}
}

View File

@@ -22,6 +22,7 @@ import (
"github.com/golang/glog"
"k8s.io/client-go/pkg/api"
restclient "k8s.io/client-go/rest"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
@@ -134,12 +135,26 @@ func (config *DeferredLoadingClientConfig) Namespace() (string, bool, error) {
return "", false, err
}
ns, ok, err := mergedKubeConfig.Namespace()
ns, overridden, err := mergedKubeConfig.Namespace()
// if we get an error and it is not empty config, or if the merged config defined an explicit namespace, or
// if in-cluster config is not possible, return immediately
if (err != nil && !IsEmptyConfig(err)) || ok || !config.icc.Possible() {
if (err != nil && !IsEmptyConfig(err)) || overridden || !config.icc.Possible() {
// return on any error except empty config
return ns, ok, err
return ns, overridden, err
}
if len(ns) > 0 {
// if we got a non-default namespace from the kubeconfig, use it
if ns != api.NamespaceDefault {
return ns, false, nil
}
// if we got a default namespace, determine whether it was explicit or implicit
if raw, err := mergedKubeConfig.RawConfig(); err == nil {
if context := raw.Contexts[raw.CurrentContext]; context != nil && len(context.Namespace) > 0 {
return ns, false, nil
}
}
}
glog.V(4).Infof("Using in-cluster namespace")

View File

@@ -1,13 +0,0 @@
language: go
go:
- 1.4
- 1.3
- 1.2
- tip
install:
- if ! go get code.google.com/p/go.tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi
script:
- go test -cover

View File

@@ -1,67 +0,0 @@
# How to contribute #
We'd love to accept your patches and contributions to this project. There are
a just a few small guidelines you need to follow.
## Contributor License Agreement ##
Contributions to any Google project must be accompanied by a Contributor
License Agreement. This is not a copyright **assignment**, it simply gives
Google permission to use and redistribute your contributions as part of the
project.
* If you are an individual writing original source code and you're sure you
own the intellectual property, then you'll need to sign an [individual
CLA][].
* If you work for a company that wants to allow you to contribute your work,
then you'll need to sign a [corporate CLA][].
You generally only need to submit a CLA once, so if you've already submitted
one (even if it was for a different project), you probably don't need to do it
again.
[individual CLA]: https://developers.google.com/open-source/cla/individual
[corporate CLA]: https://developers.google.com/open-source/cla/corporate
## Submitting a patch ##
1. It's generally best to start by opening a new issue describing the bug or
feature you're intending to fix. Even if you think it's relatively minor,
it's helpful to know what people are working on. Mention in the initial
issue that you are planning to work on that bug or feature so that it can
be assigned to you.
1. Follow the normal process of [forking][] the project, and setup a new
branch to work in. It's important that each group of changes be done in
separate branches in order to ensure that a pull request only includes the
commits related to that bug or feature.
1. Go makes it very simple to ensure properly formatted code, so always run
`go fmt` on your code before committing it. You should also run
[golint][] over your code. As noted in the [golint readme][], it's not
strictly necessary that your code be completely "lint-free", but this will
help you find common style issues.
1. Any significant changes should almost always be accompanied by tests. The
project already has good test coverage, so look at some of the existing
tests if you're unsure how to go about it. [gocov][] and [gocov-html][]
are invaluable tools for seeing which parts of your code aren't being
exercised by your tests.
1. Do your best to have [well-formed commit messages][] for each change.
This provides consistency throughout the project, and ensures that commit
messages are able to be formatted properly by various git tools.
1. Finally, push the commits to your fork and submit a [pull request][].
[forking]: https://help.github.com/articles/fork-a-repo
[golint]: https://github.com/golang/lint
[golint readme]: https://github.com/golang/lint/blob/master/README
[gocov]: https://github.com/axw/gocov
[gocov-html]: https://github.com/matm/gocov-html
[well-formed commit messages]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits
[pull request]: https://help.github.com/articles/creating-a-pull-request

View File

@@ -1,202 +0,0 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.

View File

@@ -1,71 +0,0 @@
gofuzz
======
gofuzz is a library for populating go objects with random values.
[![GoDoc](https://godoc.org/github.com/google/gofuzz?status.png)](https://godoc.org/github.com/google/gofuzz)
[![Travis](https://travis-ci.org/google/gofuzz.svg?branch=master)](https://travis-ci.org/google/gofuzz)
This is useful for testing:
* Do your project's objects really serialize/unserialize correctly in all cases?
* Is there an incorrectly formatted object that will cause your project to panic?
Import with ```import "github.com/google/gofuzz"```
You can use it on single variables:
```go
f := fuzz.New()
var myInt int
f.Fuzz(&myInt) // myInt gets a random value.
```
You can use it on maps:
```go
f := fuzz.New().NilChance(0).NumElements(1, 1)
var myMap map[ComplexKeyType]string
f.Fuzz(&myMap) // myMap will have exactly one element.
```
Customize the chance of getting a nil pointer:
```go
f := fuzz.New().NilChance(.5)
var fancyStruct struct {
A, B, C, D *string
}
f.Fuzz(&fancyStruct) // About half the pointers should be set.
```
You can even customize the randomization completely if needed:
```go
type MyEnum string
const (
A MyEnum = "A"
B MyEnum = "B"
)
type MyInfo struct {
Type MyEnum
AInfo *string
BInfo *string
}
f := fuzz.New().NilChance(0).Funcs(
func(e *MyInfo, c fuzz.Continue) {
switch c.Intn(2) {
case 0:
e.Type = A
c.Fuzz(&e.AInfo)
case 1:
e.Type = B
c.Fuzz(&e.BInfo)
}
},
)
var myObject MyInfo
f.Fuzz(&myObject) // Type will correspond to whether A or B info is set.
```
See more examples in ```example_test.go```.
Happy testing!

View File

@@ -1,18 +0,0 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 fuzz is a library for populating go objects with random values.
package fuzz

View File

@@ -1,453 +0,0 @@
/*
Copyright 2014 Google Inc. All rights reserved.
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 fuzz
import (
"fmt"
"math/rand"
"reflect"
"time"
)
// fuzzFuncMap is a map from a type to a fuzzFunc that handles that type.
type fuzzFuncMap map[reflect.Type]reflect.Value
// Fuzzer knows how to fill any object with random fields.
type Fuzzer struct {
fuzzFuncs fuzzFuncMap
defaultFuzzFuncs fuzzFuncMap
r *rand.Rand
nilChance float64
minElements int
maxElements int
}
// New returns a new Fuzzer. Customize your Fuzzer further by calling Funcs,
// RandSource, NilChance, or NumElements in any order.
func New() *Fuzzer {
f := &Fuzzer{
defaultFuzzFuncs: fuzzFuncMap{
reflect.TypeOf(&time.Time{}): reflect.ValueOf(fuzzTime),
},
fuzzFuncs: fuzzFuncMap{},
r: rand.New(rand.NewSource(time.Now().UnixNano())),
nilChance: .2,
minElements: 1,
maxElements: 10,
}
return f
}
// Funcs adds each entry in fuzzFuncs as a custom fuzzing function.
//
// Each entry in fuzzFuncs must be a function taking two parameters.
// The first parameter must be a pointer or map. It is the variable that
// function will fill with random data. The second parameter must be a
// fuzz.Continue, which will provide a source of randomness and a way
// to automatically continue fuzzing smaller pieces of the first parameter.
//
// These functions are called sensibly, e.g., if you wanted custom string
// fuzzing, the function `func(s *string, c fuzz.Continue)` would get
// called and passed the address of strings. Maps and pointers will always
// be made/new'd for you, ignoring the NilChange option. For slices, it
// doesn't make much sense to pre-create them--Fuzzer doesn't know how
// long you want your slice--so take a pointer to a slice, and make it
// yourself. (If you don't want your map/pointer type pre-made, take a
// pointer to it, and make it yourself.) See the examples for a range of
// custom functions.
func (f *Fuzzer) Funcs(fuzzFuncs ...interface{}) *Fuzzer {
for i := range fuzzFuncs {
v := reflect.ValueOf(fuzzFuncs[i])
if v.Kind() != reflect.Func {
panic("Need only funcs!")
}
t := v.Type()
if t.NumIn() != 2 || t.NumOut() != 0 {
panic("Need 2 in and 0 out params!")
}
argT := t.In(0)
switch argT.Kind() {
case reflect.Ptr, reflect.Map:
default:
panic("fuzzFunc must take pointer or map type")
}
if t.In(1) != reflect.TypeOf(Continue{}) {
panic("fuzzFunc's second parameter must be type fuzz.Continue")
}
f.fuzzFuncs[argT] = v
}
return f
}
// RandSource causes f to get values from the given source of randomness.
// Use if you want deterministic fuzzing.
func (f *Fuzzer) RandSource(s rand.Source) *Fuzzer {
f.r = rand.New(s)
return f
}
// NilChance sets the probability of creating a nil pointer, map, or slice to
// 'p'. 'p' should be between 0 (no nils) and 1 (all nils), inclusive.
func (f *Fuzzer) NilChance(p float64) *Fuzzer {
if p < 0 || p > 1 {
panic("p should be between 0 and 1, inclusive.")
}
f.nilChance = p
return f
}
// NumElements sets the minimum and maximum number of elements that will be
// added to a non-nil map or slice.
func (f *Fuzzer) NumElements(atLeast, atMost int) *Fuzzer {
if atLeast > atMost {
panic("atLeast must be <= atMost")
}
if atLeast < 0 {
panic("atLeast must be >= 0")
}
f.minElements = atLeast
f.maxElements = atMost
return f
}
func (f *Fuzzer) genElementCount() int {
if f.minElements == f.maxElements {
return f.minElements
}
return f.minElements + f.r.Intn(f.maxElements-f.minElements+1)
}
func (f *Fuzzer) genShouldFill() bool {
return f.r.Float64() > f.nilChance
}
// Fuzz recursively fills all of obj's fields with something random. First
// this tries to find a custom fuzz function (see Funcs). If there is no
// custom function this tests whether the object implements fuzz.Interface and,
// if so, calls Fuzz on it to fuzz itself. If that fails, this will see if
// there is a default fuzz function provided by this package. If all of that
// fails, this will generate random values for all primitive fields and then
// recurse for all non-primitives.
//
// Not safe for cyclic or tree-like structs!
//
// obj must be a pointer. Only exported (public) fields can be set (thanks, golang :/ )
// Intended for tests, so will panic on bad input or unimplemented fields.
func (f *Fuzzer) Fuzz(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
f.doFuzz(v, 0)
}
// FuzzNoCustom is just like Fuzz, except that any custom fuzz function for
// obj's type will not be called and obj will not be tested for fuzz.Interface
// conformance. This applies only to obj and not other instances of obj's
// type.
// Not safe for cyclic or tree-like structs!
// obj must be a pointer. Only exported (public) fields can be set (thanks, golang :/ )
// Intended for tests, so will panic on bad input or unimplemented fields.
func (f *Fuzzer) FuzzNoCustom(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
f.doFuzz(v, flagNoCustomFuzz)
}
const (
// Do not try to find a custom fuzz function. Does not apply recursively.
flagNoCustomFuzz uint64 = 1 << iota
)
func (f *Fuzzer) doFuzz(v reflect.Value, flags uint64) {
if !v.CanSet() {
return
}
if flags&flagNoCustomFuzz == 0 {
// Check for both pointer and non-pointer custom functions.
if v.CanAddr() && f.tryCustom(v.Addr()) {
return
}
if f.tryCustom(v) {
return
}
}
if fn, ok := fillFuncMap[v.Kind()]; ok {
fn(v, f.r)
return
}
switch v.Kind() {
case reflect.Map:
if f.genShouldFill() {
v.Set(reflect.MakeMap(v.Type()))
n := f.genElementCount()
for i := 0; i < n; i++ {
key := reflect.New(v.Type().Key()).Elem()
f.doFuzz(key, 0)
val := reflect.New(v.Type().Elem()).Elem()
f.doFuzz(val, 0)
v.SetMapIndex(key, val)
}
return
}
v.Set(reflect.Zero(v.Type()))
case reflect.Ptr:
if f.genShouldFill() {
v.Set(reflect.New(v.Type().Elem()))
f.doFuzz(v.Elem(), 0)
return
}
v.Set(reflect.Zero(v.Type()))
case reflect.Slice:
if f.genShouldFill() {
n := f.genElementCount()
v.Set(reflect.MakeSlice(v.Type(), n, n))
for i := 0; i < n; i++ {
f.doFuzz(v.Index(i), 0)
}
return
}
v.Set(reflect.Zero(v.Type()))
case reflect.Array:
if f.genShouldFill() {
n := v.Len()
for i := 0; i < n; i++ {
f.doFuzz(v.Index(i), 0)
}
return
}
v.Set(reflect.Zero(v.Type()))
case reflect.Struct:
for i := 0; i < v.NumField(); i++ {
f.doFuzz(v.Field(i), 0)
}
case reflect.Chan:
fallthrough
case reflect.Func:
fallthrough
case reflect.Interface:
fallthrough
default:
panic(fmt.Sprintf("Can't handle %#v", v.Interface()))
}
}
// tryCustom searches for custom handlers, and returns true iff it finds a match
// and successfully randomizes v.
func (f *Fuzzer) tryCustom(v reflect.Value) bool {
// First: see if we have a fuzz function for it.
doCustom, ok := f.fuzzFuncs[v.Type()]
if !ok {
// Second: see if it can fuzz itself.
if v.CanInterface() {
intf := v.Interface()
if fuzzable, ok := intf.(Interface); ok {
fuzzable.Fuzz(Continue{f: f, Rand: f.r})
return true
}
}
// Finally: see if there is a default fuzz function.
doCustom, ok = f.defaultFuzzFuncs[v.Type()]
if !ok {
return false
}
}
switch v.Kind() {
case reflect.Ptr:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.New(v.Type().Elem()))
}
case reflect.Map:
if v.IsNil() {
if !v.CanSet() {
return false
}
v.Set(reflect.MakeMap(v.Type()))
}
default:
return false
}
doCustom.Call([]reflect.Value{v, reflect.ValueOf(Continue{
f: f,
Rand: f.r,
})})
return true
}
// Interface represents an object that knows how to fuzz itself. Any time we
// find a type that implements this interface we will delegate the act of
// fuzzing itself.
type Interface interface {
Fuzz(c Continue)
}
// Continue can be passed to custom fuzzing functions to allow them to use
// the correct source of randomness and to continue fuzzing their members.
type Continue struct {
f *Fuzzer
// For convenience, Continue implements rand.Rand via embedding.
// Use this for generating any randomness if you want your fuzzing
// to be repeatable for a given seed.
*rand.Rand
}
// Fuzz continues fuzzing obj. obj must be a pointer.
func (c Continue) Fuzz(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
c.f.doFuzz(v, 0)
}
// FuzzNoCustom continues fuzzing obj, except that any custom fuzz function for
// obj's type will not be called and obj will not be tested for fuzz.Interface
// conformance. This applies only to obj and not other instances of obj's
// type.
func (c Continue) FuzzNoCustom(obj interface{}) {
v := reflect.ValueOf(obj)
if v.Kind() != reflect.Ptr {
panic("needed ptr!")
}
v = v.Elem()
c.f.doFuzz(v, flagNoCustomFuzz)
}
// RandString makes a random string up to 20 characters long. The returned string
// may include a variety of (valid) UTF-8 encodings.
func (c Continue) RandString() string {
return randString(c.Rand)
}
// RandUint64 makes random 64 bit numbers.
// Weirdly, rand doesn't have a function that gives you 64 random bits.
func (c Continue) RandUint64() uint64 {
return randUint64(c.Rand)
}
// RandBool returns true or false randomly.
func (c Continue) RandBool() bool {
return randBool(c.Rand)
}
func fuzzInt(v reflect.Value, r *rand.Rand) {
v.SetInt(int64(randUint64(r)))
}
func fuzzUint(v reflect.Value, r *rand.Rand) {
v.SetUint(randUint64(r))
}
func fuzzTime(t *time.Time, c Continue) {
var sec, nsec int64
// Allow for about 1000 years of random time values, which keeps things
// like JSON parsing reasonably happy.
sec = c.Rand.Int63n(1000 * 365 * 24 * 60 * 60)
c.Fuzz(&nsec)
*t = time.Unix(sec, nsec)
}
var fillFuncMap = map[reflect.Kind]func(reflect.Value, *rand.Rand){
reflect.Bool: func(v reflect.Value, r *rand.Rand) {
v.SetBool(randBool(r))
},
reflect.Int: fuzzInt,
reflect.Int8: fuzzInt,
reflect.Int16: fuzzInt,
reflect.Int32: fuzzInt,
reflect.Int64: fuzzInt,
reflect.Uint: fuzzUint,
reflect.Uint8: fuzzUint,
reflect.Uint16: fuzzUint,
reflect.Uint32: fuzzUint,
reflect.Uint64: fuzzUint,
reflect.Uintptr: fuzzUint,
reflect.Float32: func(v reflect.Value, r *rand.Rand) {
v.SetFloat(float64(r.Float32()))
},
reflect.Float64: func(v reflect.Value, r *rand.Rand) {
v.SetFloat(r.Float64())
},
reflect.Complex64: func(v reflect.Value, r *rand.Rand) {
panic("unimplemented")
},
reflect.Complex128: func(v reflect.Value, r *rand.Rand) {
panic("unimplemented")
},
reflect.String: func(v reflect.Value, r *rand.Rand) {
v.SetString(randString(r))
},
reflect.UnsafePointer: func(v reflect.Value, r *rand.Rand) {
panic("unimplemented")
},
}
// randBool returns true or false randomly.
func randBool(r *rand.Rand) bool {
if r.Int()&1 == 1 {
return true
}
return false
}
type charRange struct {
first, last rune
}
// choose returns a random unicode character from the given range, using the
// given randomness source.
func (r *charRange) choose(rand *rand.Rand) rune {
count := int64(r.last - r.first)
return r.first + rune(rand.Int63n(count))
}
var unicodeRanges = []charRange{
{' ', '~'}, // ASCII characters
{'\u00a0', '\u02af'}, // Multi-byte encoded characters
{'\u4e00', '\u9fff'}, // Common CJK (even longer encodings)
}
// randString makes a random string up to 20 characters long. The returned string
// may include a variety of (valid) UTF-8 encodings.
func randString(r *rand.Rand) string {
n := r.Intn(20)
runes := make([]rune, n)
for i := range runes {
runes[i] = unicodeRanges[r.Intn(len(unicodeRanges))].choose(r)
}
return string(runes)
}
// randUint64 makes random 64 bit numbers.
// Weirdly, rand doesn't have a function that gives you 64 random bits.
func randUint64(r *rand.Rand) uint64 {
return uint64(r.Uint32())<<32 | uint64(r.Uint32())
}