Skip to content

Commit 42bbf84

Browse files
authored
Merge pull request #3620 from gman0/virtual-resources
Add virtual resources
2 parents 135ad4c + fa0b96e commit 42bbf84

File tree

75 files changed

+5373
-3641
lines changed

Some content is hidden

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

75 files changed

+5373
-3641
lines changed

config/crds/apis.kcp.io_apiexports.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ spec:
470470
oneOf:
471471
- required:
472472
- crd
473+
- required:
474+
- virtual
473475
properties:
474476
crd:
475477
description: |-
@@ -478,7 +480,48 @@ spec:
478480
Like in vanilla Kubernetes, users can then create, update and delete
479481
custom resources.
480482
type: object
483+
virtual:
484+
description: |-
485+
Virtual storage defines that this APIResourceSchema is exposed as
486+
a projection of the referenced resource inside the workspaces that
487+
bind to the APIExport.
488+
properties:
489+
identityHash:
490+
description: IdentityHash is the identity of the virtual
491+
resource.
492+
type: string
493+
reference:
494+
description: |-
495+
Reference points to another object that has a URL to a virtual workspace
496+
in a "url" field in its status. The object can be of any kind.
497+
properties:
498+
apiGroup:
499+
description: |-
500+
APIGroup is the group for the resource being referenced.
501+
If APIGroup is not specified, the specified Kind must be in the core API group.
502+
For any other third-party types, APIGroup is required.
503+
type: string
504+
kind:
505+
description: Kind is the type of resource being
506+
referenced
507+
type: string
508+
name:
509+
description: Name is the name of resource being
510+
referenced
511+
type: string
512+
required:
513+
- kind
514+
- name
515+
type: object
516+
x-kubernetes-map-type: atomic
517+
required:
518+
- identityHash
519+
- reference
520+
type: object
481521
type: object
522+
x-kubernetes-validations:
523+
- message: Exactly one of crd or virtual must be set
524+
rule: has(self.crd) != has(self.virtual)
482525
required:
483526
- group
484527
- name

config/crds/apis.kcp.io_apiexports.yaml-patch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
path: /spec/versions/name=v1alpha2/schema/openAPIV3Schema/properties/spec/properties/resources/items/properties/storage/oneOf
1818
value:
1919
- required: ["crd"]
20+
- required: ["virtual"]
2021

2122
# conversion for core resources does not happen via webhooks, but is short-circuited to the
2223
# schema's Convert functions directly, but the CRD still needs to define a conversion.

config/crds/cache.kcp.io_cachedresourceendpointslices.yaml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ spec:
6565
x-kubernetes-validations:
6666
- message: CachedResource reference must not be changed
6767
rule: self == oldSelf
68+
partition:
69+
description: |-
70+
partition points to a partition that is used for filtering the endpoints
71+
of the CachedResource part of the slice.
72+
type: string
6873
required:
6974
- cachedResource
7075
type: object
@@ -73,6 +78,52 @@ spec:
7378
status communicates the observed state:
7479
the filtered list of endpoints for the Replication service.
7580
properties:
81+
conditions:
82+
description: conditions is a list of conditions that apply to the
83+
CachedResourceEndpointSlice.
84+
items:
85+
description: Condition defines an observation of a object operational
86+
state.
87+
properties:
88+
lastTransitionTime:
89+
description: |-
90+
Last time the condition transitioned from one status to another.
91+
This should be when the underlying condition changed. If that is not known, then using the time when
92+
the API field changed is acceptable.
93+
format: date-time
94+
type: string
95+
message:
96+
description: |-
97+
A human readable message indicating details about the transition.
98+
This field may be empty.
99+
type: string
100+
reason:
101+
description: |-
102+
The reason for the condition's last transition in CamelCase.
103+
The specific API may choose whether or not this field is considered a guaranteed API.
104+
This field may not be empty.
105+
type: string
106+
severity:
107+
description: |-
108+
Severity provides an explicit classification of Reason code, so the users or machines can immediately
109+
understand the current situation and act accordingly.
110+
The Severity field MUST be set only when Status=False.
111+
type: string
112+
status:
113+
description: Status of the condition, one of True, False, Unknown.
114+
type: string
115+
type:
116+
description: |-
117+
Type of condition in CamelCase or in foo.example.com/CamelCase.
118+
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions
119+
can be useful (see .node.status.conditions), the ability to deconflict is important.
120+
type: string
121+
required:
122+
- lastTransitionTime
123+
- status
124+
- type
125+
type: object
126+
type: array
76127
endpoints:
77128
description: endpoints contains all the URLs of the Replication service.
78129
items:
@@ -90,6 +141,12 @@ spec:
90141
x-kubernetes-list-map-keys:
91142
- url
92143
x-kubernetes-list-type: map
144+
shardSelector:
145+
description: |-
146+
shardSelector is the selector used to filter the shards. It is used to filter the shards
147+
when determining partition scope when deriving the endpoints. This is set by owning shard,
148+
and is used by follower shards to determine if its inscope or not.
149+
type: string
93150
type: object
94151
type: object
95152
served: true

