Address review comments
This commit is contained in:
@@ -247,23 +247,9 @@ func (ctrl *csiSnapshotController) getMatchSnapshotContent(snapshot *crdv1.Volum
|
||||
if content.Spec.VolumeSnapshotRef != nil &&
|
||||
content.Spec.VolumeSnapshotRef.Name == snapshot.Name &&
|
||||
content.Spec.VolumeSnapshotRef.Namespace == snapshot.Namespace &&
|
||||
content.Spec.VolumeSnapshotRef.UID == snapshot.UID {
|
||||
if content.Spec.VolumeSnapshotClassName != nil &&
|
||||
snapshot.Spec.VolumeSnapshotClassName != nil &&
|
||||
*(content.Spec.VolumeSnapshotClassName) != *(snapshot.Spec.VolumeSnapshotClassName) {
|
||||
glog.Errorf("volumeSnapshotClassName do not match. No VolumeSnapshotContent for VolumeSnapshot %s found", snapshotKey(snapshot))
|
||||
return nil
|
||||
}
|
||||
if content.Spec.VolumeSnapshotClassName != nil &&
|
||||
snapshot.Spec.VolumeSnapshotClassName == nil {
|
||||
glog.Errorf("volumeSnapshot does not have VolumeSnapshotClassName. No VolumeSnapshotContent for VolumeSnapshot %s found", snapshotKey(snapshot))
|
||||
return nil
|
||||
}
|
||||
if content.Spec.VolumeSnapshotClassName == nil &&
|
||||
snapshot.Spec.VolumeSnapshotClassName != nil {
|
||||
glog.Errorf("volumeSnapshotContent does not have VolumeSnapshotClassName. No VolumeSnapshotContent for VolumeSnapshot %s found", snapshotKey(snapshot))
|
||||
return nil
|
||||
}
|
||||
content.Spec.VolumeSnapshotRef.UID == snapshot.UID &&
|
||||
content.Spec.VolumeSnapshotClassName != nil && snapshot.Spec.VolumeSnapshotClassName != nil &&
|
||||
*(content.Spec.VolumeSnapshotClassName) == *(snapshot.Spec.VolumeSnapshotClassName) {
|
||||
found = true
|
||||
snapshotContentObj = content
|
||||
break
|
||||
@@ -596,7 +582,7 @@ func (ctrl *csiSnapshotController) deleteSnapshotContentOperation(content *crdv1
|
||||
var snapshotterCredentials map[string]string
|
||||
snapshotClassName := content.Spec.VolumeSnapshotClassName
|
||||
if snapshotClassName != nil {
|
||||
if snapshotClass, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotClasses().Get(*snapshotClassName, metav1.GetOptions{}); err == nil {
|
||||
if snapshotClass, err := ctrl.classLister.Get(*snapshotClassName); err == nil {
|
||||
// Resolve snapshotting secret credentials.
|
||||
// No VolumeSnapshot is provided when resolving delete secret names, since the VolumeSnapshot may or may not exist at delete time.
|
||||
snapshotterSecretRef, err := GetSecretReference(snapshotClass.Parameters, content.Name, nil)
|
||||
@@ -766,7 +752,7 @@ func (ctrl *csiSnapshotController) GetSnapshotClass(className string) (*crdv1.Vo
|
||||
return class, nil
|
||||
}
|
||||
}
|
||||
class, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotClasses().Get(className, metav1.GetOptions{})
|
||||
class, err := ctrl.classLister.Get(className)
|
||||
if err != nil {
|
||||
glog.Errorf("failed to retrieve snapshot class %s from the API server: %q", className, err)
|
||||
return nil, fmt.Errorf("failed to retrieve snapshot class %s from the API server: %q", className, err)
|
||||
@@ -795,7 +781,7 @@ func (ctrl *csiSnapshotController) SetDefaultSnapshotClass(snapshot *crdv1.Volum
|
||||
defaultClasses := []*crdv1.VolumeSnapshotClass{}
|
||||
|
||||
for _, class := range list {
|
||||
if IsDefaultAnnotation(class.ObjectMeta) && storageclass.Provisioner == class.Snapshotter {
|
||||
if IsDefaultAnnotation(class.ObjectMeta) && storageclass.Provisioner == class.Snapshotter && ctrl.snapshotterName == class.Snapshotter {
|
||||
defaultClasses = append(defaultClasses, class)
|
||||
glog.V(5).Infof("get defaultClass added: %s", class.Name)
|
||||
}
|
||||
|
@@ -28,7 +28,6 @@ import (
|
||||
"github.com/kubernetes-csi/external-snapshotter/pkg/connection"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
@@ -275,7 +274,7 @@ func (ctrl *csiSnapshotController) contentWorker() {
|
||||
// Skip update if content is for another CSI driver
|
||||
snapshotClassName := content.Spec.VolumeSnapshotClassName
|
||||
if snapshotClassName != nil {
|
||||
if snapshotClass, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotClasses().Get(*snapshotClassName, metav1.GetOptions{}); err == nil {
|
||||
if snapshotClass, err := ctrl.classLister.Get(*snapshotClassName); err == nil {
|
||||
if snapshotClass.Snapshotter != ctrl.snapshotterName {
|
||||
return false
|
||||
}
|
||||
@@ -326,10 +325,10 @@ func (ctrl *csiSnapshotController) contentWorker() {
|
||||
// in external controller.
|
||||
func (ctrl *csiSnapshotController) shouldProcessSnapshot(snapshot *crdv1.VolumeSnapshot) bool {
|
||||
className := snapshot.Spec.VolumeSnapshotClassName
|
||||
glog.V(5).Infof("shouldProcessSnapshot [%s]: VolumeSnapshotClassName [%s]", snapshot.Name, *className)
|
||||
var class *crdv1.VolumeSnapshotClass
|
||||
var err error
|
||||
if className != nil {
|
||||
glog.V(5).Infof("shouldProcessSnapshot [%s]: VolumeSnapshotClassName [%s]", snapshot.Name, *className)
|
||||
class, err = ctrl.GetSnapshotClass(*className)
|
||||
if err != nil {
|
||||
glog.Errorf("shouldProcessSnapshot failed to getSnapshotClass %s", err)
|
||||
@@ -337,6 +336,7 @@ func (ctrl *csiSnapshotController) shouldProcessSnapshot(snapshot *crdv1.VolumeS
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
glog.V(5).Infof("shouldProcessSnapshot [%s]: SetDefaultSnapshotClass", snapshot.Name)
|
||||
class, snapshot, err = ctrl.SetDefaultSnapshotClass(snapshot)
|
||||
if err != nil {
|
||||
glog.Errorf("shouldProcessSnapshot failed to setDefaultClass %s", err)
|
||||
|
Reference in New Issue
Block a user