Skip to content

Commit

Permalink
Remove random suffixes on creds-init volumes
Browse files Browse the repository at this point in the history
Removed the random suffixes that used to appear on creds-init volumes. These
didn't serve any purpose that couldn't be equally well-served with an
incrementing integer.

The benefit of doing it this way is that our unit tests become less brittle -
those random suffixes were a source of considerable churn whenever other
volumes were added or removed to test data because the random pool of suffixes
was shared with those other volumes.
  • Loading branch information
Scott authored and tekton-robot committed Apr 30, 2021
1 parent b4943e8 commit d735a4b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 84 deletions.
7 changes: 4 additions & 3 deletions pkg/pod/creds_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,14 @@ func credsInit(ctx context.Context, serviceAccountName, namespace string, kubecl
}

// getCredsInitVolume returns a Volume and VolumeMount for /tekton/creds. Each call
// will return a new volume and volume mount with randomized name.
func getCredsInitVolume(ctx context.Context) (*corev1.Volume, *corev1.VolumeMount) {
// will return a new volume and volume mount. Takes an integer index to append to
// the name of the volume.
func getCredsInitVolume(ctx context.Context, idx int) (*corev1.Volume, *corev1.VolumeMount) {
cfg := config.FromContextOrDefaults(ctx)
if cfg != nil && cfg.FeatureFlags != nil && cfg.FeatureFlags.DisableCredsInit {
return nil, nil
}
name := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(credsInitHomeMountPrefix)
name := fmt.Sprintf("%s-%d", credsInitHomeMountPrefix, idx)
v := corev1.Volume{
Name: name,
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{
Expand Down
2 changes: 1 addition & 1 deletion pkg/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (b *Builder) Build(ctx context.Context, taskRun *v1beta1.TaskRun, taskSpec
// guarantee what UID container runs with. If legacy credential helper (creds-init)
// is disabled via feature flag then these can be nil since we don't want to mount
// the automatic credential volume.
v, vm := getCredsInitVolume(ctx)
v, vm := getCredsInitVolume(ctx, i)
if v != nil && vm != nil {
volumes = append(volumes, *v)
s.VolumeMounts = append(s.VolumeMounts, *vm)
Expand Down
84 changes: 42 additions & 42 deletions pkg/pod/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -162,15 +162,15 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-mz4c7",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, append(append([]corev1.VolumeMount{}, implicitVolumeMounts...), corev1.VolumeMount{
Name: "tekton-internal-secret-volume-multi-creds-9l9zj",
Expand All @@ -226,7 +226,7 @@ func TestPodBuild(t *testing.T) {
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, secretsVolume, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-mz4c7",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -280,14 +280,14 @@ func TestPodBuild(t *testing.T) {
VolumeMounts: append([]corev1.VolumeMount{
toolsMount,
downwardMount,
{Name: "tekton-creds-init-home-9l9zj", MountPath: "/tekton/creds"},
{Name: "tekton-creds-init-home-0", MountPath: "/tekton/creds"},
}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
SecurityContext: &corev1.PodSecurityContext{
Expand Down Expand Up @@ -335,15 +335,15 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -377,15 +377,15 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -430,15 +430,15 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: filepath.Join(pipeline.WorkspaceDir, "test"),
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestPodBuild(t *testing.T) {
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand All @@ -493,7 +493,7 @@ func TestPodBuild(t *testing.T) {
},
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -550,7 +550,7 @@ sidecar-script-heredoc-randomly-generated-mz4c7
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-mssqb",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand All @@ -566,7 +566,7 @@ sidecar-script-heredoc-randomly-generated-mz4c7
VolumeMounts: []corev1.VolumeMount{scriptsVolumeMount},
}},
Volumes: append(implicitVolumes, scriptsVolume, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-mssqb",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -610,7 +610,7 @@ sidecar-script-heredoc-randomly-generated-mz4c7
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand All @@ -624,7 +624,7 @@ sidecar-script-heredoc-randomly-generated-mz4c7
},
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -672,7 +672,7 @@ sidecar-script-heredoc-randomly-generated-mz4c7
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand Down Expand Up @@ -701,7 +701,7 @@ sidecar-script-heredoc-randomly-generated-mz4c7
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, {
Name: "tekton-creds-init-home-mz4c7",
Name: "tekton-creds-init-home-1",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand All @@ -715,10 +715,10 @@ sidecar-script-heredoc-randomly-generated-mz4c7
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}, corev1.Volume{
Name: "tekton-creds-init-home-mz4c7",
Name: "tekton-creds-init-home-1",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down Expand Up @@ -799,7 +799,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: append(implicitEnvVars, corev1.EnvVar{Name: "FOO", Value: "bar"}),
VolumeMounts: append([]corev1.VolumeMount{scriptsVolumeMount, toolsMount, downwardMount, {
Name: "tekton-creds-init-home-6nl7g",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand All @@ -824,7 +824,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: append(implicitEnvVars, corev1.EnvVar{Name: "FOO", Value: "bar"}),
VolumeMounts: append([]corev1.VolumeMount{{Name: "i-have-a-volume-mount"}, scriptsVolumeMount, toolsMount, {
Name: "tekton-creds-init-home-j2tds",
Name: "tekton-creds-init-home-1",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand All @@ -850,21 +850,21 @@ script-heredoc-randomly-generated-78c5n
},
Env: append(implicitEnvVars, corev1.EnvVar{Name: "FOO", Value: "bar"}),
VolumeMounts: append([]corev1.VolumeMount{toolsMount, {
Name: "tekton-creds-init-home-vr6ds",
Name: "tekton-creds-init-home-2",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, scriptsVolume, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-6nl7g",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}, corev1.Volume{
Name: "tekton-creds-init-home-j2tds",
Name: "tekton-creds-init-home-1",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}, corev1.Volume{
Name: "tekton-creds-init-home-vr6ds",
Name: "tekton-creds-init-home-2",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand All @@ -891,7 +891,7 @@ script-heredoc-randomly-generated-78c5n
InitContainers: []corev1.Container{placeToolsInit},
SchedulerName: "there-scheduler",
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
Containers: []corev1.Container{{
Expand All @@ -912,7 +912,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand Down Expand Up @@ -942,7 +942,7 @@ script-heredoc-randomly-generated-78c5n
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{placeToolsInit},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
Containers: []corev1.Container{{
Expand All @@ -963,7 +963,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand Down Expand Up @@ -995,7 +995,7 @@ script-heredoc-randomly-generated-78c5n
RestartPolicy: corev1.RestartPolicyNever,
InitContainers: []corev1.Container{placeToolsInit},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
Containers: []corev1.Container{{
Expand All @@ -1016,7 +1016,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand Down Expand Up @@ -1047,7 +1047,7 @@ script-heredoc-randomly-generated-78c5n
InitContainers: []corev1.Container{placeToolsInit},
HostNetwork: true,
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
Containers: []corev1.Container{{
Expand All @@ -1068,7 +1068,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand Down Expand Up @@ -1113,7 +1113,7 @@ script-heredoc-randomly-generated-78c5n
InitContainers: []corev1.Container{placeToolsInit},
HostNetwork: false,
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
Containers: []corev1.Container{{
Expand All @@ -1134,7 +1134,7 @@ script-heredoc-randomly-generated-78c5n
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Expand Down Expand Up @@ -1176,15 +1176,15 @@ script-heredoc-randomly-generated-78c5n
},
Env: implicitEnvVars,
VolumeMounts: append([]corev1.VolumeMount{toolsMount, downwardMount, {
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
MountPath: "/tekton/creds",
}}, implicitVolumeMounts...),
WorkingDir: pipeline.WorkspaceDir,
Resources: corev1.ResourceRequirements{Requests: allZeroQty()},
TerminationMessagePath: "/tekton/termination",
}},
Volumes: append(implicitVolumes, toolsVolume, downwardVolume, corev1.Volume{
Name: "tekton-creds-init-home-9l9zj",
Name: "tekton-creds-init-home-0",
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{Medium: corev1.StorageMediumMemory}},
}),
},
Expand Down
Loading

0 comments on commit d735a4b

Please sign in to comment.