Skip to content

Commit fa0b96e

Browse files
mjudeikisgman0
authored andcommitted
Start wiring example for VMs
1 parent 6d805a4 commit fa0b96e

File tree

7 files changed

+242
-0
lines changed

7 files changed

+242
-0
lines changed
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: {}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
apiVersion: apis.kcp.io/v1alpha1
2+
kind: APIResourceSchema
3+
metadata:
4+
name: today.virtualmachines.machines.svm.io
5+
spec:
6+
group: machines.svm.io
7+
names:
8+
kind: VirtualMachine
9+
listKind: VirtualMachineList
10+
plural: virtualmachines
11+
singular: virtualmachine
12+
scope: Namespaced
13+
versions:
14+
- name: v1alpha1
15+
schema:
16+
description: VirtualMachine represents a virtual machine instance
17+
properties:
18+
apiVersion:
19+
description: 'APIVersion defines the versioned schema of this representation
20+
of an object. Servers should convert recognized schemas to the latest
21+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
22+
type: string
23+
kind:
24+
description: 'Kind is a string value representing the REST resource this
25+
object represents. Servers may infer this from the endpoint the client
26+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
27+
type: string
28+
metadata:
29+
type: object
30+
spec:
31+
description: VirtualMachineSpec holds the desired state of the VirtualMachine.
32+
properties:
33+
instanceRef:
34+
description: Reference to an Instance resource
35+
properties:
36+
name:
37+
description: Name of the Instance resource
38+
type: string
39+
namespace:
40+
description: Namespace of the Instance resource
41+
type: string
42+
required:
43+
- name
44+
type: object
45+
required:
46+
- instanceRef
47+
type: object
48+
status:
49+
description: VirtualMachineStatus communicates the observed state of the VirtualMachine.
50+
properties:
51+
phase:
52+
description: Current phase of the virtual machine
53+
type: string
54+
conditions:
55+
description: Current conditions of the virtual machine
56+
items:
57+
properties:
58+
type:
59+
type: string
60+
status:
61+
type: string
62+
lastTransitionTime:
63+
type: string
64+
reason:
65+
type: string
66+
message:
67+
type: string
68+
required:
69+
- type
70+
- status
71+
type: object
72+
type: array
73+
type: object
74+
type: object
75+
served: true
76+
storage: true
77+
subresources:
78+
status: {}

0 commit comments

Comments
 (0)