Skip to content

Commit

Permalink
Don't hard-code names of configmaps used for artifact persistence
Browse files Browse the repository at this point in the history
This allows users to rename the config maps so long as they also update
the env var value specified in controller.yaml
  • Loading branch information
imjasonh committed Dec 10, 2019
1 parent 9c9317a commit 9e2001d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 92 deletions.
4 changes: 4 additions & 0 deletions config/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ spec:
value: config-logging
- name: CONFIG_OBSERVABILITY_NAME
value: config-observability
- name: CONFIG_ARTIFACT_BUCKET_NAME
value: config-artifact-bucket
- name: CONFIG_ARTIFACT_PVC_NAME
value: config-artifact-pvc
- name: METRICS_DOMAIN
value: tekton.dev/pipeline
volumes:
Expand Down
126 changes: 60 additions & 66 deletions pkg/artifacts/artifact_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,50 +53,44 @@ var (
}
defaultStorageClass *string
customStorageClass = "custom-storage-class"
persistentVolumeClaim = GetPersistentVolumeClaim(DefaultPvcSize, defaultStorageClass)
persistentVolumeClaim = GetPersistentVolumeClaim(DefaultPVCSize, defaultStorageClass)
quantityComparer = cmp.Comparer(func(x, y resource.Quantity) bool {
return x.Cmp(y) == 0
})

pipelineWithtasksWithFrom = v1alpha1.Pipeline{
pipelineWithTasksWithFrom = v1alpha1.Pipeline{
Spec: v1alpha1.PipelineSpec{
Resources: []v1alpha1.PipelineDeclaredResource{
{
Name: "input1",
Type: "git",
Resources: []v1alpha1.PipelineDeclaredResource{{
Name: "input1",
Type: "git",
}, {
Name: "output",
Type: "git",
}},
Tasks: []v1alpha1.PipelineTask{{
Name: "task1",
TaskRef: v1alpha1.TaskRef{
Name: "task",
},
{
Name: "output",
Type: "git",
Resources: &v1alpha1.PipelineTaskResources{
Outputs: []v1alpha1.PipelineTaskOutputResource{{
Name: "foo",
Resource: "output",
}},
},
},
Tasks: []v1alpha1.PipelineTask{
{
Name: "task1",
TaskRef: v1alpha1.TaskRef{
Name: "task",
},
Resources: &v1alpha1.PipelineTaskResources{
Outputs: []v1alpha1.PipelineTaskOutputResource{{
Name: "foo",
Resource: "output",
}},
},
}, {
Name: "task2",
TaskRef: v1alpha1.TaskRef{
Name: "task",
},
{
Name: "task2",
TaskRef: v1alpha1.TaskRef{
Name: "task",
},
Resources: &v1alpha1.PipelineTaskResources{
Inputs: []v1alpha1.PipelineTaskInputResource{{
Name: "foo",
Resource: "output",
From: []string{"task1"},
}},
},
Resources: &v1alpha1.PipelineTaskResources{
Inputs: []v1alpha1.PipelineTaskInputResource{{
Name: "foo",
Resource: "output",
From: []string{"task1"},
}},
},
},
}},
},
}
)
Expand Down Expand Up @@ -124,7 +118,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "gs://fake-bucket",
Expand All @@ -138,7 +132,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "",
Expand All @@ -152,7 +146,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketServiceAccountSecretName: "secret1",
Expand All @@ -165,7 +159,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
},
pvcNeeded: true,
Expand All @@ -174,7 +168,7 @@ func TestConfigMapNeedsPVC(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "gs://fake-bucket",
Expand Down Expand Up @@ -207,10 +201,10 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: PvcConfigName,
Name: GetPVCConfigName(),
},
Data: map[string]string{
PvcSizeKey: "10Gi",
PVCSizeKey: "10Gi",
},
},
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
Expand All @@ -224,10 +218,10 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: PvcConfigName,
Name: GetPVCConfigName(),
},
Data: map[string]string{
PvcStorageClassNameKey: customStorageClass,
PVCStorageClassNameKey: customStorageClass,
},
},
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
Expand All @@ -241,7 +235,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "gs://fake-bucket",
Expand All @@ -265,7 +259,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "",
Expand All @@ -284,7 +278,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketServiceAccountSecretName: "secret1",
Expand All @@ -302,7 +296,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
},
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
Expand All @@ -316,7 +310,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "gs://fake-bucket",
Expand All @@ -333,7 +327,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "s3://fake-bucket",
Expand All @@ -356,7 +350,7 @@ func TestInitializeArtifactStorageWithConfigMap(t *testing.T) {
}} {
t.Run(c.desc, func(t *testing.T) {
fakekubeclient := fakek8s.NewSimpleClientset(c.configMap)
artifactStorage, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithtasksWithFrom.Spec, fakekubeclient, logger)
artifactStorage, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithTasksWithFrom.Spec, fakekubeclient, logger)
if err != nil {
t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err)
}
Expand Down Expand Up @@ -450,18 +444,18 @@ func TestInitializeArtifactStorageNoStorageNeeded(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: PvcConfigName,
Name: GetPVCConfigName(),
},
Data: map[string]string{
PvcSizeKey: "10Gi",
PVCSizeKey: "10Gi",
},
},
}, {
desc: "has bucket configured",
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "gs://fake-bucket",
Expand All @@ -474,7 +468,7 @@ func TestInitializeArtifactStorageNoStorageNeeded(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "",
Expand Down Expand Up @@ -512,7 +506,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "",
Expand All @@ -525,7 +519,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketServiceAccountSecretName: "secret1",
Expand All @@ -537,7 +531,7 @@ func TestCleanupArtifactStorage(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
},
}} {
Expand Down Expand Up @@ -570,7 +564,7 @@ func TestInitializeArtifactStorageWithoutConfigMap(t *testing.T) {
logger := logtesting.TestLogger(t)
fakekubeclient := fakek8s.NewSimpleClientset()

pvc, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithtasksWithFrom.Spec, fakekubeclient, logger)
pvc, err := InitializeArtifactStorage(images, pipelinerun, &pipelineWithTasksWithFrom.Spec, fakekubeclient, logger)
if err != nil {
t.Fatalf("Somehow had error initializing artifact storage run out of fake client: %s", err)
}
Expand Down Expand Up @@ -603,7 +597,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "gs://fake-bucket",
Expand All @@ -626,7 +620,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketLocationKey: "",
Expand All @@ -643,7 +637,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
Data: map[string]string{
BucketServiceAccountSecretName: "secret1",
Expand All @@ -659,7 +653,7 @@ func TestGetArtifactStorageWithConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: BucketConfigName,
Name: GetBucketConfigName(),
},
},
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
Expand Down Expand Up @@ -700,7 +694,7 @@ func TestGetArtifactStorageWithoutConfigMap(t *testing.T) {
}
}

func TestGetArtifactStorageWithPvcConfigMap(t *testing.T) {
func TestGetArtifactStorageWithPVCConfigMap(t *testing.T) {
logger := logtesting.TestLogger(t)
prName := "pipelineruntest"
for _, c := range []struct {
Expand All @@ -712,10 +706,10 @@ func TestGetArtifactStorageWithPvcConfigMap(t *testing.T) {
configMap: &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: system.GetNamespace(),
Name: PvcConfigName,
Name: GetPVCConfigName(),
},
Data: map[string]string{
PvcSizeKey: "10Gi",
PVCSizeKey: "10Gi",
},
},
expectedArtifactStorage: &v1alpha1.ArtifactPVC{
Expand Down
Loading

0 comments on commit 9e2001d

Please sign in to comment.