Skip to content

Commit 3554dfb

Browse files
committed
Don't hard-code names of configmaps used for artifact persistence
This allows users to rename the config maps so long as they also update the env var value specified in controller.yaml
1 parent 9c9317a commit 3554dfb

File tree

8 files changed

+110
-101
lines changed

8 files changed

+110
-101
lines changed

config/controller.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ spec:
6161
value: config-logging
6262
- name: CONFIG_OBSERVABILITY_NAME
6363
value: config-observability
64+
- name: CONFIG_ARTIFACT_BUCKET_NAME
65+
value: config-artifact-bucket
66+
- name: CONFIG_ARTIFACT_PVC_NAME
67+
value: config-artifact-pvc
6468
- name: METRICS_DOMAIN
6569
value: tekton.dev/pipeline
6670
volumes:

pkg/artifacts/artifact_storage_test.go

Lines changed: 60 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -53,50 +53,44 @@ var (
5353
}
5454
defaultStorageClass *string
5555
customStorageClass = "custom-storage-class"
56-
persistentVolumeClaim = GetPersistentVolumeClaim(DefaultPvcSize, defaultStorageClass)
56+
persistentVolumeClaim = GetPersistentVolumeClaim(DefaultPVCSize, defaultStorageClass)
5757
quantityComparer = cmp.Comparer(func(x, y resource.Quantity) bool {
5858
return x.Cmp(y) == 0
5959
})
6060

