forked from tektoncd/pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
artifact_pvc.go
101 lines (85 loc) · 3.55 KB
/
artifact_pvc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
Copyright 2019 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
"fmt"
"strings"
"github.com/tektoncd/pipeline/pkg/names"
corev1 "k8s.io/api/core/v1"
)
var (
pvcDir = "/pvc"
)
// ArtifactPVC represents the pvc created by the pipelinerun
// for artifacts temporary storage
type ArtifactPVC struct {
Name string
PersistentVolumeClaim *corev1.PersistentVolumeClaim
BashNoopImage string
}
// GetType returns the type of the artifact storage
func (p *ArtifactPVC) GetType() string {
return ArtifactStoragePVCType
}
// StorageBasePath returns the path to be used to store artifacts in a pipelinerun temporary storage
func (p *ArtifactPVC) StorageBasePath(pr *PipelineRun) string {
return pvcDir
}
// GetCopyFromStorageToSteps returns a container used to download artifacts from temporary storage
func (p *ArtifactPVC) GetCopyFromStorageToSteps(name, sourcePath, destinationPath string) []Step {
return []Step{{Container: corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-copy-%s", name)),
Image: p.BashNoopImage,
Command: []string{"/ko-app/bash"},
Args: []string{"-args", strings.Join([]string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath}, " ")},
}}}
}
// GetCopyToStorageFromSteps returns a container used to upload artifacts for temporary storage
func (p *ArtifactPVC) GetCopyToStorageFromSteps(name, sourcePath, destinationPath string) []Step {
return []Step{{Container: corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-mkdir-%s", name)),
Image: p.BashNoopImage,
Command: []string{"/ko-app/bash"},
Args: []string{
"-args", strings.Join([]string{"mkdir", "-p", destinationPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{GetPvcMount(p.Name)},
}}, {Container: corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("source-copy-%s", name)),
Image: p.BashNoopImage,
Command: []string{"/ko-app/bash"},
Args: []string{
"-args", strings.Join([]string{"cp", "-r", fmt.Sprintf("%s/.", sourcePath), destinationPath}, " "),
},
VolumeMounts: []corev1.VolumeMount{GetPvcMount(p.Name)},
}}}
}
// GetPvcMount returns a mounting of the volume with the mount path /pvc
func GetPvcMount(name string) corev1.VolumeMount {
return corev1.VolumeMount{
Name: name, // taskrun pvc name
MountPath: pvcDir, // nothing should be mounted here
}
}
// CreateDirStep returns a container step to create a dir
func CreateDirStep(bashNoopImage string, name, destinationPath string) Step {
return Step{Container: corev1.Container{
Name: names.SimpleNameGenerator.RestrictLengthWithRandomSuffix(fmt.Sprintf("create-dir-%s", strings.ToLower(name))),
Image: bashNoopImage,
Command: []string{"/ko-app/bash"},
Args: []string{"-args", strings.Join([]string{"mkdir", "-p", destinationPath}, " ")},
}}
}
// GetSecretsVolumes returns the list of volumes for secrets to be mounted on
// pod.
func (p *ArtifactPVC) GetSecretsVolumes() []corev1.Volume { return nil }