@@ -19,26 +19,28 @@ package sources
19
19
import (
20
20
"testing"
21
21
22
+ "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
23
+ "github.com/GoogleContainerTools/skaffold/testutil"
22
24
"github.com/google/go-cmp/cmp"
23
25
v1 "k8s.io/api/core/v1"
24
26
"k8s.io/apimachinery/pkg/api/resource"
25
27
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
26
-
27
- "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
28
- "github.com/GoogleContainerTools/skaffold/testutil"
29
28
)
30
29
31
30
func TestPodTemplate (t * testing.T ) {
32
31
tests := []struct {
33
32
description string
34
33
initial * latest.ClusterDetails
35
- image string
34
+ artifact * latest. KanikoArtifact
36
35
args []string
37
36
expected * v1.Pod
38
37
}{
39
38
{
40
39
description : "basic pod" ,
41
40
initial : & latest.ClusterDetails {},
41
+ artifact : & latest.KanikoArtifact {
42
+ Image : "kaniko-latest" ,
43
+ },
42
44
expected : & v1.Pod {
43
45
ObjectMeta : metav1.ObjectMeta {
44
46
GenerateName : "kaniko-" ,
@@ -48,75 +50,74 @@ func TestPodTemplate(t *testing.T) {
48
50
RestartPolicy : "Never" ,
49
51
Containers : []v1.Container {
50
52
{
51
- Name : "kaniko" ,
52
- Env : []v1.EnvVar {
53
- {
54
- Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
55
- Value : "/secret/kaniko-secret" ,
56
- },
57
- },
58
- VolumeMounts : []v1.VolumeMount {
59
- {
60
- Name : "kaniko-secret" , MountPath : "/secret" ,
61
- },
62
- },
53
+ Name : "kaniko" ,
54
+ Image : "kaniko-latest" ,
55
+ Env : []v1.EnvVar {{
56
+ Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
57
+ Value : "/secret/kaniko-secret" ,
58
+ }},
59
+ VolumeMounts : []v1.VolumeMount {{
60
+ Name : "kaniko-secret" ,
61
+ MountPath : "/secret" ,
62
+ }},
63
63
ImagePullPolicy : v1 .PullPolicy ("IfNotPresent" ),
64
64
},
65
65
},
66
- Volumes : []v1.Volume {
67
- {
68
- Name : "kaniko-secret" ,
69
- VolumeSource : v1.VolumeSource {
70
- Secret : & v1.SecretVolumeSource {
71
- SecretName : "" ,
72
- },
66
+ Volumes : []v1.Volume {{
67
+ Name : "kaniko-secret" ,
68
+ VolumeSource : v1.VolumeSource {
69
+ Secret : & v1.SecretVolumeSource {
70
+ SecretName : "" ,
73
71
},
74
- },
72
+ }} ,
75
73
},
76
74
},
77
75
},
78
76
},
79
77
{
80
78
description : "with docker config" ,
81
79
initial : & latest.ClusterDetails {
80
+ PullSecretName : "pull-secret" ,
82
81
DockerConfig : & latest.DockerConfig {
83
82
SecretName : "docker-cfg" ,
84
83
Path : "/kaniko/.docker" ,
85
84
},
86
85
},
86
+ artifact : & latest.KanikoArtifact {
87
+ Image : "kaniko-latest" ,
88
+ },
87
89
expected : & v1.Pod {
88
90
ObjectMeta : metav1.ObjectMeta {
89
91
GenerateName : "kaniko-" ,
90
92
Labels : map [string ]string {"skaffold-kaniko" : "skaffold-kaniko" },
91
93
},
92
94
Spec : v1.PodSpec {
93
95
RestartPolicy : "Never" ,
94
- Containers : []v1.Container {
95
- {
96
- Name : "kaniko" ,
97
- Env : []v1.EnvVar {
98
- {
99
- Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
100
- Value : "/secret/kaniko-secret" ,
101
- },
96
+ Containers : []v1.Container {{
97
+ Name : "kaniko" ,
98
+ Image : "kaniko-latest" ,
99
+ Env : []v1.EnvVar {{
100
+ Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
101
+ Value : "/secret/kaniko-secret" ,
102
+ }},
103
+ VolumeMounts : []v1.VolumeMount {
104
+ {
105
+ Name : "kaniko-secret" ,
106
+ MountPath : "/secret" ,
102
107
},
103
- VolumeMounts : []v1.VolumeMount {
104
- {
105
- Name : "kaniko-secret" , MountPath : "/secret" ,
106
- },
107
- {
108
- Name : "docker-cfg" , MountPath : "/kaniko/.docker" ,
109
- },
108
+ {
109
+ Name : "docker-cfg" ,
110
+ MountPath : "/kaniko/.docker" ,
110
111
},
111
- ImagePullPolicy : v1 .PullPolicy ("IfNotPresent" ),
112
112
},
113
- },
113
+ ImagePullPolicy : v1 .PullPolicy ("IfNotPresent" ),
114
+ }},
114
115
Volumes : []v1.Volume {
115
116
{
116
117
Name : "kaniko-secret" ,
117
118
VolumeSource : v1.VolumeSource {
118
119
Secret : & v1.SecretVolumeSource {
119
- SecretName : "" ,
120
+ SecretName : "pull-secret " ,
120
121
},
121
122
},
122
123
},
@@ -146,45 +147,92 @@ func TestPodTemplate(t *testing.T) {
146
147
},
147
148
},
148
149
},
150
+ artifact : & latest.KanikoArtifact {
151
+ Image : "kaniko-latest" ,
152
+ },
149
153
expected : & v1.Pod {
150
154
ObjectMeta : metav1.ObjectMeta {
151
155
GenerateName : "kaniko-" ,
152
156
Labels : map [string ]string {"skaffold-kaniko" : "skaffold-kaniko" },
153
157
},
154
158
Spec : v1.PodSpec {
155
159
RestartPolicy : "Never" ,
156
- Containers : []v1.Container {
157
- {
158
- Name : "kaniko" ,
159
- Env : []v1.EnvVar {
160
- {
161
- Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
162
- Value : "/secret/kaniko-secret" ,
163
- },
160
+ Containers : []v1.Container {{
161
+ Name : "kaniko" ,
162
+ Image : "kaniko-latest" ,
163
+ Env : []v1.EnvVar {{
164
+ Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
165
+ Value : "/secret/kaniko-secret" ,
166
+ }},
167
+ VolumeMounts : []v1.VolumeMount {{
168
+ Name : "kaniko-secret" ,
169
+ MountPath : "/secret" ,
170
+ }},
171
+ ImagePullPolicy : v1 .PullPolicy ("IfNotPresent" ),
172
+ Resources : createResourceRequirements (
173
+ resource .MustParse ("1.0" ),
174
+ resource .MustParse ("2000" ),
175
+ resource .MustParse ("0.5" ),
176
+ resource .MustParse ("1000" )),
177
+ }},
178
+ Volumes : []v1.Volume {{
179
+ Name : "kaniko-secret" ,
180
+ VolumeSource : v1.VolumeSource {
181
+ Secret : & v1.SecretVolumeSource {
182
+ SecretName : "" ,
164
183
},
165
- VolumeMounts : []v1.VolumeMount {
166
- {
167
- Name : "kaniko-secret" , MountPath : "/secret" ,
168
- },
184
+ },
185
+ }},
186
+ },
187
+ },
188
+ },
189
+ {
190
+ description : "with cache" ,
191
+ initial : & latest.ClusterDetails {},
192
+ artifact : & latest.KanikoArtifact {
193
+ Image : "kaniko-latest" ,
194
+ Cache : & latest.KanikoCache {
195
+ HostPath : "/cache-path" ,
196
+ },
197
+ },
198
+ expected : & v1.Pod {
199
+ ObjectMeta : metav1.ObjectMeta {
200
+ GenerateName : "kaniko-" ,
201
+ Labels : map [string ]string {"skaffold-kaniko" : "skaffold-kaniko" },
202
+ },
203
+ Spec : v1.PodSpec {
204
+ RestartPolicy : "Never" ,
205
+ Containers : []v1.Container {{
206
+ Name : "kaniko" ,
207
+ Image : "kaniko-latest" ,
208
+ Env : []v1.EnvVar {{
209
+ Name : "GOOGLE_APPLICATION_CREDENTIALS" ,
210
+ Value : "/secret/kaniko-secret" ,
211
+ }},
212
+ VolumeMounts : []v1.VolumeMount {{
213
+ Name : "kaniko-secret" ,
214
+ MountPath : "/secret" ,
215
+ }, {
216
+ Name : "kaniko-cache" ,
217
+ MountPath : "/cache" ,
218
+ }},
219
+ ImagePullPolicy : v1 .PullPolicy ("IfNotPresent" ),
220
+ }},
221
+ Volumes : []v1.Volume {{
222
+ Name : "kaniko-secret" ,
223
+ VolumeSource : v1.VolumeSource {
224
+ Secret : & v1.SecretVolumeSource {
225
+ SecretName : "" ,
169
226
},
170
- ImagePullPolicy : v1 .PullPolicy ("IfNotPresent" ),
171
- Resources : createResourceRequirements (
172
- resource .MustParse ("1.0" ),
173
- resource .MustParse ("2000" ),
174
- resource .MustParse ("0.5" ),
175
- resource .MustParse ("1000" )),
176
227
},
177
- },
178
- Volumes : []v1.Volume {
179
- {
180
- Name : "kaniko-secret" ,
181
- VolumeSource : v1.VolumeSource {
182
- Secret : & v1.SecretVolumeSource {
183
- SecretName : "" ,
184
- },
228
+ }, {
229
+ Name : "kaniko-cache" ,
230
+ VolumeSource : v1.VolumeSource {
231
+ HostPath : & v1.HostPathVolumeSource {
232
+ Path : "/cache-path" ,
185
233
},
186
234
},
187
- },
235
+ }} ,
188
236
},
189
237
},
190
238
},
@@ -196,7 +244,7 @@ func TestPodTemplate(t *testing.T) {
196
244
197
245
for _ , test := range tests {
198
246
testutil .Run (t , test .description , func (t * testutil.T ) {
199
- actual := podTemplate (test .initial , & latest. KanikoArtifact { Image : test .image , Cache : & latest. KanikoCache {}} , test .args )
247
+ actual := podTemplate (test .initial , test .artifact , test .args )
200
248
201
249
t .CheckDeepEqual (test .expected , actual , opt )
202
250
})
0 commit comments