Skip to content

Commit d56128a

Browse files
committed
test: add examplesa and update reconcile test
1 parent bf0c8a5 commit d56128a

11 files changed

Lines changed: 512 additions & 7 deletions
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Test Examples
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
# Allow manual triggering
9+
workflow_dispatch:
10+
11+
jobs:
12+
examples-test:
13+
name: Test example VirtualClusters
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v4
23+
with:
24+
go-version-file: 'go.mod'
25+
cache: true
26+
27+
- name: Setup Kind
28+
uses: helm/kind-action@v1.8.0
29+
with:
30+
wait: 300s
31+
cluster_name: kind
32+
33+
- name: Install CRDs
34+
run: |
35+
make install
36+
37+
- name: Build and load controller image
38+
run: |
39+
make docker-build docker-push IMG=openvirtualcluster-operator:test
40+
kind load docker-image openvirtualcluster-operator:test --name kind
41+
42+
- name: Deploy controller
43+
run: |
44+
make deploy IMG=openvirtualcluster-operator:test
45+
46+
- name: Wait for controller to be ready
47+
run: |
48+
kubectl wait --for=condition=available --timeout=300s deployment/openvirtualcluster-controller-manager -n openvirtualcluster-system
49+
50+
- name: Run example tests
51+
run: |
52+
go test -v ./test/e2e/examples_test.go -ginkgo.v
53+
54+
- name: Collect logs on failure
55+
if: failure()
56+
run: |
57+
kubectl logs -n openvirtualcluster-system -l control-plane=controller-manager --tail=100
58+
kubectl get pods -A
59+
kubectl get virtualclusters -A

examples/basic-virtualcluster.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: basic-vcluster
5+
namespace: default
6+
spec:
7+
values:
8+
# Minimal configuration for a basic virtual cluster
9+
vcluster:
10+
image: rancher/k3s:v1.27.3-k3s1
11+
12+
# Disable persistent storage to keep the example simple
13+
storage:
14+
persistence: false
15+
16+
# Disable telemetry
17+
telemetry:
18+
disabled: true

examples/custom-k8s-version.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: custom-k8s-version
5+
namespace: default
6+
spec:
7+
# You can also specify a custom chart version
8+
chart:
9+
version: "v0.24.1"
10+
values:
11+
# Specify a particular K8s version for your virtual cluster
12+
vcluster:
13+
# Using K8s 1.28 instead of the default version
14+
image: rancher/k3s:v1.28.2-k3s1
15+
16+
# Additional K3s/K8s args if needed
17+
extraArgs:
18+
- --disable=traefik
19+
- --disable=servicelb
20+
21+
# Disable telemetry
22+
telemetry:
23+
disabled: true

examples/distro-specific.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: k0s-vcluster
5+
namespace: default
6+
spec:
7+
values:
8+
# Configure a different Kubernetes distribution
9+
# In this example, we're using k0s instead of k3s
10+
vcluster:
11+
# Switch from k3s (default) to k0s
12+
plugin:
13+
name: k0s
14+
15+
# K0s-specific settings
16+
k0s:
17+
version: "v1.27.1-k0s.0"
18+
# Optional k0s config
19+
extraConfig: |
20+
apiVersion: k0s.k0sproject.io/v1beta1
21+
kind: ClusterConfig
22+
metadata:
23+
name: k0s
24+
spec:
25+
extensions:
26+
helm:
27+
repositories:
28+
- name: ingress-nginx
29+
url: https://kubernetes.github.io/ingress-nginx
30+
charts:
31+
- name: ingress-controller
32+
chartname: ingress-nginx/ingress-nginx
33+
version: "4.6.0"
34+
namespace: ingress-nginx
35+
36+
# Configure a minimal, working setup
37+
service:
38+
type: ClusterIP
39+
40+
storage:
41+
persistence: false

examples/exposed-service.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: exposed-vcluster
5+
namespace: default
6+
spec:
7+
values:
8+
# Basic vcluster configuration
9+
vcluster:
10+
image: rancher/k3s:v1.27.3-k3s1
11+
12+
# Configure the service to expose the virtual cluster
13+
service:
14+
# Use NodePort to expose the service on a port on each node
15+
type: NodePort
16+
17+
# If you have a load balancer available, use LoadBalancer instead
18+
# type: LoadBalancer
19+
20+
# Configure the node port if using NodePort
21+
nodePort: 30080
22+
23+
# Configure extra ports to expose
24+
extraPorts:
25+
- name: metrics
26+
port: 8443
27+
targetPort: 8443
28+
nodePort: 30081

