mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
Remove custom hash function, generate a random UUID for snapshot and snapcontent name instead
This commit is contained in:
parent
86af5a5ec3
commit
7918f69055
@ -35,10 +35,12 @@ go_library(
|
||||
"//staging/src/k8s.io/apimachinery/pkg/fields:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/errors:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/rand:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/util/uuid:go_default_library",
|
||||
"//staging/src/k8s.io/apiserver/pkg/storage/names:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/dynamic:go_default_library",
|
||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||
|
@ -34,6 +34,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
@ -46,7 +47,6 @@ import (
|
||||
e2evolume "k8s.io/kubernetes/test/e2e/framework/volume"
|
||||
"k8s.io/kubernetes/test/e2e/storage/podlogs"
|
||||
"k8s.io/kubernetes/test/e2e/storage/testpatterns"
|
||||
"k8s.io/kubernetes/test/e2e/storage/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -572,13 +572,13 @@ func getSnapshot(claimName string, ns, snapshotClassName string) *unstructured.U
|
||||
|
||||
return snapshot
|
||||
}
|
||||
func getPreProvisionedSnapshot(snapshotContentName, ns, snapshotHandle string) *unstructured.Unstructured {
|
||||
func getPreProvisionedSnapshot(snapName, ns, snapshotContentName string) *unstructured.Unstructured {
|
||||
snapshot := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": "VolumeSnapshot",
|
||||
"apiVersion": snapshotAPIVersion,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": getPreProvisionedSnapshotName(snapshotHandle),
|
||||
"name": snapName,
|
||||
"namespace": ns,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
@ -591,13 +591,13 @@ func getPreProvisionedSnapshot(snapshotContentName, ns, snapshotHandle string) *
|
||||
|
||||
return snapshot
|
||||
}
|
||||
func getPreProvisionedSnapshotContent(snapshotName, snapshotNamespace, snapshotHandle, deletionPolicy, csiDriverName string) *unstructured.Unstructured {
|
||||
func getPreProvisionedSnapshotContent(snapcontentName, snapshotName, snapshotNamespace, snapshotHandle, deletionPolicy, csiDriverName string) *unstructured.Unstructured {
|
||||
snapshotContent := &unstructured.Unstructured{
|
||||
Object: map[string]interface{}{
|
||||
"kind": "VolumeSnapshotContent",
|
||||
"apiVersion": snapshotAPIVersion,
|
||||
"metadata": map[string]interface{}{
|
||||
"name": getPreProvisionedSnapshotContentName(snapshotHandle),
|
||||
"name": snapcontentName,
|
||||
},
|
||||
"spec": map[string]interface{}{
|
||||
"source": map[string]interface{}{
|
||||
@ -616,12 +616,12 @@ func getPreProvisionedSnapshotContent(snapshotName, snapshotNamespace, snapshotH
|
||||
return snapshotContent
|
||||
}
|
||||
|
||||
func getPreProvisionedSnapshotContentName(snapshotHandle string) string {
|
||||
return fmt.Sprintf("pre-provisioned-snapcontent-%s", utils.GenShortHash(snapshotHandle))
|
||||
func getPreProvisionedSnapshotContentName(uuid types.UID) string {
|
||||
return fmt.Sprintf("pre-provisioned-snapcontent-%s", string(uuid))
|
||||
}
|
||||
|
||||
func getPreProvisionedSnapshotName(snapshotHandle string) string {
|
||||
return fmt.Sprintf("pre-provisioned-snapshot-%s", utils.GenShortHash(snapshotHandle))
|
||||
func getPreProvisionedSnapshotName(uuid types.UID) string {
|
||||
return fmt.Sprintf("pre-provisioned-snapshot-%s", string(uuid))
|
||||
}
|
||||
|
||||
// StartPodLogs begins capturing log output and events from current
|
||||
|
@ -30,6 +30,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apimachinery/pkg/util/uuid"
|
||||
"k8s.io/client-go/dynamic"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/kubernetes/test/e2e/framework"
|
||||
@ -458,12 +459,17 @@ func CreateSnapshotResource(sDriver SnapshottableTestDriver, config *PerTestConf
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("creating a snapshot content with the snapshot handle")
|
||||
r.Vscontent = getPreProvisionedSnapshotContent(getPreProvisionedSnapshotName(snapshotHandle), pvcNamespace, snapshotHandle, pattern.SnapshotDeletionPolicy.String(), csiDriverName)
|
||||
uuid := uuid.NewUUID()
|
||||
|
||||
snapName := getPreProvisionedSnapshotName(uuid)
|
||||
snapcontentName := getPreProvisionedSnapshotContentName(uuid)
|
||||
|
||||
r.Vscontent = getPreProvisionedSnapshotContent(snapcontentName, snapName, pvcNamespace, snapshotHandle, pattern.SnapshotDeletionPolicy.String(), csiDriverName)
|
||||
r.Vscontent, err = dc.Resource(SnapshotContentGVR).Create(context.TODO(), r.Vscontent, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("creating a snapshot with that snapshot content")
|
||||
r.Vs = getPreProvisionedSnapshot(getPreProvisionedSnapshotContentName(snapshotHandle), pvcNamespace, snapshotHandle)
|
||||
r.Vs = getPreProvisionedSnapshot(snapName, pvcNamespace, snapcontentName)
|
||||
r.Vs, err = dc.Resource(SnapshotGVR).Namespace(r.Vs.GetNamespace()).Create(context.TODO(), r.Vs, metav1.CreateOptions{})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
|
@ -18,7 +18,6 @@ package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
@ -786,11 +785,3 @@ func WaitUntil(poll, timeout time.Duration, checkDone func() bool) bool {
|
||||
framework.Logf("WaitUntil failed after reaching the timeout %v", timeout)
|
||||
return false
|
||||
}
|
||||
|
||||
// GenShortHash returns the first 7 hex characters of the sha1 hash of string s
|
||||
func GenShortHash(s string) string {
|
||||
h := sha1.New()
|
||||
h.Write([]byte(s))
|
||||
bs := h.Sum(nil)
|
||||
return fmt.Sprintf("%x", bs)[:7]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user