Skip to content

Commit b5185cd

Browse files
committed
remove v1 support
1 parent 0a249ba commit b5185cd

32 files changed

+100
-2008
lines changed

.e2e/chainsaw-tests.yaml

Lines changed: 0 additions & 100 deletions
This file was deleted.
File renamed without changes.

.e2e/vcluster-resources.yaml

Lines changed: 0 additions & 61 deletions
This file was deleted.
File renamed without changes.

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: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,74 +43,43 @@ 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
@@ -119,19 +88,14 @@ steps:
11988
working_directory: '${{clone}}'
12089
commands:
12190
- 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
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}}"
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
File renamed without changes.
File renamed without changes.

v2/go.mod renamed to go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/codefresh-contrib/vcluster-prometheus-operator-plugin/v2
1+
module github.com/codefresh-contrib/vcluster-prometheus-operator-plugin
22

33
go 1.23.2
44

v2/go.sum renamed to go.sum

File renamed without changes.

v2/main.go renamed to main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package main
22

33
import (
4-
"github.com/codefresh-contrib/vcluster-prometheus-operator-plugin/v2/syncers/podmonitor"
5-
"github.com/codefresh-contrib/vcluster-prometheus-operator-plugin/v2/syncers/servicemonitor"
4+
"github.com/codefresh-contrib/vcluster-prometheus-operator-plugin/syncers/podmonitor"
5+
"github.com/codefresh-contrib/vcluster-prometheus-operator-plugin/syncers/servicemonitor"
66
"github.com/loft-sh/vcluster-sdk/plugin"
77
"k8s.io/klog/v2"
88
)
File renamed without changes.

0 commit comments

Comments
 (0)