Skip to content

Commit

Permalink
local storage provider in liqo controller manager
Browse files Browse the repository at this point in the history
  • Loading branch information
aleoli authored and adamjensenbot committed Nov 3, 2021
1 parent 50bc160 commit 725331f
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 4 deletions.
23 changes: 23 additions & 0 deletions cmd/liqo-controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/sig-storage-lib-external-provisioner/v7/controller"

discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
netv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
Expand All @@ -46,6 +47,7 @@ import (
resourceoffercontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/resourceoffer-controller"
searchdomainoperator "github.com/liqotech/liqo/pkg/liqo-controller-manager/search-domain-operator"
shadowpodctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/shadowpod-controller"
liqostorageprovisioner "github.com/liqotech/liqo/pkg/liqo-controller-manager/storageprovisioner"
virtualNodectrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/virtualNode-controller"
"github.com/liqotech/liqo/pkg/mapperUtils"
peeringroles "github.com/liqotech/liqo/pkg/peering-roles"
Expand Down Expand Up @@ -146,6 +148,12 @@ func main() {
flag.Var(&nodeExtraAnnotations, "node-extra-annotations", "Extra annotations to add to the Virtual Node")
flag.Var(&nodeExtraLabels, "node-extra-labels", "Extra labels to add to the Virtual Node")

// Storage Provisioner parameters
enableStorage := flag.Bool("enable-storage", false, "enable the liqo virtual storage class")
virtualStorageClassName := flag.String("virtual-storage-class-name", "liqo", "Name of the virtual storage class")
realStorageClassName := flag.String("real-storage-class-name", "", "Name of the real storage class to use for the actual volumes")
storageNamespace := flag.String("storage-namespace", "liqo-storage", "Namespace where the liqo storage-related resources are stored")

liqoerrors.InitFlags(nil)
restcfg.InitFlags(nil)
klog.InitFlags(nil)
Expand Down Expand Up @@ -339,6 +347,21 @@ func main() {
var wg = &sync.WaitGroup{}
broadcaster.StartBroadcaster(ctx, wg)

if enableStorage != nil && *enableStorage {
liqoProvisioner := liqostorageprovisioner.NewLiqoLocalStorageProvisioner(mgr.GetClient(),
*virtualStorageClassName, *storageNamespace, *realStorageClassName)

provisionController := controller.NewProvisionController(clientset, consts.StorageProvisionerName, liqoProvisioner,
controller.LeaderElection(false),
)

if err = mgr.Add(liqostorageprovisioner.StorageControllerRunnable{
Ctrl: provisionController,
}); err != nil {
klog.Fatal(err)
}
}

klog.Info("starting manager as controller manager")
if err := mgr.Start(ctx); err != nil {
klog.Error(err)
Expand Down
3 changes: 2 additions & 1 deletion deployments/liqo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@
| route.pod.extraArgs | list | `[]` | route pod extra arguments |
| route.pod.labels | object | `{}` | route pod labels |
| storage.enable | bool | `false` | |
| storage.storageClassName | string | `"liqo"` | name to assign to the liqo virtual storage class |
| storage.realStorageClassName | string | `""` | name of the real storage class to use in the local cluster |
| storage.storageNamespace | string | `"liqo-storage"` | namespace where liqo will deploy specific PVCs |
| storage.virtualStorageClassName | string | `"liqo"` | name to assign to the liqo virtual storage class |
| tag | string | `""` | Images' tag to select a development version of liqo instead of a release |
| virtualKubelet.extra.annotations | object | `{}` | virtual kubelet pod extra annotations |
| virtualKubelet.extra.args | list | `[]` | virtual kubelet pod extra arguments |
Expand Down
20 changes: 20 additions & 0 deletions deployments/liqo/files/liqo-controller-manager-ClusterRole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ rules:
- get
- list
- watch
- apiGroups:
- ""
resources:
- persistentvolumeclaims
- persistentvolumes
verbs:
- create
- delete
- get
- list
- update
- watch
- apiGroups:
- ""
resources:
Expand Down Expand Up @@ -471,6 +483,14 @@ rules:
- patch
- update
- watch
- apiGroups:
- storage.k8s.io
resources:
- storageclasses
verbs:
- get
- list
- watch
- apiGroups:
- virtualkubelet.liqo.io
resources:
Expand Down
6 changes: 6 additions & 0 deletions deployments/liqo/templates/liqo-controller-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ spec:
- --kubelet-image={{ .Values.virtualKubelet.imageName }}{{ include "liqo.suffix" $ctrlManagerConfig }}:{{ include "liqo.version" $ctrlManagerConfig }}
- --init-kubelet-image={{ .Values.virtualKubelet.initContainer.imageName }}{{ include "liqo.suffix" $ctrlManagerConfig }}:{{ include "liqo.version" $ctrlManagerConfig }}
- --auto-join-discovered-clusters={{ .Values.discovery.config.autojoin }}
- --enable-storage={{ .Values.storage.enable }}
{{- if .Values.storage.enable }}
- --virtual-storage-class-name={{ .Values.storage.virtualStorageClassName }}
- --real-storage-class-name={{ .Values.storage.realStorageClassName }}
- --storage-namespace={{ .Values.storage.storageNamespace }}
{{- end }}
{{- if .Values.discovery.config.clusterName }}
- --cluster-name={{ .Values.discovery.config.clusterName }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion deployments/liqo/templates/liqo-storage-class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: {{ .Values.storage.storageClassName }}
name: {{ .Values.storage.virtualStorageClassName }}
provisioner: liqo.io/storage
volumeBindingMode: WaitForFirstConsumer

Expand Down
4 changes: 3 additions & 1 deletion deployments/liqo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ virtualKubelet:
storage:
enable: false
# -- name to assign to the liqo virtual storage class
storageClassName: liqo
virtualStorageClassName: liqo
# -- name of the real storage class to use in the local cluster
realStorageClassName: ""
# -- namespace where liqo will deploy specific PVCs
storageNamespace: liqo-storage

Expand Down
3 changes: 2 additions & 1 deletion docs/pages/installation/chart_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ weight: 5
| route.pod.extraArgs | list | `[]` | route pod extra arguments |
| route.pod.labels | object | `{}` | route pod labels |
| storage.enable | bool | `false` | |
| storage.storageClassName | string | `"liqo"` | name to assign to the liqo virtual storage class |
| storage.realStorageClassName | string | `""` | name of the real storage class to use in the local cluster |
| storage.storageNamespace | string | `"liqo-storage"` | namespace where liqo will deploy specific PVCs |
| storage.virtualStorageClassName | string | `"liqo"` | name to assign to the liqo virtual storage class |
| tag | string | `""` | Images' tag to select a development version of liqo instead of a release |
| virtualKubelet.extra.annotations | object | `{}` | virtual kubelet pod extra annotations |
| virtualKubelet.extra.args | list | `[]` | virtual kubelet pod extra arguments |
Expand Down
20 changes: 20 additions & 0 deletions pkg/consts/storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2019-2021 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package consts

const (
// StorageProvisionerName is the name of the liqo storage provisioner.
StorageProvisionerName = "liqo.io/storage"
)
32 changes: 32 additions & 0 deletions pkg/liqo-controller-manager/storageprovisioner/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2019-2021 The Liqo Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package storageprovisioner

import (
"context"

"sigs.k8s.io/sig-storage-lib-external-provisioner/v7/controller"
)

// StorageControllerRunnable wraps the storage ProvisionController to implement the Runnable interface.
type StorageControllerRunnable struct {
Ctrl *controller.ProvisionController
}

// Start starts the runnable and make it run until the context is open.
func (c StorageControllerRunnable) Start(ctx context.Context) error {
c.Ctrl.Run(ctx)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
"sigs.k8s.io/sig-storage-lib-external-provisioner/v7/controller"
)

// +kubebuilder:rbac:groups=core,resources=persistentvolumeclaims;persistentvolumes,verbs=get;list;watch;create;delete;update
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=get;list;watch

type liqoLocalStorageProvisioner struct {
client client.Client
virtualStorageClassName string
Expand Down

0 comments on commit 725331f

Please sign in to comment.