@@ -1718,13 +1718,13 @@ func TestReconcileWithVolumeClaimTemplateWorkspace(t *testing.T) {
17181718 claimName := "myclaim"
17191719 pipelineRunName := "test-pipeline-run"
17201720 ps := []* v1alpha1.Pipeline {tb .Pipeline ("test-pipeline" , tb .PipelineNamespace ("foo" ), tb .PipelineSpec (
1721- tb .PipelineTask ("hello-world-1" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceName )),
1721+ tb .PipelineTask ("hello-world-1" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceName , "" )),
17221722 tb .PipelineTask ("hello-world-2" , "hello-world" ),
17231723 tb .PipelineWorkspaceDeclaration (workspaceName ),
17241724 ))}
17251725
17261726 prs := []* v1alpha1.PipelineRun {tb .PipelineRun (pipelineRunName , tb .PipelineRunNamespace ("foo" ),
1727- tb .PipelineRunSpec ("test-pipeline" , tb .PipelineRunWorkspaceBindingVolumeClaimTemplate (workspaceName , claimName ))),
1727+ tb .PipelineRunSpec ("test-pipeline" , tb .PipelineRunWorkspaceBindingVolumeClaimTemplate (workspaceName , claimName , "" ))),
17281728 }
17291729 ts := []* v1alpha1.Task {tb .Task ("hello-world" , tb .TaskNamespace ("foo" ))}
17301730
@@ -1792,6 +1792,120 @@ func TestReconcileWithVolumeClaimTemplateWorkspace(t *testing.T) {
17921792 }
17931793}
17941794
1795+ // TestReconcileWithVolumeClaimTemplateWorkspaceUsingSubPaths tests that given a pipeline with volumeClaimTemplate workspace and
1796+ // multiple instances of the same task, but using different subPaths in the volume - is seen as taskRuns with expected subPaths.
1797+ func TestReconcileWithVolumeClaimTemplateWorkspaceUsingSubPaths (t * testing.T ) {
1798+ workspaceName := "ws1"
1799+ workspaceNameWithSubPath := "ws2"
1800+ subPath1 := "customdirectory"
1801+ subPath2 := "otherdirecory"
1802+ pipelineRunWsSubPath := "mypath"
1803+ ps := []* v1alpha1.Pipeline {tb .Pipeline ("test-pipeline" , tb .PipelineNamespace ("foo" ), tb .PipelineSpec (
1804+ tb .PipelineTask ("hello-world-1" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceName , subPath1 )),
1805+ tb .PipelineTask ("hello-world-2" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceName , subPath2 )),
1806+ tb .PipelineTask ("hello-world-3" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceName , "" )),
1807+ tb .PipelineTask ("hello-world-4" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceNameWithSubPath , "" )),
1808+ tb .PipelineTask ("hello-world-5" , "hello-world" , tb .PipelineTaskWorkspaceBinding ("taskWorkspaceName" , workspaceNameWithSubPath , subPath1 )),
1809+ tb .PipelineWorkspaceDeclaration (workspaceName , workspaceNameWithSubPath ),
1810+ ))}
1811+
1812+ prs := []* v1alpha1.PipelineRun {tb .PipelineRun ("test-pipeline-run" , tb .PipelineRunNamespace ("foo" ),
1813+ tb .PipelineRunSpec ("test-pipeline" ,
1814+ tb .PipelineRunWorkspaceBindingVolumeClaimTemplate (workspaceName , "myclaim" , "" ),
1815+ tb .PipelineRunWorkspaceBindingVolumeClaimTemplate (workspaceNameWithSubPath , "myclaim" , pipelineRunWsSubPath ))),
1816+ }
1817+ ts := []* v1alpha1.Task {tb .Task ("hello-world" , tb .TaskNamespace ("foo" ))}
1818+
1819+ d := test.Data {
1820+ PipelineRuns : prs ,
1821+ Pipelines : ps ,
1822+ Tasks : ts ,
1823+ }
1824+
1825+ testAssets , cancel := getPipelineRunController (t , d )
1826+ defer cancel ()
1827+ c := testAssets .Controller
1828+ clients := testAssets .Clients
1829+
1830+ err := c .Reconciler .Reconcile (context .Background (), "foo/test-pipeline-run" )
1831+ if err != nil {
1832+ t .Errorf ("Did not expect to see error when reconciling PipelineRun but saw %s" , err )
1833+ }
1834+
1835+ // Check that the PipelineRun was reconciled correctly
1836+ reconciledRun , err := clients .Pipeline .TektonV1alpha1 ().PipelineRuns ("foo" ).Get ("test-pipeline-run" , metav1.GetOptions {})
1837+ if err != nil {
1838+ t .Fatalf ("Somehow had error getting reconciled run out of fake client: %s" , err )
1839+ }
1840+
1841+ taskRuns , err := clients .Pipeline .TektonV1alpha1 ().TaskRuns ("foo" ).List (metav1.ListOptions {})
1842+ if err != nil {
1843+ t .Fatalf ("unexpected error when listing TaskRuns: %v" , err )
1844+ }
1845+
1846+ if len (taskRuns .Items ) != 5 {
1847+ t .Fatalf ("unexpected number of taskRuns found, expected 2, but found %d" , len (taskRuns .Items ))
1848+ }
1849+
1850+ hasSeenWorkspaceWithPipelineTaskSubPath1 := false
1851+ hasSeenWorkspaceWithPipelineTaskSubPath2 := false
1852+ hasSeenWorkspaceWithEmptyPipelineTaskSubPath := false
1853+ hasSeenWorkspaceWithRunSubPathAndEmptyPipelineTaskSubPath := false
1854+ hasSeenWorkspaceWithRunSubPathAndPipelineTaskSubPath1 := false
1855+ for _ , tr := range taskRuns .Items {
1856+ for _ , ws := range tr .Spec .Workspaces {
1857+
1858+ if ws .PersistentVolumeClaim == nil {
1859+ t .Fatalf ("found taskRun workspace that is not PersistentVolumeClaim workspace. Did only expect PersistentVolumeClaims workspaces" )
1860+ }
1861+
1862+ if ws .SubPath == subPath1 {
1863+ hasSeenWorkspaceWithPipelineTaskSubPath1 = true
1864+ }
1865+
1866+ if ws .SubPath == subPath2 {
1867+ hasSeenWorkspaceWithPipelineTaskSubPath2 = true
1868+ }
1869+
1870+ if ws .SubPath == "" {
1871+ hasSeenWorkspaceWithEmptyPipelineTaskSubPath = true
1872+ }
1873+
1874+ if ws .SubPath == pipelineRunWsSubPath {
1875+ hasSeenWorkspaceWithRunSubPathAndEmptyPipelineTaskSubPath = true
1876+ }
1877+
1878+ if ws .SubPath == fmt .Sprintf ("%s/%s" , pipelineRunWsSubPath , subPath1 ) {
1879+ hasSeenWorkspaceWithRunSubPathAndPipelineTaskSubPath1 = true
1880+ }
1881+ }
1882+ }
1883+
1884+ if ! hasSeenWorkspaceWithPipelineTaskSubPath1 {
1885+ t .Fatalf ("did not see a taskRun with a workspace using pipelineTask subPath1" )
1886+ }
1887+
1888+ if ! hasSeenWorkspaceWithPipelineTaskSubPath2 {
1889+ t .Fatalf ("did not see a taskRun with a workspace using pipelineTask subPath2" )
1890+ }
1891+
1892+ if ! hasSeenWorkspaceWithEmptyPipelineTaskSubPath {
1893+ t .Fatalf ("did not see a taskRun with a workspace using empty pipelineTask subPath" )
1894+ }
1895+
1896+ if ! hasSeenWorkspaceWithRunSubPathAndEmptyPipelineTaskSubPath {
1897+ t .Fatalf ("did not see a taskRun with workspace using empty pipelineTask subPath and a subPath from pipelineRun" )
1898+ }
1899+
1900+ if ! hasSeenWorkspaceWithRunSubPathAndPipelineTaskSubPath1 {
1901+ t .Fatalf ("did not see a taskRun with workspace using pipelineTaks subPath1 and a subPath from pipelineRun" )
1902+ }
1903+
1904+ if ! reconciledRun .Status .GetCondition (apis .ConditionSucceeded ).IsUnknown () {
1905+ t .Errorf ("Expected PipelineRun to be running, but condition status is %s" , reconciledRun .Status .GetCondition (apis .ConditionSucceeded ))
1906+ }
1907+ }
1908+
17951909func TestReconcileWithTaskResults (t * testing.T ) {
17961910 names .TestingSeed ()
17971911 ps := []* v1alpha1.Pipeline {tb .Pipeline ("test-pipeline" , tb .PipelineNamespace ("foo" ), tb .PipelineSpec (
0 commit comments