@@ -35,6 +35,7 @@ import (
35
35
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
36
36
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
37
37
"github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1"
38
+ "github.com/tektoncd/pipeline/pkg/spire"
38
39
"github.com/tektoncd/pipeline/test/diff"
39
40
"github.com/tektoncd/pipeline/test/names"
40
41
corev1 "k8s.io/api/core/v1"
@@ -2458,6 +2459,167 @@ func TestPodBuild_TaskLevelResourceRequirements(t *testing.T) {
2458
2459
}
2459
2460
}
2460
2461
2462
+ func TestPodBuildwithSpireEnabled (t * testing.T ) {
2463
+ initContainers := []corev1.Container {entrypointInitContainer (images .EntrypointImage , []v1beta1.Step {{Name : "name" }})}
2464
+ readonly := true
2465
+ for i := range initContainers {
2466
+ c := & initContainers [i ]
2467
+ c .VolumeMounts = append (c .VolumeMounts , corev1.VolumeMount {
2468
+ Name : spire .WorkloadAPI ,
2469
+ MountPath : spire .VolumeMountPath ,
2470
+ ReadOnly : true ,
2471
+ })
2472
+ }
2473
+
2474
+ for _ , c := range []struct {
2475
+ desc string
2476
+ trs v1beta1.TaskRunSpec
2477
+ trAnnotation map [string ]string
2478
+ ts v1beta1.TaskSpec
2479
+ want * corev1.PodSpec
2480
+ wantAnnotations map [string ]string
2481
+ }{{
2482
+ desc : "simple" ,
2483
+ ts : v1beta1.TaskSpec {
2484
+ Steps : []v1beta1.Step {{
2485
+ Name : "name" ,
2486
+ Image : "image" ,
2487
+ Command : []string {"cmd" }, // avoid entrypoint lookup.
2488
+ }},
2489
+ },
2490
+ want : & corev1.PodSpec {
2491
+ RestartPolicy : corev1 .RestartPolicyNever ,
2492
+ InitContainers : initContainers ,
2493
+ Containers : []corev1.Container {{
2494
+ Name : "step-name" ,
2495
+ Image : "image" ,
2496
+ Command : []string {"/tekton/bin/entrypoint" },
2497
+ Args : []string {
2498
+ "-wait_file" ,
2499
+ "/tekton/downward/ready" ,
2500
+ "-wait_file_content" ,
2501
+ "-post_file" ,
2502
+ "/tekton/run/0/out" ,
2503
+ "-termination_path" ,
2504
+ "/tekton/termination" ,
2505
+ "-step_metadata_dir" ,
2506
+ "/tekton/run/0/status" ,
2507
+ "-enable_spire" ,
2508
+ "-entrypoint" ,
2509
+ "cmd" ,
2510
+ "--" ,
2511
+ },
2512
+ VolumeMounts : append ([]corev1.VolumeMount {binROMount , runMount (0 , false ), downwardMount , {
2513
+ Name : "tekton-creds-init-home-0" ,
2514
+ MountPath : "/tekton/creds" ,
2515
+ }, {
2516
+ Name : spire .WorkloadAPI ,
2517
+ MountPath : spire .VolumeMountPath ,
2518
+ ReadOnly : true ,
2519
+ }}, implicitVolumeMounts ... ),
2520
+ TerminationMessagePath : "/tekton/termination" ,
2521
+ }},
2522
+ Volumes : append (implicitVolumes , binVolume , runVolume (0 ), downwardVolume , corev1.Volume {
2523
+ Name : "tekton-creds-init-home-0" ,
2524
+ VolumeSource : corev1.VolumeSource {EmptyDir : & corev1.EmptyDirVolumeSource {Medium : corev1 .StorageMediumMemory }},
2525
+ }, corev1.Volume {
2526
+ Name : spire .WorkloadAPI ,
2527
+ VolumeSource : corev1.VolumeSource {
2528
+ CSI : & corev1.CSIVolumeSource {
2529
+ Driver : "csi.spiffe.io" ,
2530
+ ReadOnly : & readonly ,
2531
+ },
2532
+ },
2533
+ }),
2534
+ ActiveDeadlineSeconds : & defaultActiveDeadlineSeconds ,
2535
+ },
2536
+ }} {
2537
+ t .Run (c .desc , func (t * testing.T ) {
2538
+ featureFlags := map [string ]string {
2539
+ "enable-api-fields" : "alpha" ,
2540
+ "enforce-nonfalsifiability" : "spire" ,
2541
+ }
2542
+ names .TestingSeed ()
2543
+ store := config .NewStore (logtesting .TestLogger (t ))
2544
+ store .OnConfigChanged (
2545
+ & corev1.ConfigMap {
2546
+ ObjectMeta : metav1.ObjectMeta {Name : config .GetFeatureFlagsConfigName (), Namespace : system .Namespace ()},
2547
+ Data : featureFlags ,
2548
+ },
2549
+ )
2550
+ kubeclient := fakek8s .NewSimpleClientset (
2551
+ & corev1.ServiceAccount {ObjectMeta : metav1.ObjectMeta {Name : "default" , Namespace : "default" }},
2552
+ & corev1.ServiceAccount {ObjectMeta : metav1.ObjectMeta {Name : "service-account" , Namespace : "default" },
2553
+ Secrets : []corev1.ObjectReference {{
2554
+ Name : "multi-creds" ,
2555
+ }},
2556
+ },
2557
+ & corev1.Secret {
2558
+ ObjectMeta : metav1.ObjectMeta {
2559
+ Name : "multi-creds" ,
2560
+ Namespace : "default" ,
2561
+ Annotations : map [string ]string {
2562
+ "tekton.dev/docker-0" : "https://us.gcr.io" ,
2563
+ "tekton.dev/docker-1" : "https://docker.io" ,
2564
+ "tekton.dev/git-0" : "github.com" ,
2565
+ "tekton.dev/git-1" : "gitlab.com" ,
2566
+ }},
2567
+ Type : "kubernetes.io/basic-auth" ,
2568
+ Data : map [string ][]byte {
2569
+ "username" : []byte ("foo" ),
2570
+ "password" : []byte ("BestEver" ),
2571
+ },
2572
+ },
2573
+ )
2574
+ var trAnnotations map [string ]string
2575
+ if c .trAnnotation == nil {
2576
+ trAnnotations = map [string ]string {
2577
+ ReleaseAnnotation : fakeVersion ,
2578
+ }
2579
+ } else {
2580
+ trAnnotations = c .trAnnotation
2581
+ trAnnotations [ReleaseAnnotation ] = fakeVersion
2582
+ }
2583
+ tr := & v1beta1.TaskRun {
2584
+ ObjectMeta : metav1.ObjectMeta {
2585
+ Name : "taskrun-name" ,
2586
+ Namespace : "default" ,
2587
+ Annotations : trAnnotations ,
2588
+ },
2589
+ Spec : c .trs ,
2590
+ }
2591
+
2592
+ // No entrypoints should be looked up.
2593
+ entrypointCache := fakeCache {}
2594
+ builder := Builder {
2595
+ Images : images ,
2596
+ KubeClient : kubeclient ,
2597
+ EntrypointCache : entrypointCache ,
2598
+ }
2599
+
2600
+ got , err := builder .Build (store .ToContext (context .Background ()), tr , c .ts )
2601
+ if err != nil {
2602
+ t .Fatalf ("builder.Build: %v" , err )
2603
+ }
2604
+
2605
+ want := kmeta .ChildName (tr .Name , "-pod" )
2606
+ if d := cmp .Diff (got .Name , want ); d != "" {
2607
+ t .Errorf ("got %v; want %v" , got .Name , want )
2608
+ }
2609
+
2610
+ if d := cmp .Diff (c .want , & got .Spec , resourceQuantityCmp , volumeSort , volumeMountSort ); d != "" {
2611
+ t .Errorf ("Diff %s" , diff .PrintWantGot (d ))
2612
+ }
2613
+
2614
+ if c .wantAnnotations != nil {
2615
+ if d := cmp .Diff (c .wantAnnotations , got .ObjectMeta .Annotations , cmpopts .IgnoreMapEntries (ignoreReleaseAnnotation )); d != "" {
2616
+ t .Errorf ("Annotation Diff(-want, +got):\n %s" , d )
2617
+ }
2618
+ }
2619
+ })
2620
+ }
2621
+ }
2622
+
2461
2623
// verifyTaskLevelComputeResources verifies that the given TaskRun's containers have the expected compute resources.
2462
2624
func verifyTaskLevelComputeResources (expectedComputeResources []ExpectedComputeResources , containers []corev1.Container ) error {
2463
2625
if len (expectedComputeResources ) != len (containers ) {
0 commit comments