From 7cdd92316d781e602a05749fa8ba5c2c505ffa30 Mon Sep 17 00:00:00 2001 From: pengli Date: Fri, 14 Feb 2020 10:48:14 +0800 Subject: [PATCH] Add random suffix when make volumn from secret To avoid same volumn name when length of secret name is too big(more than 63) --- pkg/pod/creds_init.go | 2 +- pkg/pod/creds_init_test.go | 2 +- pkg/pod/pod_test.go | 4 ++-- pkg/reconciler/taskrun/taskrun.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/pod/creds_init.go b/pkg/pod/creds_init.go index 376a1508473..eb3b853fbf4 100644 --- a/pkg/pod/creds_init.go +++ b/pkg/pod/creds_init.go @@ -65,7 +65,7 @@ func credsInit(credsImage string, serviceAccountName, namespace string, kubeclie } if matched { - name := names.SimpleNameGenerator.RestrictLength(fmt.Sprintf("tekton-internal-secret-volume-%s", secret.Name)) + name := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("tekton-internal-secret-volume-%s", secret.Name)) volumeMounts = append(volumeMounts, corev1.VolumeMount{ Name: name, MountPath: credentials.VolumeName(secret.Name), diff --git a/pkg/pod/creds_init_test.go b/pkg/pod/creds_init_test.go index 22fa8ad53cd..b72681bb5fe 100644 --- a/pkg/pod/creds_init_test.go +++ b/pkg/pod/creds_init_test.go @@ -110,7 +110,7 @@ func TestCredsInit(t *testing.T) { }, Env: envVars, VolumeMounts: append(volumeMounts, corev1.VolumeMount{ - Name: "tekton-internal-secret-volume-my-creds", + Name: "tekton-internal-secret-volume-my-creds-9l9zj", MountPath: "/tekton/creds-secrets/my-creds", }), }, diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 942c4a2e700..8bd14f1a86c 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -45,11 +45,11 @@ func TestMakePod(t *testing.T) { names.TestingSeed() secretsVolumeMount := corev1.VolumeMount{ - Name: "tekton-internal-secret-volume-multi-creds", + Name: "tekton-internal-secret-volume-multi-creds-9l9zj", MountPath: "/tekton/creds-secrets/multi-creds", } secretsVolume := corev1.Volume{ - Name: "tekton-internal-secret-volume-multi-creds", + Name: "tekton-internal-secret-volume-multi-creds-9l9zj", VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{SecretName: "multi-creds"}}, } diff --git a/pkg/reconciler/taskrun/taskrun.go b/pkg/reconciler/taskrun/taskrun.go index 30823d88f96..526a7e459b9 100644 --- a/pkg/reconciler/taskrun/taskrun.go +++ b/pkg/reconciler/taskrun/taskrun.go @@ -539,7 +539,7 @@ func (c *Reconciler) createPod(tr *v1alpha1.TaskRun, rtr *resources.ResolvedTask pod, err := podconvert.MakePod(c.Images, tr, *ts, c.KubeClientSet, c.entrypointCache) if err != nil { - return nil, fmt.Errorf("translating Build to Pod: %w", err) + return nil, fmt.Errorf("translating TaskSpec to Pod: %w", err) } return c.KubeClientSet.CoreV1().Pods(tr.Namespace).Create(pod)