mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-29 05:22:37 +00:00
Add an integration test for volume tags.
This commit is contained in:
parent
400ebf87a1
commit
8c48250a55
@ -33,7 +33,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestProvisionerRunStop(t *testing.T) {
|
func TestProvisionerRunStop(t *testing.T) {
|
||||||
controller, _ := makeTestController()
|
controller, _, _ := makeTestController()
|
||||||
|
|
||||||
if len(controller.stopChannels) != 0 {
|
if len(controller.stopChannels) != 0 {
|
||||||
t.Errorf("Non-running provisioner should not have any stopChannels. Got %v", len(controller.stopChannels))
|
t.Errorf("Non-running provisioner should not have any stopChannels. Got %v", len(controller.stopChannels))
|
||||||
@ -92,15 +92,15 @@ func makeTestClaim() *api.PersistentVolumeClaim {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeTestController() (*PersistentVolumeProvisionerController, *mockControllerClient) {
|
func makeTestController() (*PersistentVolumeProvisionerController, *mockControllerClient, *volume.FakeVolumePlugin) {
|
||||||
mockClient := &mockControllerClient{}
|
mockClient := &mockControllerClient{}
|
||||||
mockVolumePlugin := &volume.FakeVolumePlugin{}
|
mockVolumePlugin := &volume.FakeVolumePlugin{}
|
||||||
controller, _ := NewPersistentVolumeProvisionerController(mockClient, 1*time.Second, nil, mockVolumePlugin, &fake_cloud.FakeCloud{})
|
controller, _ := NewPersistentVolumeProvisionerController(mockClient, 1*time.Second, nil, mockVolumePlugin, &fake_cloud.FakeCloud{})
|
||||||
return controller, mockClient
|
return controller, mockClient, mockVolumePlugin
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReconcileClaim(t *testing.T) {
|
func TestReconcileClaim(t *testing.T) {
|
||||||
controller, mockClient := makeTestController()
|
controller, mockClient, _ := makeTestController()
|
||||||
pvc := makeTestClaim()
|
pvc := makeTestClaim()
|
||||||
|
|
||||||
// watch would have added the claim to the store
|
// watch would have added the claim to the store
|
||||||
@ -132,9 +132,16 @@ func TestReconcileClaim(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkTagValue(t *testing.T, tags map[string]string, tag string, expectedValue string) {
|
||||||
|
value, found := tags[tag]
|
||||||
|
if !found || value != expectedValue {
|
||||||
|
t.Errorf("Expected tag value %s = %s but value %s found", tag, expectedValue, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReconcileVolume(t *testing.T) {
|
func TestReconcileVolume(t *testing.T) {
|
||||||
|
|
||||||
controller, mockClient := makeTestController()
|
controller, mockClient, mockVolumePlugin := makeTestController()
|
||||||
pv := makeTestVolume()
|
pv := makeTestVolume()
|
||||||
pvc := makeTestClaim()
|
pvc := makeTestClaim()
|
||||||
|
|
||||||
@ -163,6 +170,13 @@ func TestReconcileVolume(t *testing.T) {
|
|||||||
if !isAnnotationMatch(pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue, mockClient.volume.Annotations) {
|
if !isAnnotationMatch(pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue, mockClient.volume.Annotations) {
|
||||||
t.Errorf("Expected %s but got %s", pvProvisioningRequiredAnnotationKey, mockClient.volume.Annotations[pvProvisioningRequiredAnnotationKey])
|
t.Errorf("Expected %s but got %s", pvProvisioningRequiredAnnotationKey, mockClient.volume.Annotations[pvProvisioningRequiredAnnotationKey])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the volume plugin was called with correct tags
|
||||||
|
tags := *mockVolumePlugin.LastProvisionerOptions.CloudTags
|
||||||
|
checkTagValue(t, tags, cloudVolumeCreatedForClaimNamespaceTag, pvc.Namespace)
|
||||||
|
checkTagValue(t, tags, cloudVolumeCreatedForClaimNameTag, pvc.Name)
|
||||||
|
checkTagValue(t, tags, cloudVolumeCreatedForVolumeNameTag, pv.Name)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ controllerClient = &mockControllerClient{}
|
var _ controllerClient = &mockControllerClient{}
|
||||||
|
@ -122,6 +122,7 @@ type FakeVolumePlugin struct {
|
|||||||
PluginName string
|
PluginName string
|
||||||
Host VolumeHost
|
Host VolumeHost
|
||||||
Config VolumeConfig
|
Config VolumeConfig
|
||||||
|
LastProvisionerOptions VolumeOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ VolumePlugin = &FakeVolumePlugin{}
|
var _ VolumePlugin = &FakeVolumePlugin{}
|
||||||
@ -160,6 +161,7 @@ func (plugin *FakeVolumePlugin) NewDeleter(spec *Spec) (Deleter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (plugin *FakeVolumePlugin) NewProvisioner(options VolumeOptions) (Provisioner, error) {
|
func (plugin *FakeVolumePlugin) NewProvisioner(options VolumeOptions) (Provisioner, error) {
|
||||||
|
plugin.LastProvisionerOptions = options
|
||||||
return &FakeProvisioner{options, plugin.Host}, nil
|
return &FakeProvisioner{options, plugin.Host}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func TestPersistentVolumeRecycler(t *testing.T) {
|
|||||||
testClient := client.NewOrDie(&client.Config{Host: s.URL, GroupVersion: testapi.Default.GroupVersion()})
|
testClient := client.NewOrDie(&client.Config{Host: s.URL, GroupVersion: testapi.Default.GroupVersion()})
|
||||||
host := volume.NewFakeVolumeHost("/tmp/fake", nil, nil)
|
host := volume.NewFakeVolumeHost("/tmp/fake", nil, nil)
|
||||||
|
|
||||||
plugins := []volume.VolumePlugin{&volume.FakeVolumePlugin{"plugin-name", host, volume.VolumeConfig{}}}
|
plugins := []volume.VolumePlugin{&volume.FakeVolumePlugin{"plugin-name", host, volume.VolumeConfig{}, volume.VolumeOptions{}}}
|
||||||
cloud := &fake_cloud.FakeCloud{}
|
cloud := &fake_cloud.FakeCloud{}
|
||||||
|
|
||||||
binder := persistentvolumecontroller.NewPersistentVolumeClaimBinder(binderClient, 10*time.Second)
|
binder := persistentvolumecontroller.NewPersistentVolumeClaimBinder(binderClient, 10*time.Second)
|
||||||
|
Loading…
Reference in New Issue
Block a user