Skip to content

Commit 759c2c5

Browse files
authored
major: Support for vCluster 0.21.0 and up. Dropping support for previous versions. (#5)
1 parent 4b08096 commit 759c2c5

36 files changed

+1273
-3731
lines changed

.e2e/chainsaw-tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ spec:
2121
values:
2222
- my-virtual-namespace
2323
matchLabels:
24-
vcluster.loft.sh/label-vcluster-x-a172cedcae: example-app
24+
app: example-app
2525
---
2626
apiVersion: chainsaw.kyverno.io/v1alpha1
2727
kind: Test
@@ -47,7 +47,7 @@ spec:
4747
values:
4848
- default
4949
matchLabels:
50-
vcluster.loft.sh/label-vcluster-x-a172cedcae: example-app
50+
app: example-app
5151
---
5252
apiVersion: chainsaw.kyverno.io/v1alpha1
5353
kind: Test
@@ -72,7 +72,7 @@ spec:
7272
values:
7373
- my-virtual-namespace
7474
matchLabels:
75-
vcluster.loft.sh/label-vcluster-x-a172cedcae: example-app
75+
app: example-app
7676
---
7777
apiVersion: chainsaw.kyverno.io/v1alpha1
7878
kind: Test
@@ -97,4 +97,4 @@ spec:
9797
values:
9898
- default
9999
matchLabels:
100-
vcluster.loft.sh/label-vcluster-x-a172cedcae: example-app
100+
app: example-app

v2/.e2e/scripts/init.sh renamed to .e2e/scripts/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
PLUGIN_IMAGE=$1
55
MYDIR=$(dirname $0)
66
ROOT_DIR=$MYDIR/../../
7-
RESOURCES_FILE=$MYDIR/../../../.e2e/vcluster-resources.yaml
7+
RESOURCES_FILE=$MYDIR/../../.e2e/vcluster-resources.yaml
88

99
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.70.0/example/prometheus-operator-crd-full/monitoring.coreos.com_podmonitors.yaml
1010
kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/v0.70.0/example/prometheus-operator-crd-full/monitoring.coreos.com_servicemonitors.yaml

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# syntax=docker.io/docker/dockerfile-upstream:1.14.1-labs
2+
3+
# Build the manager binary
4+
FROM golang:1.23.2 AS builder
5+
WORKDIR /vcluster
6+
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.sum /vcluster/
9+
10+
# Install dependencies
11+
RUN go mod download
12+
13+
# Copy the sources
14+
COPY --parents pkg main.go /vcluster/
15+
16+
# Build plugin
17+
RUN CGO_ENABLED=0 go build -o /plugin main.go
18+
19+
# we use alpine for easier debugging
20+
FROM alpine
21+
WORKDIR /plugin
22+
COPY --from=builder /plugin .

README.md

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,82 @@ This repository contains a [vCluster plugin](https://www.vcluster.com/docs/v0.19
66

77
Currently only the very basic functionality is implemented so the plugin only supports syncing of `PodMonitor` and `ServiceMonitor` resources. This is to allow scraping of metrics from workloads running on virtual clusters from a signle Prometheus or Open Telemetry collector on the host (with [target allocator](https://github.com/open-telemetry/opentelemetry-operator/blob/main/cmd/otel-allocator/README.md) that supports Prometheus operator CRDs).
88

9-
The repository contains 2 versions of the plugin, each version is compatible with different versions of vCluster, but both versions provide the same functionality.
10-
This compatibility is required as Syncer arhitecture was overhauled by loft.sh in version 0.20.0 and plugin-sdk changed accordingly.
9+
This plugin is compatibe with vCluster version `0.21.0` and above, tested on `v0.23.0`, which was latest at the time of writing this plugin.
1110

12-
`v1` - Compatible with older versions of vCluster - latest confirmed & tested version is `0.16.4`
11+
# Development
1312

14-
`v2` - Compatibe with vCluster version `0.20.0-beta.9` which was the latest version at the time of writing.
13+
For more information how to develop plugins in vcluster, please refer to the [official vcluster docs](https://www.vcluster.com/docs/plugins/overview).
14+
15+
## Using the Plugin in vcluster
16+
17+
To use the plugin, create a new vcluster with the `plugin.yaml`:
18+
19+
```
20+
# Deploy Prometheus operator on host cluster with Helm:
21+
For more info see -https://artifacthub.io/packages/helm/prometheus-community/kube-prometheus-stack?modal=install
22+
23+
# Create vcluster with plugin
24+
vcluster create my-vcluster -n my-vcluster -f https://raw.githubusercontent.com/codefresh-contrib/vcluster-prometheus-operator-plugin/main/v2/plugin.yaml
25+
```
26+
27+
This will create a new vcluster with the plugin installed. Then test the plugin with:
28+
29+
```
30+
# Apply example ServicerMonitor
31+
vcluster connect my-vcluster -n my-vcluster -- kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/main/example/user-guides/getting-started/example-app-service-monitor.yaml
32+
33+
# Check if car got correctly synced
34+
kubectl get servicemonitor -n my-vcluster
35+
```
36+
37+
## Building the Plugin
38+
To just build the plugin image and push it to the registry, run:
39+
```
40+
# Build
41+
docker build . -t my-repo/my-plugin:0.0.1
42+
43+
# Push
44+
docker push my-repo/my-plugin:0.0.1
45+
```
46+
47+
Then exchange the image in the `plugin.yaml`
48+
49+
## Development Process
50+
51+
General vcluster plugin project structure:
52+
```
53+
.
54+
├── go.mod # Go module definition
55+
├── go.sum
56+
├── devspace.yaml # Development environment definition
57+
├── devspace_start.sh # Development entrypoint script
58+
├── Dockerfile # Production Dockerfile
59+
├── main.go # Go Entrypoint
60+
├── plugin.yaml # Plugin Helm Values
61+
├── syncers/ # Plugin Syncers
62+
└── manifests/ # Additional plugin resources
63+
```
64+
65+
Before starting to develop, make sure you have installed the following tools on your computer:
66+
- [docker](https://docs.docker.com/)
67+
- [kubectl](https://kubernetes.io/docs/tasks/tools/) with a valid kube context configured
68+
- [helm](https://helm.sh/docs/intro/install/), which is used to deploy vcluster and the plugin
69+
- [vcluster CLI](https://www.vcluster.com/docs/getting-started/setup) v0.20.0 or higher
70+
- [DevSpace](https://devspace.sh/cli/docs/quickstart), which is used to spin up a development environment
71+
72+
After successfully setting up the tools, start the development environment with:
73+
```
74+
devspace dev -n vcluster
75+
```
76+
77+
After a while a terminal should show up with additional instructions. Enter the following command to start the plugin:
78+
```
79+
go build -mod vendor -o plugin main.go && /vcluster/syncer start
80+
```
81+
82+
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.
83+
84+
Delete the development environment with:
85+
```
86+
devspace purge -n vcluster
87+
```

codefresh.yaml

Lines changed: 19 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -43,95 +43,59 @@ steps:
4343
on:
4444
- success
4545

46-
build_v1:
47-
title: "Build v1"
48-
type: build
49-
stage: "build"
50-
working_directory: '${{clone}}/v1'
51-
build_arguments:
52-
- BUILDKIT_INLINE_CACHE=1
53-
image_name: "${{CF_REPO_NAME}}"
54-
tag: "v1-${{IMAGE_TAG}}"
55-
registry: "ghcr-codefresh-contrib"
56-
platform: 'linux/amd64,linux/arm64'
57-
buildx:
58-
builder:
59-
driver_opts: "image=moby/buildkit:v0.14.1"
60-
cache_from:
61-
- ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v1-${{IMAGE_TAG}}
62-
- ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v1-main
63-
when:
64-
steps:
65-
- name: clone
66-
on:
67-
- success
68-
69-
build_v2:
70-
title: "Build v2"
46+
build:
47+
title: "Build image"
7148
type: build
7249
stage: "build"
7350
build_arguments:
7451
- BUILDKIT_INLINE_CACHE=1
75-
working_directory: '${{clone}}/v2'
52+
working_directory: '${{clone}}'
7653
image_name: "${{CF_REPO_NAME}}"
77-
tag: "v2-${{IMAGE_TAG}}"
54+
tag: "${{IMAGE_TAG}}"
7855
registry: "ghcr-codefresh-contrib"
7956
platform: 'linux/amd64,linux/arm64'
8057
buildx:
8158
builder:
8259
driver_opts: "image=moby/buildkit:v0.14.1"
8360
cache_from:
84-
- ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v2-${{IMAGE_TAG}}
85-
- ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v2-main
61+
- ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:${{IMAGE_TAG}}
62+
- ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:main
8663
when:
8764
steps:
8865
- name: clone
8966
on:
9067
- success
91-
- name: build_v1
92-
on:
93-
- success
9468

95-
create_clusters:
69+
create_cluster:
9670
title: 'Create k3d clusters'
9771
stage: test
9872
type: freestyle
9973
image: 'ghcr.io/k3d-io/k3d:5.5.2-dind'
10074
commands:
10175
- export NETWORK=$(docker network ls | grep bridge | tail -1 | awk '{print $2}')
102-
- export FULL_CLUSTER_NAME_V1="k3d-test-prom-vcluster-plugin-v1"
103-
- export FULL_CLUSTER_NAME_V2="k3d-test-prom-vcluster-plugin-v2"
76+
- export FULL_CLUSTER_NAME="k3d-test-prom-vcluster-plugin"
10477
- export CLUSTER_IMAGE="rancher/k3s:v1.24.4-k3s1"
105-
- k3d cluster create $FULL_CLUSTER_NAME_V1 --network $NETWORK -i $CLUSTER_IMAGE --no-lb
106-
- k3d cluster create $FULL_CLUSTER_NAME_V2 --network $NETWORK -i $CLUSTER_IMAGE --no-lb
107-
- export CLUSTER_IP_V1=$(docker inspect k3d-$FULL_CLUSTER_NAME_V1-server-0 | jq -r '.[0].NetworkSettings.IPAddress')
108-
- export CLUSTER_IP_V2=$(docker inspect k3d-$FULL_CLUSTER_NAME_V2-server-0 | jq -r '.[0].NetworkSettings.IPAddress')
109-
- yq e -i '(.clusters[] | select(.name=="k3d-"+env(FULL_CLUSTER_NAME_V1)) | .cluster.server) = "https://"+env(CLUSTER_IP_V1)+":6443"' $KUBECONFIG
110-
- yq e -i '(.clusters[] | select(.name=="k3d-"+env(FULL_CLUSTER_NAME_V2)) | .cluster.server) = "https://"+env(CLUSTER_IP_V2)+":6443"' $KUBECONFIG
111-
- export V1_KUBE_CONTEXT=k3d-$FULL_CLUSTER_NAME_V1
112-
- export V2_KUBE_CONTEXT=k3d-$FULL_CLUSTER_NAME_V2
113-
- cf_export FULL_CLUSTER_NAME_V1 V1_KUBE_CONTEXT FULL_CLUSTER_NAME_V2 V2_KUBE_CONTEXT
78+
- k3d cluster create $FULL_CLUSTER_NAME --network $NETWORK -i $CLUSTER_IMAGE --no-lb
79+
- export CLUSTER_IP=$(docker inspect k3d-$FULL_CLUSTER_NAME-server-0 | jq -r '.[0].NetworkSettings.IPAddress')
80+
- yq e -i '(.clusters[] | select(.name=="k3d-"+env(FULL_CLUSTER_NAME)) | .cluster.server) = "https://"+env(CLUSTER_IP)+":6443"' $KUBECONFIG
81+
- export KUBE_CONTEXT=k3d-$FULL_CLUSTER_NAME
82+
- cf_export FULL_CLUSTER_NAME KUBE_CONTEXT
11483

11584
init_test_envs:
11685
stage: test
11786
title: 'Init test environments'
11887
image: "dtzar/helm-kubectl:3.15"
11988
working_directory: '${{clone}}'
12089
commands:
121-
- curl -L -o vcluster "https://github.com/loft-sh/vcluster/releases/download/v0.20.0-beta.11/vcluster-linux-amd64" && chmod +x ./vcluster && mv ./vcluster /usr/local/bin/vcluster
122-
- kubectl config use-context $V1_KUBE_CONTEXT
123-
- v1/.e2e/scripts/init.sh "${{steps.build_v1.imageId}}"
124-
- kubectl config use-context $V2_KUBE_CONTEXT
125-
- v2/.e2e/scripts/init.sh "${{steps.build_v2.imageId}}"
90+
- curl -L -o vcluster "https://github.com/loft-sh/vcluster/releases/download/v0.23.0/vcluster-linux-amd64" && chmod +x ./vcluster && mv ./vcluster /usr/local/bin/vcluster
91+
- kubectl config use-context $KUBE_CONTEXT
92+
- .e2e/scripts/init.sh "${{steps.build.imageId}}"
12693
when:
12794
steps:
128-
- name: create_clusters
129-
on:
130-
- success
131-
- name: build_v1
95+
- name: create_cluster
13296
on:
13397
- success
134-
- name: build_v2
98+
- name: build
13599
on:
136100
- success
137101

@@ -141,8 +105,7 @@ steps:
141105
image: 'ghcr.io/kyverno/chainsaw:v0.2.5'
142106
working_directory: '${{clone}}'
143107
commands:
144-
- chainsaw test --kube-context $V1_KUBE_CONTEXT --test-file .e2e/chainsaw-tests.yaml --skip-delete
145-
- chainsaw test --kube-context $V2_KUBE_CONTEXT --test-file .e2e/chainsaw-tests.yaml --skip-delete
108+
- chainsaw test --kube-context $KUBE_CONTEXT --test-file .e2e/chainsaw-tests.yaml --skip-delete
146109
when:
147110
steps:
148111
- name: init_test_envs

v2/devspace.yaml renamed to devspace.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ hooks:
1212
fi
1313
1414
deployments:
15-
prometheus-operator:
15+
prometheus-operator-crds:
1616
helm:
1717
chart:
18-
name: kube-prometheus-stack
18+
name: prometheus-operator-crds
1919
repo: https://prometheus-community.github.io/helm-charts
20-
version: 60.2.0
20+
version: 18.0.1
2121
vcluster:
2222
helm:
2323
chart:
2424
name: vcluster
2525
repo: https://charts.loft.sh
26-
version: v0.20.0-beta.5
26+
version: v0.23.0
2727
values:
2828
controlPlane:
2929
advanced:
@@ -36,6 +36,11 @@ deployments:
3636
enabled: false
3737
readinessProbe:
3838
enabled: false
39+
resources:
40+
limits:
41+
memory: 4Gi
42+
requests:
43+
memory: 4Gi
3944
distro:
4045
k3s:
4146
enabled: true
@@ -53,13 +58,13 @@ deployments:
5358
verbs: ["create", "delete", "patch", "update", "get", "list", "watch"]
5459
clusterRole:
5560
extraRules:
56-
- apiGroups: [ "apiextensions.k8s.io" ]
57-
resources: [ "customresourcedefinitions" ]
58-
verbs: [ "get", "list", "watch" ]
61+
- apiGroups: ["apiextensions.k8s.io"]
62+
resources: ["customresourcedefinitions"]
63+
verbs: ["get", "list", "watch"]
5964
dev:
6065
vcluster:
6166
imageSelector: "ghcr.io/loft-sh/vcluster-pro"
62-
devImage: golang:1.22.2
67+
devImage: golang:1.23.2
6368
workingDir: /plugins/prometheus-operator-resources
6469
container: syncer
6570
terminal:

v2/devspace_start.sh renamed to devspace_start.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ COLOR_RESET="\033[0m"
77
if [ ! -f "/vcluster/syncer" ]; then
88
echo "Downloading vCluster syncer..."
99
mkdir -p /vcluster
10-
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.20.0-beta.5/syncer-linux-$(go env GOARCH)"
11-
curl -L -o /usr/local/bin/kine "https://github.com/k3s-io/kine/releases/download/v0.11.9/kine-$(go env GOARCH)"
10+
curl -L -o /vcluster/syncer "https://github.com/loft-sh/vcluster/releases/download/v0.23.0/syncer-linux-$(go env GOARCH)"
11+
curl -L -o /usr/local/bin/kine "https://github.com/k3s-io/kine/releases/download/v0.13.8/kine-$(go env GOARCH)"
1212
chmod +x /vcluster/syncer
1313
chmod +x /usr/local/bin/kine
1414
echo "Successfully downloaded syncer"

0 commit comments

Comments
 (0)