Skip to content

Commit f2b098a

Browse files
chia-meAleTopp
andcommitted
Add PVC Mirror Provisioner
Co-authored-by: Alessio Giliberti <alessio.giliberti.rg@gmail.com>
1 parent 38889c1 commit f2b098a

22 files changed

Lines changed: 1325 additions & 109 deletions

operators/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ run-operator: generate ## Run the main operator locally
131131
--enable-workspace=true\
132132
--enable-instance=true\
133133
--enable-sharedvolume=true\
134+
--enable-pmp=true\
134135
--enable-keycloak=true\
135136
--enable-webhooks=false
136137

operators/cmd/operator/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ func main() {
7676
var enableWorkspace bool
7777
var enableInstance bool
7878
var enableSharedVolume bool
79+
var enablePmp bool
7980
var enableKeycloak bool
8081
flag.BoolVar(&enableTenant, "enable-tenant", true, "Enable the tenant controller.")
8182
flag.BoolVar(&enableWorkspace, "enable-workspace", true, "Enable the workspace controller.")
8283
flag.BoolVar(&enableInstance, "enable-instance", true, "Enable the instance controller.")
8384
flag.BoolVar(&enableSharedVolume, "enable-sharedvolume", true, "Enable the sharedvolume controller.")
85+
flag.BoolVar(&enablePmp, "enable-pmp", true, "Enable the PVC mirror provisioner.")
8486
flag.BoolVar(&enableKeycloak, "enable-keycloak", true, "Enable the Keycloak integration.")
8587

8688
flag.BoolVar(&enableWebhooks, "enable-webhooks", true, "Enable the webhooks server.")
@@ -156,6 +158,14 @@ func main() {
156158
}
157159
}
158160

161+
if enablePmp {
162+
log.Info("Starting the PVC mirror provisioner")
163+
err := setupPmp(ctx, mgr, log, targetLabel)
164+
if err != nil {
165+
klog.Fatal(err, "Unable to create PVC mirror provisioner")
166+
}
167+
}
168+
159169
// Setup operator probes
160170
if err := addOperatorProbes(mgr); err != nil {
161171
klog.Fatal(err, "Unable to set up operator probes")

operators/cmd/operator/pmp.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2020-2026 Politecnico di Torino
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"context"
19+
"flag"
20+
21+
"github.com/go-logr/logr"
22+
"sigs.k8s.io/controller-runtime/pkg/manager"
23+
24+
"github.com/netgroup-polito/CrownLabs/operators/pkg/controller/common"
25+
"github.com/netgroup-polito/CrownLabs/operators/pkg/controller/pmp"
26+
)
27+
28+
var (
29+
mirrorStorageClass string
30+
mirrorProvisionerName string
31+
)
32+
33+
func init() {
34+
flag.StringVar(&mirrorStorageClass, "mirror-storage-class", "nfs-mirror", "The StorageClass to be used for all PVCs which are going to be mirrors")
35+
flag.StringVar(&mirrorProvisionerName, "mirror-provisioner-name", "pmp.crownlabs.polito.it", "The provisioner name to be used for the mirror StorageClass")
36+
}
37+
38+
func setupPmp(
39+
ctx context.Context,
40+
mgr manager.Manager,
41+
log logr.Logger,
42+
targetLabel common.KVLabel,
43+
) error {
44+
log = log.WithName("pmp")
45+
46+
pmprov := pmp.PvcMirrorProvisioner{
47+
Ctx: ctx,
48+
Client: mgr.GetClient(),
49+
Config: mgr.GetConfig(),
50+
Logger: log,
51+
TargetLabel: targetLabel,
52+
MirrorStorageClass: mirrorStorageClass,
53+
MirrorProvisionerName: mirrorProvisionerName,
54+
}
55+
return mgr.Add(&pmprov)
56+
}

operators/deploy/operator/templates/clusterrole.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,16 @@ metadata:
66
{{- include "operator.labels" . | nindent 4 }}
77
rules:
88
- apiGroups: ["crownlabs.polito.it"]
9-
resources: ["workspaces", "workspaces/status", "tenants", "tenants/status", "instances", "instances/status", "templates", "templates/status"]
10-
verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"]
11-
12-
- apiGroups: ["crownlabs.polito.it"]
13-
resources: ["sharedvolumes", "sharedvolumes/status"]
9+
resources: ["workspaces", "workspaces/status", "tenants", "tenants/status", "instances", "instances/status", "templates", "templates/status", "sharedvolumes", "sharedvolumes/status"]
1410
verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "deletecollection"]
1511

1612
- apiGroups: [""]
1713
resources: ["namespaces", "resourcequotas", "limitranges", "secrets"]
1814
verbs: ["get", "list", "watch", "create", "update", "delete", "deletecollection"]
1915