61-
pipelineWithtasksWithFrom = v1alpha1.Pipeline{
61+
pipelineWithTasksWithFrom = v1alpha1.Pipeline{
6262
Spec: v1alpha1.PipelineSpec{
63-
Resources: []v1alpha1.PipelineDeclaredResource{
64-
{
65-
Name: "input1",
66-
Type: "git",
63+
Resources: []v1alpha1.PipelineDeclaredResource{{
64+
Name: "input1",
65+
Type: "git",
66+
}, {
67+
Name: "output",
68+
Type: "git",
69+
}},
70+
Tasks: []v1alpha1.PipelineTask{{
71+
Name: "task1",
72+
TaskRef: v1alpha1.TaskRef{
73+
Name: "task",
6774
},
68-
{
69-
Name: "output",
70-
Type: "git",
75+
Resources: &v1alpha1.PipelineTaskResources{
76+
Outputs: []v1alpha1.PipelineTaskOutputResource{{
77+
Name: "foo",
78+
Resource: "output",
79+
}},
7180
},
72-
},
73-
Tasks: []v1alpha1.PipelineTask{
74-
{
75-
Name: "task1",
76-
TaskRef: v1alpha1.TaskRef{
77-
Name: "task",
78-
},
79-
Resources: &v1alpha1.PipelineTaskResources{
80-
Outputs: []v1alpha1.PipelineTaskOutputResource{{
81-
Name: "foo",
82-
Resource: "output",
83-
}},
84-
},
81+
}, {
82+
Name: "task2",
83+
TaskRef: v1alpha1.TaskRef{
84+
Name: "task",
8585
},
86-
{
87-
Name: "task2",
88-
TaskRef: v1alpha1.TaskRef{
89-
Name: "task",
90-
},
91-
Resources: &v1alpha1.PipelineTaskResources{
92-
Inputs: []v1alpha1.PipelineTaskInputResource{{
93-
Name: "foo",
94-
Resource: "output",
95-
From: []string{"task1"},
96-
}},
97-
},
86+
Resources: &v1alpha1.PipelineTaskResources{
87+
Inputs: []v1alpha1.PipelineTaskInputResource{{
88+
Name: "foo",
89+
Resource: "output",
90+
From: []string{"task1"},
91+
}},
9892
},
99-
},
93+
}},
10094
},
10195
}
10296
)
@@ -124,7 +118,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
124118
configMap: &corev1.ConfigMap{
125119
ObjectMeta: metav1.ObjectMeta{
126120
Namespace: system.GetNamespace(),
127-
Name: BucketConfigName,
121+
Name: GetBucketConfigName(),
128122
},
129123
Data: map[string]string{
130124
BucketLocationKey: "gs://fake-bucket",
@@ -138,7 +132,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
138132
configMap: &corev1.ConfigMap{
139133
ObjectMeta: metav1.ObjectMeta{
140134
Namespace: system.GetNamespace(),
141-
Name: BucketConfigName,
135+
Name: GetBucketConfigName(),
142136
},
143137
Data: map[string]string{
144138
BucketLocationKey: "",
@@ -152,7 +146,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
152146
configMap: &corev1.ConfigMap{
153147
ObjectMeta: metav1.ObjectMeta{
154148
Namespace: system.GetNamespace(),
155-
Name: BucketConfigName,
149+
Name: GetBucketConfigName(),
156150
},
157151
Data: map[string]string{
158152
BucketServiceAccountSecretName: "secret1",
@@ -165,7 +159,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
165159
configMap: &corev1.ConfigMap{
166160
ObjectMeta: metav1.ObjectMeta{
167161
Namespace: system.GetNamespace(),
168-
Name: BucketConfigName,
162+
Name: GetBucketConfigName(),
169163
},
170164
},
171165
pvcNeeded: true,
@@ -174,7 +168,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
174168
configMap: &corev1.ConfigMap{
175169
ObjectMeta: metav1.ObjectMeta{
176170
Namespace: system.GetNamespace(),
177-
Name: BucketConfigName,
171+
Name: GetBucketConfigName(),
178172
},
179173
Data: map[string]string{
180174
BucketLocationKey: "gs://fake-bucket",
@@ -207,10 +201,10 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
207201
configMap: &corev1.ConfigMap{
208202
ObjectMeta: metav1.ObjectMeta{
209203
Namespace: system.GetNamespace(),
210-
Name: PvcConfigName,
204+
Name: GetPVCConfigName(),
211205
},
212206
Data: map[string]string{
213-
PvcSizeKey: "10Gi",
207+
PVCSizeKey: "10Gi",
214208
},
215209
},
216210
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
@@ -224,10 +218,10 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
224218
configMap: &corev1.ConfigMap{
225219
ObjectMeta: metav1.ObjectMeta{
226220
Namespace: system.GetNamespace(),
227-
Name: PvcConfigName,
221+
Name: GetPVCConfigName(),
228222
},
229223
Data: map[string]string{
230-
PvcStorageClassNameKey: customStorageClass,
224+
PVCStorageClassNameKey: customStorageClass,
231225
},
232226
},
233227
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
@@ -241,7 +235,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
241235
configMap: &corev1.ConfigMap{
242236
ObjectMeta: metav1.ObjectMeta{
243237
Namespace: system.GetNamespace(),
244-
Name: BucketConfigName,
238+
Name: GetBucketConfigName(),
245239
},
246240
Data: map[string]string{
247241
BucketLocationKey: "gs://fake-bucket",
@@ -265,7 +259,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
265259
configMap: &corev1.ConfigMap{
266260
ObjectMeta: metav1.ObjectMeta{
267261
Namespace: system.GetNamespace(),
268-
Name: BucketConfigName,
262+
Name: GetBucketConfigName(),
269263
},
270264
Data: map[string]string{
271265
BucketLocationKey: "",
@@ -284,7 +278,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
284278
configMap: &corev1.ConfigMap{
285279
ObjectMeta: metav1.ObjectMeta{
286280
Namespace: system.GetNamespace(),
287-
Name: BucketConfigName,
281+
Name: GetBucketConfigName(),
288282
},
289283
Data: map[string]string{
290284
BucketServiceAccountSecretName: "secret1",
@@ -302,7 +296,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
302296
configMap: &corev1.ConfigMap{
303297
ObjectMeta: metav1.ObjectMeta{
304298
Namespace: system.GetNamespace(),
305-
Name: BucketConfigName,
299+
Name: GetBucketConfigName(),
306300
},
307301
},
308302
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
@@ -316,7 +310,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
316310
configMap: &corev1.ConfigMap{
317311
ObjectMeta: metav1.ObjectMeta{
318312
Namespace: system.GetNamespace(),
319-
Name: BucketConfigName,
313+
Name: GetBucketConfigName(),
320314
},
321315
Data: map[string]string{
322316
BucketLocationKey: "gs://fake-bucket",
@@ -333,7 +327,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
333327
configMap: &corev1.ConfigMap{
334328
ObjectMeta: metav1.ObjectMeta{
335329
Namespace: system.GetNamespace(),
336-
Name: BucketConfigName,
330+
Name: GetBucketConfigName(),
337331
},
338332
Data: map[string]string{
339333
BucketLocationKey: "s3://fake-bucket",
@@ -356,7 +350,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
356350
}} {
357351
t.Run(c.desc, func(t *testing.T) {
358352
fakekubeclient := fakek8s.NewSimpleClientset(c.configMap)
359-
artifactStorage, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithtasksWithFrom.Spec, fakekubeclient, logger)
353+
artifactStorage, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithTasksWithFrom.Spec, fakekubeclient, logger)
360354
if err != nil {
361355
t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err)
362356
}
@@ -450,18 +444,18 @@ func TestInitializeArtifactStorageNoStorageNeeded(t *testing.T) {
450444
configMap: &corev1.ConfigMap{
451445
ObjectMeta: metav1.ObjectMeta{
452446
Namespace: system.GetNamespace(),
453-
Name: PvcConfigName,
447+
Name: GetPVCConfigName(),
454448
},
455449
Data: map[string]string{
456-
PvcSizeKey: "10Gi",
450+
PVCSizeKey: "10Gi",
457451
},
458452
},
459453
}, {
460454
desc: "has bucket configured",
461455
configMap: &corev1.ConfigMap{
462456
ObjectMeta: metav1.ObjectMeta{
463457
Namespace: system.GetNamespace(),
464-
Name: BucketConfigName,
458+
Name: GetBucketConfigName(),
465459
},
466460
Data: map[string]string{
467461
BucketLocationKey: "gs://fake-bucket",
@@ -474,7 +468,7 @@ func TestInitializeArtifactStorageNoStorageNeeded(t *testing.T) {
474468
configMap: &corev1.ConfigMap{
475469
ObjectMeta: metav1.ObjectMeta{
476470
Namespace: system.GetNamespace(),
477-
Name: BucketConfigName,
471+
Name: GetBucketConfigName(),
478472
},
479473
Data: map[string]string{
480474
BucketLocationKey: "",
@@ -512,7 +506,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
512506
configMap: &corev1.ConfigMap{
513507
ObjectMeta: metav1.ObjectMeta{
514508
Namespace: system.GetNamespace(),
515-
Name: BucketConfigName,
509+
Name: GetBucketConfigName(),
516510
},
517511
Data: map[string]string{
518512
BucketLocationKey: "",
@@ -525,7 +519,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
525519
configMap: &corev1.ConfigMap{
526520
ObjectMeta: metav1.ObjectMeta{
527521
Namespace: system.GetNamespace(),
528-
Name: BucketConfigName,
522+
Name: GetBucketConfigName(),
529523
},
530524
Data: map[string]string{
531525
BucketServiceAccountSecretName: "secret1",
@@ -537,7 +531,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
537531
configMap: &corev1.ConfigMap{
538532
ObjectMeta: metav1.ObjectMeta{
539533
Namespace: system.GetNamespace(),
540-
Name: BucketConfigName,
534+
Name: GetBucketConfigName(),
541535
},
542536
},
543537
}} {
@@ -570,7 +564,7 @@ func TestInitializeArtifactStorageWithoutConfigMap(t *testing.T) {
570564
logger := logtesting.TestLogger(t)
571565
fakekubeclient := fakek8s.NewSimpleClientset()
572566

573-
pvc, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithtasksWithFrom.Spec, fakekubeclient, logger)
567+
pvc, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithTasksWithFrom.Spec, fakekubeclient, logger)
574568
if err != nil {
575569
t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err)
576570
}
@@ -603,7 +597,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
603597
configMap: &corev1.ConfigMap{
604598
ObjectMeta: metav1.ObjectMeta{
605599
Namespace: system.GetNamespace(),
606-
Name: BucketConfigName,
600+
Name: GetBucketConfigName(),
607601
},
608602
Data: map[string]string{
609603
BucketLocationKey: "gs://fake-bucket",
@@ -626,7 +620,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
626620
configMap: &corev1.ConfigMap{
627621
ObjectMeta: metav1.ObjectMeta{
628622
Namespace: system.GetNamespace(),
629-
Name: BucketConfigName,
623+
Name: GetBucketConfigName(),
630624
},
631625
Data: map[string]string{
632626
BucketLocationKey: "",
@@ -643,7 +637,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
643637
configMap: &corev1.ConfigMap{
644638
ObjectMeta: metav1.ObjectMeta{
645639
Namespace: system.GetNamespace(),
646-
Name: BucketConfigName,
640+
Name: GetBucketConfigName(),
647641
},
648642
Data: map[string]string{
649643
BucketServiceAccountSecretName: "secret1",
@@ -659,7 +653,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
659653
configMap: &corev1.ConfigMap{
660654
ObjectMeta: metav1.ObjectMeta{
661655
Namespace: system.GetNamespace(),
662-
Name: BucketConfigName,
656+
Name: GetBucketConfigName(),
663657
},
664658
},
665659
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
@@ -700,7 +694,7 @@ func TestGetArtifactStorageWithoutConfigMap(t *testing.T) {
700694
}
701695
}
702696

703-
func TestGetArtifactStorageWithPvcConfigMap(t *testing.T) {
697+
func TestGetArtifactStorageWithPVCConfigMap(t *testing.T) {
704698
logger := logtesting.TestLogger(t)
705699
prName := "pipelineruntest"
706700
for _, c := range []struct {
@@ -712,10 +706,10 @@ func TestGetArtifactStorageWithPvcConfigMap(t *testing.T) {
712706
configMap: &corev1.ConfigMap{
713707
ObjectMeta: metav1.ObjectMeta{
714708
Namespace: system.GetNamespace(),
715-
Name: PvcConfigName,
709+
Name: GetPVCConfigName(),
716710
},
717711
Data: map[string]string{
718-
PvcSizeKey: "10Gi",
712+
PVCSizeKey: "10Gi",
719713
},
720714
},
721715
expectedArtifactStorage: &v1alpha1.ArtifactPVC{

0 commit comments

Comments
 (0)