Skip to content

Commit 18d1aa5

Browse files
author
OpenShift Bot
authored
Merge pull request #9793 from smarterclayton/protobuf
Merged by openshift-bot
2 parents 6bfd721 + a230c74 commit 18d1aa5

File tree

100 files changed

+61611
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+61611
-625
lines changed

Godeps/Godeps.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

hack/copy-kube-artifacts.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ rsync -av \
5252
/test/fixtures/***
5353
/test/integration/***
5454
/third_party/golang/***
55+
/third_party/protobuf/***
5556
/README.md
5657
EOF
5758

hack/update-generated-clientsets.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [[ ! "$clientgen" ]]; then
1919
echo "It looks as if you don't have a compiled client-gen binary"
2020
echo
2121
echo "If you are running from a clone of the git repo, please run"
22-
echo "'./hack/build-go.sh Godeps/_workspace/src/k8s.io/kubernetes/cmd/libs/go2idl/client-gen'."
22+
echo "'./hack/build-go.sh vendor/k8s.io/kubernetes/cmd/libs/go2idl/client-gen'."
2323
} >&2
2424
exit 1
2525
fi

hack/update-generated-protobuf.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
8+
source "${OS_ROOT}/hack/lib/init.sh"
9+
10+
# Go to the top of the tree.
11+
cd "${OS_ROOT}"
12+
13+
if [[ -z "$(which protoc)" || "$(protoc --version)" != "libprotoc 3.0."* ]]; then
14+
echo "Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
15+
echo "install the platform appropriate Protobuf package for your OS: "
16+
echo
17+
echo " https://github.com/google/protobuf/releases"
18+
echo
19+
exit 1
20+
fi
21+
22+
os::build::setup_env
23+
24+
hack/build-go.sh tools/genprotobuf vendor/k8s.io/kubernetes/cmd/libs/go2idl/go-to-protobuf/protoc-gen-gogo
25+
genprotobuf="$( os::build::find-binary genprotobuf )"
26+
27+
if [[ -z "${genprotobuf}" ]]; then
28+
echo "It looks as if you don't have a compiled genprotobuf binary."
29+
echo
30+
echo "If you are running from a clone of the git repo, please run"
31+
echo "'./hack/build-go.sh tools/genprotobuf'."
32+
exit 1
33+
fi
34+
35+
${genprotobuf} --output-base="${GOPATH}/src" "$@"

hack/verify-generated-protobuf.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -o errexit
4+
set -o nounset
5+
set -o pipefail
6+
7+
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
8+
source "${OS_ROOT}/hack/lib/init.sh"
9+
10+
APIROOTS=${APIROOTS:-pkg}
11+
_tmp="${OS_ROOT}/_output/diff"
12+
13+
cleanup() {
14+
echo rm -rf "${_tmp}"
15+
}
16+
17+
trap "cleanup" EXIT SIGINT
18+
19+
cleanup
20+
for APIROOT in ${APIROOTS}; do
21+
mkdir -p "${_tmp}/${APIROOT%/*}"
22+
cp -rf "${OS_ROOT}/${APIROOT}" "${_tmp}/"
23+
done
24+
25+
"${OS_ROOT}/hack/update-generated-protobuf.sh"
26+
for APIROOT in ${APIROOTS}; do
27+
TMP_APIROOT="${_tmp}/${APIROOT}"
28+
echo "diffing ${APIROOT} against freshly generated protobuf"
29+
ret=0
30+
diff -Naupr -I 'Auto generated by' "${OS_ROOT}/${APIROOT}" "${TMP_APIROOT}" || ret=$?
31+
# cp -rf "${TMP_APIROOT}" "${OS_ROOT}/${APIROOT%/*}"
32+
if [[ $ret -eq 0 ]]; then
33+
echo "${APIROOT} up to date."
34+
else
35+
echo "${APIROOT} is out of date. Please run hack/update-generated-protobuf.sh"
36+
exit 1
37+
fi
38+
done

hack/verify-govet.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ DIR_BLACKLIST='./hack
5050
./pkg/project
5151
./pkg/quota
5252
./pkg/router
53+
./pkg/sdn
5354
./pkg/security
5455
./pkg/serviceaccounts
5556
./pkg/template

pkg/api/extension/extension.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,16 @@ func DecodeNestedRawExtensionOrUnknown(d runtime.Decoder, ext *runtime.RawExtens
7070
}
7171
obj, gvk, err := d.Decode(ext.Raw, nil, nil)
7272
if err != nil {
73-
// TODO: record mime-type with the object
7473
unk := &runtime.Unknown{Raw: ext.Raw}
74+
if runtime.IsNotRegisteredError(err) {
75+
if _, gvk, err := d.Decode(ext.Raw, nil, unk); err == nil {
76+
unk.APIVersion = gvk.GroupVersion().String()
77+
unk.Kind = gvk.Kind
78+
ext.Object = unk
79+
return
80+
}
81+
}
82+
// TODO: record mime-type with the object
7583
if gvk != nil {
7684
unk.APIVersion = gvk.GroupVersion().String()
7785
unk.Kind = gvk.Kind

pkg/api/serialization_test.go

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package api_test
22

33
import (
4+
"bytes"
5+
"encoding/hex"
46
"fmt"
57
"math/rand"
68
"reflect"
@@ -11,10 +13,12 @@ import (
1113
"github.com/google/gofuzz"
1214
kapi "k8s.io/kubernetes/pkg/api"
1315
"k8s.io/kubernetes/pkg/api/meta"
16+
"k8s.io/kubernetes/pkg/api/testapi"
1417
apitesting "k8s.io/kubernetes/pkg/api/testing"
1518
"k8s.io/kubernetes/pkg/api/unversioned"
1619
"k8s.io/kubernetes/pkg/api/validation"
1720
"k8s.io/kubernetes/pkg/runtime"
21+
"k8s.io/kubernetes/pkg/runtime/serializer/protobuf"
1822
"k8s.io/kubernetes/pkg/types"
1923
"k8s.io/kubernetes/pkg/util/diff"
2024
"k8s.io/kubernetes/pkg/util/intstr"
@@ -42,6 +46,16 @@ import (
4246
_ "k8s.io/kubernetes/pkg/api/install"
4347
)
4448

49+
var codecsToTest = []func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, error){
50+
func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, error) {
51+
return kapi.Codecs.LegacyCodec(version), nil
52+
},
53+
func(version unversioned.GroupVersion, item runtime.Object) (runtime.Codec, error) {
54+
s := protobuf.NewSerializer(kapi.Scheme, kapi.Scheme, "application/arbitrary.content.type")
55+
return kapi.Codecs.CodecForVersions(s, s, testapi.ExternalGroupVersions(), nil), nil
56+
},
57+
}
58+
4559
func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item runtime.Object, seed int64) runtime.Object {
4660
f := apitesting.FuzzerFor(t, forVersion, rand.NewSource(seed))
4761
f.Funcs(
@@ -130,7 +144,7 @@ func fuzzInternalObject(t *testing.T, forVersion unversioned.GroupVersion, item
130144
case 0:
131145
j.AttributeRestrictions = &authorizationapi.IsPersonalSubjectAccessReview{}
132146
case 1:
133-
j.AttributeRestrictions = &runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Type", APIVersion: "other"}, Raw: []byte(`{"apiVersion":"other","kind":"Type"}`)}
147+
j.AttributeRestrictions = &runtime.Unknown{TypeMeta: runtime.TypeMeta{Kind: "Type", APIVersion: "other"}, ContentType: "application/json", Raw: []byte(`{"apiVersion":"other","kind":"Type"}`)}
134148
default:
135149
j.AttributeRestrictions = nil
136150
}
@@ -439,6 +453,21 @@ func defaultHookContainerName(hook *deploy.LifecycleHook, containerName string)
439453
}
440454
}
441455

456+
func roundTripWithAllCodecs(t *testing.T, version unversioned.GroupVersion, item runtime.Object) {
457+
var codecs []runtime.Codec
458+
for _, fn := range codecsToTest {
459+
codec, err := fn(version, item)
460+
if err != nil {
461+
t.Errorf("unable to get codec: %v", err)
462+
return
463+
}
464+
codecs = append(codecs, codec)
465+
}
466+
for _, codec := range codecs {
467+
roundTrip(t, codec, item)
468+
}
469+
}
470+
442471
func roundTrip(t *testing.T, codec runtime.Codec, originalItem runtime.Object) {
443472
// Make a copy of the originalItem to give to conversion functions
444473
// This lets us know if conversion messed with the input object
@@ -453,7 +482,8 @@ func roundTrip(t *testing.T, codec runtime.Codec, originalItem runtime.Object) {
453482
data, err := runtime.Encode(codec, item)
454483
if err != nil {
455484
if runtime.IsNotRegisteredError(err) {
456-
t.Logf("%v is not registered", name)
485+
t.Logf("%v skipped: not registered: %v", name, err)
486+
return
457487
}
458488
t.Errorf("%v: %v (%#v)", name, err, item)
459489
return
@@ -474,7 +504,7 @@ func roundTrip(t *testing.T, codec runtime.Codec, originalItem runtime.Object) {
474504
}
475505

476506
if !kapi.Semantic.DeepEqual(originalItem, obj2) {
477-
t.Errorf("1: %v: diff: %v\nCodec: %v\nData: %s", name, diff.ObjectReflectDiff(originalItem, obj2), codec, string(data))
507+
t.Errorf("1: %v: diff: %v\nCodec: %v\nData: %s", name, diff.ObjectReflectDiff(originalItem, obj2), codec, dataToString(data))
478508
return
479509
}
480510

@@ -489,6 +519,13 @@ func roundTrip(t *testing.T, codec runtime.Codec, originalItem runtime.Object) {
489519
}
490520
}
491521

522+
func dataToString(s []byte) string {
523+
if bytes.HasPrefix(s, []byte("k8s")) {
524+
return "\n" + hex.Dump(s)
525+
}
526+
return string(s)
527+
}
528+
492529
// skipStandardVersions is a map of Kind to a list of API versions to test with.
493530
var skipStandardVersions = map[string][]unversioned.GroupVersion{
494531
// The API versions here are to test our object that serializes from/into
@@ -503,17 +540,20 @@ func TestSpecificKind(t *testing.T) {
503540
kapi.Scheme.Log(t)
504541
defer kapi.Scheme.Log(nil)
505542

506-
kind := "DeploymentConfig"
543+
kind := "ClusterRole"
507544
item, err := kapi.Scheme.New(osapi.SchemeGroupVersion.WithKind(kind))
508545
if err != nil {
509-
t.Errorf("Couldn't make a %v? %v", kind, err)
510-
return
546+
t.Fatalf("Couldn't make a %v? %v", kind, err)
547+
}
548+
codec, err := codecsToTest[1](v1.SchemeGroupVersion, nil)
549+
if err != nil {
550+
t.Fatal(err)
511551
}
512-
seed := int64(2703387474910584091) //rand.Int63()
552+
seed := int64(2703387474910584091)
513553
for i := 0; i < fuzzIters; i++ {
514554
//t.Logf(`About to test %v with "v1"`, kind)
515555
fuzzInternalObject(t, v1.SchemeGroupVersion, item, seed)
516-
roundTrip(t, kapi.Codecs.LegacyCodec(v1.SchemeGroupVersion), item)
556+
roundTrip(t, codec, item)
517557
}
518558
}
519559

@@ -558,7 +598,7 @@ func TestTypes(t *testing.T) {
558598
continue
559599
}
560600
fuzzInternalObject(t, externalVersion, item, seed)
561-
roundTrip(t, kapi.Codecs.LegacyCodec(externalVersion), item)
601+
roundTripWithAllCodecs(t, externalVersion, item)
562602
}
563603
}
564604
}

0 commit comments

Comments
 (0)