2016
- apiGroups: [""]
21-
resources: ["persistentvolumeclaims", "persistentvolumes"]
22-
verbs: ["get", "list", "watch", "create", "patch", "update"]
17+
resources: ["persistentvolumeclaims", "persistentvolumes", "events"]
18+
verbs: ["get", "list", "watch", "create", "patch", "update", "delete"]
2319

2420
- apiGroups: ["batch"]
2521
resources: ["jobs", "jobs/status"]
@@ -32,3 +28,11 @@ rules:
3228
- apiGroups: ["networking.k8s.io"]
3329
resources: ["networkpolicies"]
3430
verbs: ["get", "list", "watch", "create", "update", "delete", "deletecollection"]
31+
32+
- apiGroups: ["storage.k8s.io"]
33+
resources: ["storageclasses"]
34+
verbs: ["get", "list", "watch"]
35+
36+
- apiGroups: ["coordination.k8s.io"]
37+
resources: ["leases"]
38+
verbs: ["get", "create", "update", "delete"]

operators/deploy/operator/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ spec:
5353
- "--cap-cpu={{ .Values.configurations.tenant.resourcecaps.cpu }}"
5454
- "--cap-memory-giga={{ .Values.configurations.tenant.resourcecaps.memory }}"
5555
- "--shared-volume-storage-class={{.Values.configurations.sharedVolumeOptions.storageClass }}"
56+
- "--mirror-storage-class={{.Values.configurations.pvcMirrorProvisioner.storageClassName}}"
57+
- "--mirror-provisioner-name={{.Values.configurations.pvcMirrorProvisioner.provisionerName}}"
5658
# compatibility with older Keycloak versions
5759
- "--keycloak-compatibility-mode={{ .Values.configurations.keycloak.compatibilityMode }}"
5860
ports:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: storage.k8s.io/v1
2+
kind: StorageClass
3+
metadata:
4+
annotations:
5+
storageclass.kubernetes.io/is-default-class: "false"
6+
name: {{ .Values.configurations.pvcMirrorProvisioner.storageClassName }}
7+
provisioner: {{ .Values.configurations.pvcMirrorProvisioner.provisionerName }}
8+
reclaimPolicy: Delete
9+
volumeBindingMode: Immediate
10+
allowVolumeExpansion: false

operators/deploy/operator/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ configurations:
3838
sharedVolumeOptions:
3939
storageClass: rook-nfs
4040

41+
pvcMirrorProvisioner:
42+
provisionerName: pmp.crownlabs.polito.it
43+
storageClassName: nfs-mirror
44+
4145
image:
4246
repository: crownlabs/tenant-operator
4347
pullPolicy: IfNotPresent

operators/go.mod

Lines changed: 53 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,74 +20,97 @@ require (
2020
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674
2121
github.com/onsi/ginkgo/v2 v2.23.3
2222
github.com/onsi/gomega v1.37.0
23-
github.com/prometheus/client_golang v1.22.0
24-
github.com/prometheus/common v0.62.0
25-
go.uber.org/mock v0.5.2
23+
github.com/prometheus/client_golang v1.23.0
24+
github.com/prometheus/common v0.66.0
2625
golang.org/x/crypto v0.46.0
2726
golang.org/x/net v0.48.0
2827
golang.org/x/text v0.32.0
2928
google.golang.org/grpc v1.79.3
3029
google.golang.org/protobuf v1.36.10
3130
gopkg.in/yaml.v3 v3.0.1
32-
k8s.io/api v0.33.0
33-
k8s.io/apimachinery v0.33.0
34-
k8s.io/client-go v0.33.0
31+
k8s.io/api v0.34.0
32+
k8s.io/apimachinery v0.34.0
33+
k8s.io/client-go v0.34.0
3534
k8s.io/cri-api v0.29.3
3635
k8s.io/klog/v2 v2.130.1
37-
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
36+
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
3837
kubevirt.io/api v1.2.0
3938
kubevirt.io/containerized-data-importer-api v1.58.3
4039
sigs.k8s.io/controller-runtime v0.21.0
4140
)
4241

