Add csi_operations_seconds metrics on kubelet

This commit is contained in:
Jiawei Wang
2021-02-10 21:09:38 -08:00
parent 2a05c78600
commit 43bc6fa806
13 changed files with 185 additions and 33 deletions

View File

@@ -26,12 +26,14 @@ import (
"path"
"path/filepath"
"testing"
"time"
api "k8s.io/api/core/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/resource"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/volume"
)
// TestMain starting point for all tests.
@@ -146,3 +148,49 @@ func TestSaveVolumeData(t *testing.T) {
}
}
}
func TestCreateCSIOperationContext(t *testing.T) {
testCases := []struct {
name string
spec *volume.Spec
migrated string
}{
{
name: "test volume spec nil",
spec: nil,
migrated: "false",
},
{
name: "test volume normal spec with migrated true",
spec: &volume.Spec{
Migrated: true,
},
migrated: "true",
},
{
name: "test volume normal spec with migrated false",
spec: &volume.Spec{
Migrated: false,
},
migrated: "false",
},
}
for _, tc := range testCases {
t.Logf("test case: %s", tc.name)
timeout := time.Minute
ctx, _ := createCSIOperationContext(tc.spec, timeout)
additionalInfoVal := ctx.Value(additionalInfoKey)
if additionalInfoVal == nil {
t.Error("Could not load additional info from context")
}
additionalInfoV, ok := additionalInfoVal.(additionalInfo)
if !ok {
t.Errorf("Additional info type assertion fail, additionalInfo object: %v", additionalInfoVal)
}
migrated := additionalInfoV.Migrated
if migrated != tc.migrated {
t.Errorf("Expect migrated value: %v, got: %v", tc.migrated, migrated)
}
}
}