Skip to content

Commit 0269efc

Browse files
committed
Fix virutal workspace OpenAPI v3 endpoint panics
Signed-off-by: Marko Mudrinić <[email protected]> On-behalf-of: @SAP [email protected]
1 parent cb91839 commit 0269efc

File tree

5 files changed

+95
-7
lines changed

5 files changed

+95
-7
lines changed

pkg/virtual/framework/dynamic/apiserver/openapi.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ func (o *openAPIHandler) handleOpenAPIRequest(apiSet apidefinition.APIDefinition
228228
}
229229

230230
groupPath := "apis/" + gv.Group
231-
webservices[groupPath] = append(webservices[groupPath], discovery.NewAPIGroupHandler(codecs, apiGroup).WebService())
231+
if _, ok := webservices[groupPath]; !ok {
232+
webservices[groupPath] = append(webservices[groupPath], discovery.NewAPIGroupHandler(codecs, apiGroup).WebService())
233+
}
232234
}
233235

234236
// Build OpenAPI v3 spec for /apis/<group> webservices
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
apiVersion: apis.kcp.io/v1alpha1
2+
kind: APIResourceSchema
3+
metadata:
4+
name: today.cowboys.wildwest.dev
5+
spec:
6+
group: wildwest.dev
7+
names:
8+
kind: Cowboy
9+
listKind: CowboyList
10+
plural: cowboys
11+
singular: cowboy
12+
scope: Namespaced
13+
conversion:
14+
strategy: None
15+
versions:
16+
- name: v1alpha1
17+
schema:
18+
description: Cowboy is part of the wild west
19+
properties:
20+
apiVersion:
21+
description: 'APIVersion defines the versioned schema of this representation
22+
of an object. Servers should convert recognized schemas to the latest
23+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
24+
type: string
25+
kind:
26+
description: 'Kind is a string value representing the REST resource this
27+
object represents. Servers may infer this from the endpoint the client
28+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
29+
type: string
30+
metadata:
31+
type: object
32+
spec:
33+
description: CowboySpec holds the desired state of the Cowboy.
34+
properties:
35+
intent:
36+
type: string
37+
type: object
38+
status:
39+
description: CowboyStatus communicates the observed state of the Cowboy.
40+
properties:
41+
result:
42+
type: string
43+
type: object
44+
type: object
45+
served: true
46+
storage: true
47+
subresources:
48+
status: {}
49+
- name: v1alpha2
50+
schema:
51+
description: Cowboy is part of the wild west
52+
properties:
53+
apiVersion:
54+
description: 'APIVersion defines the versioned schema of this representation
55+
of an object. Servers should convert recognized schemas to the latest
56+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
57+
type: string
58+
kind:
59+
description: 'Kind is a string value representing the REST resource this
60+
object represents. Servers may infer this from the endpoint the client
61+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
62+
type: string
63+
metadata:
64+
type: object
65+
spec:
66+
description: CowboySpec holds the desired state of the Cowboy.
67+
properties:
68+
intent:
69+
type: string
70+
type: object
71+
status:
72+
description: CowboyStatus communicates the observed state of the Cowboy.
73+
properties:
74+
result:
75+
type: string
76+
type: object
77+
type: object
78+
served: true
79+
storage: false
80+
subresources:
81+
status: {}

test/e2e/virtual/apiexport/binding_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func TestAPIBindingPermissionClaimsVerbs(t *testing.T) {
262262
permissionClaims := defaultPermissionsClaims(identityHash, pcModifiers...)
263263

264264
t.Logf("set up service provider with permission claims")
265-
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClusterClient, providerPath, cfg, permissionClaims)
265+
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClusterClient, false, providerPath, cfg, permissionClaims)
266266

267267
t.Logf("set up binding")
268268
bindConsumerToProvider(ctx, t, consumerPath, providerPath, kcpClusterClient, cfg, permissionClaimsToAcceptable(permissionClaims)...)

