Skip to content

Commit

Permalink
Merge pull request #106 from ThomasK33/thomaskosiewski/eng-4408-updat…
Browse files Browse the repository at this point in the history
…e-vcluster-sdk-examples
  • Loading branch information
ThomasK33 authored Sep 25, 2024
2 parents 06b25ea + ff8043c commit e80d7c9
Show file tree
Hide file tree
Showing 236 changed files with 58,900 additions and 4,122 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

### **[Website](https://www.vcluster.com)****[Documentation](https://www.vcluster.com/docs/what-are-virtual-clusters)****[Blog](https://loft.sh/blog)****[Twitter](https://twitter.com/loft_sh)****[Slack](https://slack.loft.sh/)**

This project holds the official vcluster SDK, which can be used to develop plugins for [vcluster](https://github.com/loft-sh/vcluster). Plugins are a feature to extend the capabilities of vcluster. They allow you to add custom functionality, such as:
This project holds the official vCluster SDK, which can be used to develop plugins
for [vCluster](https://github.com/loft-sh/vcluster). Plugins are a feature to
extend the capabilities of vCluster. They allow you to add custom functionality,
such as:

1. Syncing specific resources from or to the virtual clusters including cluster scoped resources like cluster roles.
1. Syncing specific resources from or to the virtual clusters including cluster
scoped resources like cluster roles.
2. Syncing custom resources from or to the virtual cluster.
3. Deploying resources on virtual cluster startup, such as CRDs, applications etc.
4. Manage resources and applications inside the host or virtual cluster.
5. Enforcing certain restrictions on synced resources or extending the existing syncers of vcluster.
6. Any other operator use case that could benefit from having access to the virtual cluster as well the host cluster at the same time.
5. Enforcing certain restrictions on synced resources or extending the existing
syncers of vCluster.
6. Any other operator use case that could benefit from having access to the
virtual cluster as well the host cluster at the same time.

To learn more about plugins, please take a look at the [vcluster documentation](https://www.vcluster.com/docs/plugins/overview) or [our plugin examples](https://github.com/loft-sh/vcluster-sdk/tree/main/examples).
To learn more about plugins, please take a look at the
[vCluster documentation](https://vcluster.com/docs/vcluster/next/configure/vcluster-yaml/plugins?x0=1)
or [our plugin examples](https://github.com/loft-sh/vcluster-sdk/tree/main/examples).
3 changes: 2 additions & 1 deletion e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
ginkgo "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

// Enable cloud provider auth
_ "k8s.io/client-go/plugin/pkg/client/auth"

Expand All @@ -32,7 +33,7 @@ func TestRunE2ETests(t *testing.T) {
log.GetInstance().Fatalf("Error setting up framework: %v", err)
}

var _ = ginkgo.AfterSuite(func() {
_ = ginkgo.AfterSuite(func() {
err = framework.DefaultFramework.Cleanup()
if err != nil {
log.GetInstance().Warnf("Error executing testsuite cleanup: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions e2e/test_plugin/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Build the manager binary
FROM golang:1.22 as builder
FROM golang:1.23 as builder

# Make sure we use go modules
WORKDIR vcluster
WORKDIR /vcluster

# Copy the Go Modules manifests
COPY . .
Expand Down
3 changes: 1 addition & 2 deletions e2e/test_plugin/apis/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ type CarSpec struct {
Seats int `json:"seats,omitempty"`
}

type CarStatus struct {
}
type CarStatus struct{}

// CarType is the type of the car
type CarType string
Expand Down
3 changes: 2 additions & 1 deletion e2e/test_plugin/manifests/audi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ metadata:
name: audi-a4
spec:
type: "Audi"
seats: 4
seats: 4

69 changes: 35 additions & 34 deletions e2e/test_plugin/manifests/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,44 @@ spec:
singular: car
scope: Namespaced
versions:
- name: v1
schema:
openAPIV3Schema:
description: Car holds the webhook configuration
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
properties:
seats:
description: Number of seats within the car
type: integer
type:
description: Type is the type of the car
type: string
type: object
status:
type: object
type: object
served: true
storage: true
subresources:
status: {}
- name: v1
schema:
openAPIV3Schema:
description: Car holds the webhook configuration
properties:
apiVersion:
description:
"APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources"
type: string
kind:
description:
"Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds"
type: string
metadata:
type: object
spec:
properties:
seats:
description: Number of seats within the car
type: integer
type:
description: Type is the type of the car
type: string
type: object
status:
type: object
type: object
served: true
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []

4 changes: 2 additions & 2 deletions e2e/test_plugin/manifests/mydeployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ spec:
app: mydeployment
spec:
containers:
- name: mydeployment
image: k8s.gcr.io/pause:3.2
- name: mydeployment
image: k8s.gcr.io/pause:3.2
3 changes: 2 additions & 1 deletion e2e/test_plugin/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ plugin:
extraRules:
- apiGroups: ["example.loft.sh"]
resources: ["cars"]
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
verbs:
["create", "delete", "patch", "update", "get", "list", "watch"]
clusterRole:
extraRules:
- apiGroups: ["apiextensions.k8s.io"]
Expand Down
6 changes: 3 additions & 3 deletions e2e/test_plugin/syncers/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import (

var _ plugin.Interceptor = DummyInterceptor{}

type DummyInterceptor struct {
}
type DummyInterceptor struct{}

func (d DummyInterceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
scheme := runtime.NewScheme()
Expand All @@ -31,7 +30,8 @@ func (d DummyInterceptor) ServeHTTP(w http.ResponseWriter, r *http.Request) {
negotiation.DefaultEndpointRestrictions,
schema.GroupVersion{
Group: "",
Version: "v1"},
Version: "v1",
},
w,
r,
200,
Expand Down
4 changes: 2 additions & 2 deletions examples/bootstrap-with-deployment/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Build the manager binary
FROM golang:1.22.2 as builder
FROM golang:1.23 as builder

# Make sure we use go modules
WORKDIR vcluster
WORKDIR /vcluster

# Copy the Go Modules manifests
COPY . .
Expand Down
52 changes: 33 additions & 19 deletions examples/bootstrap-with-deployment/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
## Bootstrap With Deployment Plugin
# Bootstrap With Deployment Plugin

This example plugin applies a deployment manifest file in the vcluster on startup.
This example plugin applies a deployment manifest file in the vCluster on startup.

For more information how to develop plugins in vcluster, please refer to the [official vcluster docs](https://www.vcluster.com/docs/plugins/overview).
For more information how to develop plugins in vCluster, please refer to the
[official vCluster docs](https://www.vcluster.com/docs/plugins/overview).

## Using the Plugin

To use the plugin, create a new vcluster with the `plugin.yaml`:
To use the plugin, create a new vCluster with the `plugin.yaml`:

```
```bash
# Use public plugin.yaml
vcluster create my-vcluster -n my-vcluster -f https://raw.githubusercontent.com/loft-sh/vcluster-sdk/main/examples/bootstrap-with-deployment/plugin.yaml
```

After that, wait for vcluster to start up and check:
After that, wait for vCluster to start up and check:

```
```bash
# Check if deployment is in vcluster
vcluster connect my-vcluster -n my-vcluster -- kubectl get deployments

Expand All @@ -24,8 +25,10 @@ kubectl get po -n my-vcluster
```

## Building the Plugin

To just build the plugin image and push it to the registry, run:
```

```bash
# Make sure vendor is updated
go mod vendor

Expand All @@ -40,8 +43,9 @@ Then exchange the image in the `plugin.yaml`.

## Development

General vcluster plugin project structure:
```
General vCluster plugin project structure:

```text
.
├── go.mod # Go module definition
├── go.sum
Expand All @@ -54,26 +58,36 @@ General vcluster plugin project structure:
└── manifests/ # Additional plugin resources
```

Before starting to develop, make sure you have installed the following tools on your computer:
Before starting to develop, make sure you have installed the following tools on
your computer:

- [docker](https://docs.docker.com/)
- [kubectl](https://kubernetes.io/docs/tasks/tools/) with a valid kube context configured
- [helm](https://helm.sh/docs/intro/install/), which is used to deploy vcluster and the plugin
- [vcluster CLI](https://www.vcluster.com/docs/getting-started/setup) v0.20.0 or higher
- [DevSpace](https://devspace.sh/cli/docs/quickstart), which is used to spin up a development environment
- [helm](https://helm.sh/docs/intro/install/), which is used to deploy vCluster
and the plugin
- [vCluster CLI](https://www.vcluster.com/docs/getting-started/setup) v0.20.0 or
higher
- [DevSpace](https://devspace.sh/cli/docs/quickstart), which is used to spin up
a development environment

After successfully setting up the tools, start the development environment with:
```

```bash
devspace dev -n vcluster
```

After a while a terminal should show up with additional instructions. Enter the following command to start the plugin:
```
After a while a terminal should show up with additional instructions. Enter the
following command to start the plugin:

```bash
go build -mod vendor -o plugin main.go && /vcluster/syncer start
```

You can now change a file locally in your IDE and then restart the command in the terminal to apply the changes to the plugin.
You can now change a file locally in your IDE and then restart the command in the
terminal to apply the changes to the plugin.

Delete the development environment with:
```

```bash
devspace purge -n vcluster
```
8 changes: 4 additions & 4 deletions examples/bootstrap-with-deployment/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ deployments:
chart:
name: vcluster
repo: https://charts.loft.sh
version: v0.20.0-beta.5
version: v0.20.0
values:
controlPlane:
advanced:
serviceAccount:
serviceAccount:
enabled: false
name: default
statefulSet:
statefulSet:
probes:
livenessProbe:
enabled: false
Expand All @@ -37,7 +37,7 @@ deployments:
dev:
vcluster:
imageSelector: "ghcr.io/loft-sh/vcluster-pro"
devImage: golang:1.22.2
devImage: golang:1.23
workingDir: /plugins/bootstrap-with-deployment
container: syncer
terminal:
Expand Down
Loading

0 comments on commit e80d7c9

Please sign in to comment.