config/crds/cache.kcp.io_cachedresources.yaml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -216,42 +216,6 @@ spec:
216216
- cache
217217
- local
218218
type: object
219-
resourceSchemaSource:
220-
description: ResourceSchemaSource is a reference to the schema object
221-
of the cached resource.
222-
properties:
223-
apiResourceSchema:
224-
description: APIResourceSchema defines an APIResourceSchema as
225-
the source of the schema.
226-
properties:
227-
clusterName:
228-
description: ClusterName is the name of the cluster where
229-
the APIResourceSchema is defined.
230-
minLength: 1
231-
type: string
232-
name:
233-
description: Name is the APIResourceSchema name.
234-
minLength: 1
235-
type: string
236-
required:
237-
- clusterName
238-
- name
239-
type: object
240-
crd:
241-
description: CRD defines a CRD as the source of the schema.
242-
properties:
243-
name:
244-
description: Name is the CRD name.
245-
minLength: 1
246-
type: string
247-
resourceVersion:
248-
description: ResourceVersion is the resource version of the
249-
source CRD object.
250-
type: string
251-
required:
252-
- name
253-
type: object
254-
type: object
255219
type: object
256220
required:
257221
- spec
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# VirtualResources Example
2+
3+
This example shows usage of VirtualResources, together with CachedResources.
4+
The goal of VirtualResources is to distribute static, read-only resources to multiple clusters
5+
in a scalable way.
6+
7+
## Setup
8+
9+
1. Start kcp with sharded setup:
10+
11+
```bash
12+
make test-run-sharded-server
13+
```
14+
15+
2. Create a provider workspace, where we will create the resources to be distributed:
16+
17+
```bash
18+
export KUBECONFIG=.kcp/admin.kubeconfig
19+
kubectl ws create provider --enter
20+
21+
kubectl create -f config/examples/virtualresources/crd-instances.yaml
22+
# this this to work we always require apiresource schema to be present
23+
kubectl create -f config/examples/virtualresources/apiresourceschema-instances.yaml
24+
kubectl create -f config/examples/virtualresources/instances.yaml
25+
26+
# create caching for the resources
27+
kubectl create -f config/examples/virtualresources/cached-resource-instances.yaml
28+
```
29+
30+
3. Create a an APIResourceSchema for actual virtual machines to be distributed,
31+
which will be using instance types.
32+
33+
```bash
34+
kubectl create -f config/examples/virtualresources/apiresourceschema-virtualmachine.yaml
35+
```
36+
37+
4. Create an APIExport for the virtual machines:
38+
39+
```bash
40+
kubectl create -f config/examples/virtualresources/apiexport.yaml
41+
```
42+
43+
5. Create a consumer workspace, where we will consume the virtual machines:
44+
45+
```bash
46+
kubectl ws use :root
47+
kubectl ws create consumer --enter
48+
kubectl kcp bind apiexport root:provider:virtualmachines virtualmachines
49+
```
50+
51+
6. Now check if we can see instances in the consumer workspace:
52+
53+
```bash
54+
kubectl get instances.machines.svm.io
55+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apis.kcp.io/v1alpha2
2+
kind: APIExport
3+
metadata:
4+
name: virtualmachines
5+
spec:
6+
resources:
7+
- name: instances
8+
group: machines.svm.io
9+
schema: today.instances.machines.svm.io
10+
storage:
11+
virtual:
12+
reference:
13+
apiGroup: cache.kcp.io
14+
kind: CachedResourceEndpointSlice
15+
name: instances
16+
identityHash: 2857921554ab76ec50f25bf083b7aeb4f7808cd169fd2945b007429f426614ec
17+
- name: virtualmachines
18+
group: machines.svm.io
19+
schema: today.virtualmachines.machines.svm.io
20+
storage:
21+
crd: {}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
apiVersion: apis.kcp.io/v1alpha1
2+
kind: APIResourceSchema
3+
metadata:
4+
name: today.instances.machines.svm.io
5+
spec:
6+
group: machines.svm.io
7+
names:
8+
kind: Instance
9+
listKind: InstanceList
10+
plural: instances
11+
singular: instance
12+
shortNames:
13+
- inst
14+
scope: Cluster
15+
versions:
16+
- name: v1alpha1
17+
schema:
18+
description: Instance represents a virtual machine instance
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: InstanceSpec holds the desired state of the Instance.
34+
properties:
35+
instanceType:
36+
description: The type of the instance (e.g. small, medium, large)
37+
type: string
38+
name:
39+
description: The name of the instance
40+
type: string
41+
tier:
42+
description: The tier of the instance (e.g. basic, premium)
43+
type: string
44+
enum:
45+
- basic
46+
- premium
47+
- enterprise
48+
required:
49+
- instanceType
50+
- name
51+
- tier
52+
type: object
53+
status:
54+
description: InstanceStatus communicates the observed state of the Instance.
55+
properties:
56+
phase:
57+
description: The current phase of the instance
58+
type: string
59+
enum:
60+
- Pending
61+
- Running
62+
- Terminated
63+
conditions:
64+
description: Current conditions of the instance
65+
items:
66+
properties:
67+
type:
68+
type: string
69+
status:
70+
type: string
71+
lastTransitionTime:
72+
type: string
73+
format: date-time
74+
reason:
75+
type: string
76+
message:
77+
type: string
78+
required:
79+
- type
80+
- status
81+
type: object
82+
type: array
83+
type: object
84+
type: object
85+
served: true
86+
storage: true
87+
subresources:
88+
status: {}

0 commit comments

Comments
 (0)