Skip to content

Commit fd32386

Browse files
Merge pull request #63913 from deads2k/controller-10-event
Automatic merge from submit-queue (batch tested with PRs 63598, 63913, 63459, 63963, 60464). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. fix event ref determination for apigroups The event ref determination was never updated to handle apigroups so it has been returning only a group (not a version). @kubernetes/sig-apps-bugs ```release-note event object references with apiversion will now report an apiversion. ``` Kubernetes-commit: 4810b9ba679f4fb9cc39f3a83bbcd23b3e4accce
2 parents d9cf977 + acfb32b commit fd32386

File tree

3 files changed

+129
-53
lines changed

3 files changed

+129
-53
lines changed

Godeps/Godeps.json

+51-51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/reference/ref.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ func GetReference(scheme *runtime.Scheme, obj runtime.Object) (*v1.ObjectReferen
8686
}
8787
// example paths: /<prefix>/<version>/*
8888
parts := strings.Split(selfLinkUrl.Path, "/")
89-
if len(parts) < 3 {
89+
if len(parts) < 4 {
9090
return nil, fmt.Errorf("unexpected self link format: '%v'; got version '%v'", selfLink, version)
9191
}
92-
version = parts[2]
92+
if parts[1] == "api" {
93+
version = parts[2]
94+
} else {
95+
version = parts[2] + "/" + parts[3]
96+
}
9397
}
9498

9599
// only has list metadata

tools/reference/ref_test.go

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package reference
18+
19+
import (
20+
"testing"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/apimachinery/pkg/runtime"
24+
"k8s.io/apimachinery/pkg/runtime/schema"
25+
)
26+
27+
type TestRuntimeObj struct {
28+
metav1.TypeMeta
29+
metav1.ObjectMeta
30+
}
31+
32+
func (o *TestRuntimeObj) DeepCopyObject() runtime.Object {
33+
panic("die")
34+
}
35+
36+
func TestGetReferenceRefVersion(t *testing.T) {
37+
tests := []struct {
38+
name string
39+
input *TestRuntimeObj
40+
expectedRefVersion string
41+
}{
42+
{
43+
name: "api from selflink",
44+
input: &TestRuntimeObj{
45+
ObjectMeta: metav1.ObjectMeta{SelfLink: "/api/v1/namespaces"},
46+
},
47+
expectedRefVersion: "v1",
48+
},
49+
{
50+
name: "foo.group/v3 from selflink",
51+
input: &TestRuntimeObj{
52+
ObjectMeta: metav1.ObjectMeta{SelfLink: "/apis/foo.group/v3/namespaces"},
53+
},
54+
expectedRefVersion: "foo.group/v3",
55+
},
56+
}
57+
58+
scheme := runtime.NewScheme()
59+
scheme.AddKnownTypes(schema.GroupVersion{Group: "this", Version: "is ignored"}, &TestRuntimeObj{})
60+
61+
for _, test := range tests {
62+
t.Run(test.name, func(t *testing.T) {
63+
ref, err := GetReference(scheme, test.input)
64+
if err != nil {
65+
t.Fatal(err)
66+
}
67+
if test.expectedRefVersion != ref.APIVersion {
68+
t.Errorf("expected %q, got %q", test.expectedRefVersion, ref.APIVersion)
69+
}
70+
})
71+
}
72+
}

0 commit comments

Comments
 (0)