examples/ingress-sync.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: ingress-sync
5+
namespace: default
6+
spec:
7+
values:
8+
# Configure which resources to sync from virtual cluster to host cluster
9+
sync:
10+
# Enable ingress sync
11+
ingresses:
12+
enabled: true
13+
14+
# Enable service sync
15+
services:
16+
enabled: true
17+
18+
# Enable configmap sync
19+
configmaps:
20+
enabled: false
21+
22+
# Enable secret sync
23+
secrets:
24+
enabled: false
25+
26+
# Basic vcluster configuration
27+
vcluster:
28+
image: rancher/k3s:v1.27.3-k3s1
29+
30+
# Service configuration
31+
service:
32+
type: ClusterIP
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: tenant-a-vcluster
5+
namespace: tenant-a
6+
spec:
7+
values:
8+
# Basic vcluster configuration with specific version
9+
vcluster:
10+
image: rancher/k3s:v1.27.3-k3s1
11+
12+
# Configure isolation settings for multi-tenancy
13+
isolation:
14+
# Enable network isolation
15+
enabled: true
16+
17+
# Prevent tenant from accessing host services
18+
networkPolicy: true
19+
20+
# Resource quota enforcement for the tenant
21+
syncer:
22+
extraArgs:
23+
- --enforce-pod-security-standard=restricted
24+
25+
# Configure resource limits
26+
resources:
27+
limits:
28+
cpu: "2"
29+
memory: "2Gi"
30+
requests:
31+
cpu: "500m"
32+
memory: "512Mi"
33+
34+
# Control which resources get synced to parent cluster
35+
sync:
36+
# Only sync ingresses and services, not other resources
37+
ingresses:
38+
enabled: true
39+
services:
40+
enabled: true
41+
configmaps:
42+
enabled: false
43+
secrets:
44+
enabled: false
45+
46+
# Disable admin access from host cluster
47+
rbac:
48+
clusterRole:
49+
# Disable admin role binding creation in the host cluster
50+
createRole: false

examples/persistent-storage.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: persistent-vcluster
5+
namespace: default
6+
spec:
7+
values:
8+
# Configure persistent storage for the virtual cluster
9+
storage:
10+
# Enable persistent storage
11+
persistence: true
12+
13+
# Configure the storage class to use
14+
# Leave empty to use the default storage class
15+
storageClass: ""
16+
17+
# Configure the size of the persistent volume
18+
size: 5Gi
19+
20+
# Configure the access mode for the persistent volume
21+
accessModes:
22+
- ReadWriteOnce
23+
24+
# Basic vcluster configuration
25+
vcluster:
26+
image: rancher/k3s:v1.27.3-k3s1

examples/resource-limits.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: core.openvc.dev/v1alpha1
2+
kind: VirtualCluster
3+
metadata:
4+
name: resource-limited-vcluster
5+
namespace: default
6+
spec:
7+
values:
8+
# Basic vcluster configuration
9+
vcluster:
10+
image: rancher/k3s:v1.27.3-k3s1
11+
12+
# Configure resource limits and requests for the virtual cluster
13+
resources:
14+
# Resource limits for the vcluster itself
15+
limits:
16+
cpu: "1"
17+
memory: "1Gi"
18+
19+
# Resource requests for the vcluster
20+
requests:
21+
cpu: "200m"
22+
memory: "512Mi"
23+
24+
# Configure resource limits for other components
25+
syncer:
26+
resources:
27+
limits:
28+
cpu: "500m"
29+
memory: "256Mi"
30+
requests:
31+
cpu: "100m"
32+
memory: "128Mi"
33+
34+
# Disable telemetry
35+
telemetry:
36+
disabled: true

internal/controller/reconcile_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ import (
3838

3939
// MockVirtualClusterReconciler embeds the real reconciler for testing
4040
type MockVirtualClusterReconciler struct {
41-
// Embed the reconciler
42-
client.Client
43-
Scheme *runtime.Scheme
44-
Recorder record.EventRecorder
41+
VirtualClusterReconciler
4542

4643
// Add fields to track mock behavior
4744
createValuesFileCalled bool
@@ -202,9 +199,11 @@ var _ = Describe("VirtualCluster Reconciler", func() {
202199

203200
// Create the mock reconciler
204201
mockReconciler = &MockVirtualClusterReconciler{
205-
Client: fakeClient,
206-
Scheme: scheme,
207-
Recorder: record.NewFakeRecorder(10),
202+
VirtualClusterReconciler: VirtualClusterReconciler{
203+
Client: fakeClient,
204+
Scheme: scheme,
205+
Recorder: record.NewFakeRecorder(10),
206+
},
208207
// Set default mock return values
209208
createValuesFileResult: "/tmp/mock-values.yaml",
210209
createValuesFileError: nil,

0 commit comments

Comments
 (0)