feat: Implement distributed snapshotting
This commit is contained in:
@@ -21,11 +21,28 @@ import (
|
||||
|
||||
crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1"
|
||||
"github.com/kubernetes-csi/external-snapshotter/v4/pkg/utils"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
var deletionPolicy = crdv1.VolumeSnapshotContentDelete
|
||||
|
||||
type FakeNodeLister struct {
|
||||
NodeList []*v1.Node
|
||||
}
|
||||
|
||||
// List lists all Nodes in the indexer.
|
||||
// Objects returned here must be treated as read-only.
|
||||
func (l FakeNodeLister) List(selector labels.Selector) (ret []*v1.Node, err error) {
|
||||
return l.NodeList, nil
|
||||
}
|
||||
|
||||
func (l FakeNodeLister) Get(name string) (*v1.Node, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func storeVersion(t *testing.T, prefix string, c cache.Store, version string, expectedReturn bool) {
|
||||
content := newContent("contentName", "snapuid1-1", "snap1-1", "sid1-1", classGold, "", "pv-handle-1-1", deletionPolicy, nil, nil, false, true)
|
||||
content.ResourceVersion = version
|
||||
@@ -92,3 +109,71 @@ func TestControllerCacheParsingError(t *testing.T) {
|
||||
t.Errorf("Expected parsing error, got nil instead")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetManagedByNode(t *testing.T) {
|
||||
|
||||
// Test that a matching node is found
|
||||
|
||||
node1 := &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "node1",
|
||||
Labels: map[string]string{"key1": "value1"},
|
||||
},
|
||||
}
|
||||
|
||||
node2 := &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "node2",
|
||||
Labels: map[string]string{"key2": "value2"},
|
||||
},
|
||||
}
|
||||
|
||||
ctrl := &csiSnapshotCommonController{
|
||||
nodeLister: FakeNodeLister{NodeList: []*v1.Node{node1, node2}},
|
||||
}
|
||||
|
||||
pv := &v1.PersistentVolume{
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
NodeAffinity: &v1.VolumeNodeAffinity{
|
||||
Required: &v1.NodeSelector{
|
||||
NodeSelectorTerms: []v1.NodeSelectorTerm{
|
||||
{
|
||||
MatchExpressions: []v1.NodeSelectorRequirement{
|
||||
{
|
||||
Key: "key1",
|
||||
Operator: v1.NodeSelectorOpIn,
|
||||
Values: []string{"value1"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
nodeName, err := ctrl.getManagedByNode(pv)
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error occurred: %v", err)
|
||||
}
|
||||
if nodeName != "node1" {
|
||||
t.Errorf("Expected node:%s , Found node: %s instead", "node1", nodeName)
|
||||
}
|
||||
|
||||
// Test that no matching node is found
|
||||
|
||||
node1 = &v1.Node{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "node1",
|
||||
},
|
||||
}
|
||||
|
||||
ctrl = &csiSnapshotCommonController{
|
||||
nodeLister: FakeNodeLister{NodeList: []*v1.Node{node1}},
|
||||
}
|
||||
|
||||
nodeName, _ = ctrl.getManagedByNode(pv)
|
||||
if nodeName != "" {
|
||||
t.Errorf("Expected no node, Found node(%s)", nodeName)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user