4342
require (
44-
github.com/beorn7/perks v1.0.1 // indirect
4543
github.com/blang/semver/v4 v4.0.0 // indirect
44+
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
45+
github.com/go-openapi/swag/cmdutils v0.24.0 // indirect
46+
github.com/go-openapi/swag/conv v0.24.0 // indirect
47+
github.com/go-openapi/swag/fileutils v0.24.0 // indirect
48+
github.com/go-openapi/swag/jsonname v0.24.0 // indirect
49+
github.com/go-openapi/swag/jsonutils v0.24.0 // indirect
50+
github.com/go-openapi/swag/loading v0.24.0 // indirect
51+
github.com/go-openapi/swag/mangling v0.24.0 // indirect
52+
github.com/go-openapi/swag/netutils v0.24.0 // indirect
53+
github.com/go-openapi/swag/stringutils v0.24.0 // indirect
54+
github.com/go-openapi/swag/typeutils v0.24.0 // indirect
55+
github.com/go-openapi/swag/yamlutils v0.24.0 // indirect
56+
github.com/google/btree v1.1.3 // indirect
57+
github.com/grafana/regexp v0.0.0-20240518133315-a468a5bfb3bc // indirect
58+
github.com/kubernetes-csi/csi-lib-utils v0.22.0 // indirect
59+
github.com/miekg/dns v1.1.68 // indirect
60+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
61+
github.com/x448/float16 v0.8.4 // indirect
62+
go.yaml.in/yaml/v2 v2.4.2 // indirect
63+
go.yaml.in/yaml/v3 v3.0.4 // indirect
64+
golang.org/x/mod v0.30.0 // indirect
65+
golang.org/x/sync v0.19.0 // indirect
66+
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
67+
gopkg.in/yaml.v2 v2.4.0 // indirect
68+
sigs.k8s.io/randfill v1.0.0 // indirect
69+
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
70+
)
71+
72+
require (
73+
github.com/beorn7/perks v1.0.1 // indirect
4674
github.com/cespare/xxhash/v2 v2.3.0 // indirect
47-
github.com/davecgh/go-spew v1.1.1 // indirect
48-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
75+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
76+
github.com/emicklei/go-restful/v3 v3.13.0 // indirect
4977
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
5078
github.com/fsnotify/fsnotify v1.7.0 // indirect
51-
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
52-
github.com/go-openapi/jsonpointer v0.21.0 // indirect
53-
github.com/go-openapi/jsonreference v0.20.2 // indirect
54-
github.com/go-openapi/swag v0.23.0 // indirect
79+
github.com/go-openapi/jsonpointer v0.22.0 // indirect
80+
github.com/go-openapi/jsonreference v0.21.1 // indirect
81+
github.com/go-openapi/swag v0.24.1 // indirect
5582
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
5683
github.com/gogo/protobuf v1.3.2 // indirect
57-
github.com/google/btree v1.1.3 // indirect
58-
github.com/google/gnostic-models v0.6.9 // indirect
84+
github.com/google/gnostic-models v0.7.0 // indirect
5985
github.com/google/go-cmp v0.7.0 // indirect
6086
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
6187
github.com/josharian/intern v1.0.0 // indirect
6288
github.com/json-iterator/go v1.1.12 // indirect
63-
github.com/mailru/easyjson v0.7.7 // indirect
89+
github.com/mailru/easyjson v0.9.0 // indirect
6490
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
65-
github.com/modern-go/reflect2 v1.0.2 // indirect
91+
github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect
6692
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6793
github.com/openshift/api v0.0.0-20230503133300-8bbcb7ca7183 // indirect
6894
github.com/openshift/custom-resource-status v1.1.2 // indirect
6995
github.com/opentracing/opentracing-go v1.2.0 // indirect
7096
github.com/pkg/errors v0.9.1 // indirect
71-
github.com/prometheus/client_model v0.6.1 // indirect
72-
github.com/prometheus/procfs v0.15.1 // indirect
97+
github.com/prometheus/client_model v0.6.2 // indirect
98+
github.com/prometheus/procfs v0.17.0 // indirect
7399
github.com/segmentio/ksuid v1.0.4 // indirect
74-
github.com/spf13/pflag v1.0.5 // indirect
75-
github.com/x448/float16 v0.8.4 // indirect
100+
github.com/spf13/pflag v1.0.6 // indirect
101+
go.uber.org/mock v0.5.2
76102
golang.org/x/oauth2 v0.34.0 // indirect
77-
golang.org/x/sync v0.19.0 // indirect
78103
golang.org/x/sys v0.39.0 // indirect
79104
golang.org/x/term v0.38.0 // indirect
80-
golang.org/x/time v0.9.0 // indirect
105+
golang.org/x/time v0.12.0 // indirect
81106
golang.org/x/tools v0.39.0 // indirect
82107
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
83108
google.golang.org/genproto/googleapis/rpc v0.0.0-20251202230838-ff82c1b0f217 // indirect
84-
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
85109
gopkg.in/inf.v0 v0.9.1 // indirect
86110
k8s.io/apiextensions-apiserver v0.33.0 // indirect
87-
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect
111+
k8s.io/kube-openapi v0.0.0-20250902184714-7fc278399c7f // indirect
88112
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
89-
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
90-
sigs.k8s.io/randfill v1.0.0 // indirect
91-
sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect
92-
sigs.k8s.io/yaml v1.4.0 // indirect
113+
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
114+
sigs.k8s.io/sig-storage-lib-external-provisioner/v13 v13.0.0
115+
sigs.k8s.io/yaml v1.6.0 // indirect
93116
)

0 commit comments

Comments
 (0)