Skip to content

Commit

Permalink
Merge pull request #545 from zvikorn/issue-#534
Browse files Browse the repository at this point in the history
Host-assisted cloning runs after PVC is already cloned #534
  • Loading branch information
awels authored Nov 30, 2018
2 parents 523a24f + d724928 commit 31df8cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions manifests/templates/cdi-controller.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list", "watch", "create"]
- apiGroups: ["storage.k8s.io"]
resources: ["storageclasses"]
verbs: ["get"]
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["get", "list", "watch", "create"]
Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/clone-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
storageV1 "k8s.io/api/storage/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
coreinformers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -230,6 +231,27 @@ func (cc *CloneController) syncPvc(key string) error {
if !checkPVC(pvc, AnnCloneRequest) {
return nil
}

pvcPhase := pvc.Status.Phase
glog.V(3).Infof("PVC phase for PVC \"%s/%s\" is %s", pvc.Namespace, pvc.Name, pvcPhase)
if pvc.Spec.StorageClassName != nil {
storageClassName := *pvc.Spec.StorageClassName
glog.V(3).Infof("storageClassName used by PVC \"%s/%s\" is \"%s\"", pvc.Namespace, pvc.Name, storageClassName)
storageclass, err := cc.clientset.StorageV1().StorageClasses().Get(storageClassName, metav1.GetOptions{})
if err != nil {
return err
}

//Do not schedule the clone pods unless the target PVC is either Bound or Pending/WaitFirstConsumer.
if !(pvcPhase == v1.ClaimBound || (pvcPhase == v1.ClaimPending && *storageclass.VolumeBindingMode == storageV1.VolumeBindingWaitForFirstConsumer)) {
glog.V(3).Infof("PVC \"%s/%s\" is either not bound or is in pending phase and VolumeBindingMode is not VolumeBindingWaitForFirstConsumer."+
" Ignoring this PVC.", pvc.Namespace, pvc.Name)
glog.V(3).Infof("PVC phase is %s", pvcPhase)
glog.V(3).Infof("VolumeBindingMode is %s", *storageclass.VolumeBindingMode)
return nil
}
}

//checking for CloneOf annotation indicating that the clone was already taken care of by the provisioner (smart clone).
if metav1.HasAnnotation(pvc.ObjectMeta, AnnCloneOf) {
glog.V(3).Infof("pvc annotation %q exists indicating cloning completed, skipping pvc \"%s/%s\"\n", AnnCloneOf, pvc.Namespace, pvc.Name)
Expand Down

0 comments on commit 31df8cd

Please sign in to comment.