Skip to content

Commit

Permalink
fix(CNV-52011): generate random VMExport secret name
Browse files Browse the repository at this point in the history
When running disk-uploader it creates
VMExport secret to store a token that
required by the Export API endpoints.

Currently the name of VMExport secret
is not random generated and will fail to
be created again if the disk-uploader
(as a Tekton Task) will run twice.
As a result, it throws a panic error that
causes the failure of the execution.

Signed-off-by: Ben Oukhanov <[email protected]>
  • Loading branch information
codingben committed Nov 27, 2024
1 parent 796c31b commit 9b539e1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/disk-uploader/pkg/secrets/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"crypto/rand"
"fmt"
"math/big"
"strings"

"github.com/kubevirt/kubevirt-tekton-tasks/modules/shared/pkg/ownerreference"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8srand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/client-go/kubernetes"
)

Expand All @@ -22,7 +24,7 @@ func CreateVirtualMachineExportSecret(k8sClient kubernetes.Interface, namespace,

v1Secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Name: generateName(name),
Namespace: namespace,
},
StringData: map[string]string{
Expand Down Expand Up @@ -66,3 +68,8 @@ func generateSecureRandomString(n int) (string, error) {

return string(ret), nil
}

func generateName(name string) string {
id := k8srand.String(5)
return strings.Join([]string{name, id}, "-")
}

0 comments on commit 9b539e1

Please sign in to comment.