test/e2e/virtual/apiexport/openapi_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestAPIExportOpenAPI(t *testing.T) {
6767

6868
framework.AdmitWorkspaceAccess(ctx, t, kubeClusterClient, serviceProviderPath, []string{"user-1"}, nil, false)
6969

70-
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClients, serviceProviderPath, cfg, nil)
70+
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClients, true, serviceProviderPath, cfg, nil)
7171

7272
t.Logf("Waiting for APIExport to have a virtual workspace URL for the bound workspace %q", consumerWorkspace.Name)
7373
apiExportVWCfg := rest.CopyConfig(cfg)

test/e2e/virtual/apiexport/virtualworkspace_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func TestAPIExportVirtualWorkspace(t *testing.T) {
103103

104104
framework.AdmitWorkspaceAccess(ctx, t, kubeClusterClient, serviceProviderPath, []string{"user-1"}, nil, false)
105105

106-
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClients, serviceProviderPath, cfg, nil)
106+
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClients, false, serviceProviderPath, cfg, nil)
107107
bindConsumerToProvider(ctx, t, consumerPath, serviceProviderPath, kcpClients, cfg)
108108
createCowboyInConsumer(ctx, t, consumerPath, wildwestClusterClient)
109109

@@ -1007,18 +1007,23 @@ func defaultPermissionsClaims(identityHash string, modifiers ...func([]apisv1alp
10071007
func setUpServiceProviderWithPermissionClaims(ctx context.Context, t *testing.T, dynamicClusterClient kcpdynamic.ClusterInterface, kcpClients kcpclientset.ClusterInterface, serviceProviderWorkspace logicalcluster.Path, cfg *rest.Config, identityHash string) {
10081008
t.Helper()
10091009

1010-
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClients, serviceProviderWorkspace, cfg, defaultPermissionsClaims(identityHash))
1010+
setUpServiceProvider(ctx, t, dynamicClusterClient, kcpClients, false, serviceProviderWorkspace, cfg, defaultPermissionsClaims(identityHash))
10111011
}
10121012

1013-
func setUpServiceProvider(ctx context.Context, t *testing.T, dynamicClusterClient kcpdynamic.ClusterInterface, kcpClients kcpclientset.ClusterInterface, serviceProviderWorkspace logicalcluster.Path, cfg *rest.Config, claims []apisv1alpha2.PermissionClaim) {
1013+
func setUpServiceProvider(ctx context.Context, t *testing.T, dynamicClusterClient kcpdynamic.ClusterInterface, kcpClients kcpclientset.ClusterInterface, multipleVersions bool, serviceProviderWorkspace logicalcluster.Path, cfg *rest.Config, claims []apisv1alpha2.PermissionClaim) {
10141014
t.Helper()
10151015
t.Logf("Install today cowboys APIResourceSchema into service provider workspace %q", serviceProviderWorkspace)
10161016

10171017
serviceProviderClient, err := kcpclientset.NewForConfig(cfg)
10181018
require.NoError(t, err)
10191019

1020+
apiResPath := "apiresourceschema_cowboys.yaml"
1021+
if multipleVersions {
1022+
apiResPath = "apiresourceschema_cowboys_versions.yaml"
1023+
}
1024+
10201025
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(serviceProviderClient.Cluster(serviceProviderWorkspace).Discovery()))
1021-
err = helpers.CreateResourceFromFS(ctx, dynamicClusterClient.Cluster(serviceProviderWorkspace), mapper, nil, "apiresourceschema_cowboys.yaml", testFiles)
1026+
err = helpers.CreateResourceFromFS(ctx, dynamicClusterClient.Cluster(serviceProviderWorkspace), mapper, nil, apiResPath, testFiles)
10221027
require.NoError(t, err)
10231028

10241029
t.Logf("Create an APIExport for it")

0 commit comments

Comments
 (0)