Skip to content

Commit 2d7d529

Browse files
committed
Remove default flag values for image names
These values were previously defined in two places (here in flag defaults, and in config/controller.yaml), which could lead to confusing mismatches (#3007)
1 parent a81f43d commit 2d7d529

File tree

3 files changed

+94
-19
lines changed

3 files changed

+94
-19
lines changed

cmd/controller/main.go

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"flag"
21+
"log"
2122

2223
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
2324
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun"
@@ -34,25 +35,17 @@ const (
3435
)
3536

3637
var (
37-
entrypointImage = flag.String("entrypoint-image", "override-with-entrypoint:latest",
38-
"The container image containing our entrypoint binary.")
39-
nopImage = flag.String("nop-image", "override-with-nop:latest", "The container image used to stop sidecars")
40-
gitImage = flag.String("git-image", "override-with-git:latest",
41-
"The container image containing our Git binary.")
42-
credsImage = flag.String("creds-image", "override-with-creds:latest",
43-
"The container image for preparing our Build's credentials.")
44-
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "override-with-kubeconfig-writer:latest",
45-
"The container image containing our kubeconfig writer binary.")
46-
shellImage = flag.String("shell-image", "busybox", "The container image containing a shell")
47-
gsutilImage = flag.String("gsutil-image", "google/cloud-sdk",
48-
"The container image containing gsutil")
49-
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "gcr.io/cloud-builders/gcs-fetcher:latest",
50-
"The container image containing our GCS fetcher binary.")
51-
prImage = flag.String("pr-image", "override-with-pr:latest",
52-
"The container image containing our PR binary.")
53-
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "override-with-imagedigest-exporter-image:latest",
54-
"The container image containing our image digest exporter binary.")
55-
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
38+
entrypointImage = flag.String("entrypoint-image", "", "The container image containing our entrypoint binary.")
39+
nopImage = flag.String("nop-image", "", "The container image used to stop sidecars")
40+
gitImage = flag.String("git-image", "", "The container image containing our Git binary.")
41+
credsImage = flag.String("creds-image", "", "The container image for preparing our Build's credentials.")
42+
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "", "The container image containing our kubeconfig writer binary.")
43+
shellImage = flag.String("shell-image", "", "The container image containing a shell")
44+
gsutilImage = flag.String("gsutil-image", "", "The container image containing gsutil")
45+
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "", "The container image containing our GCS fetcher binary.")
46+
prImage = flag.String("pr-image", "", "The container image containing our PR binary.")
47+
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
48+
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
5649
)
5750

5851
func main() {
@@ -69,6 +62,9 @@ func main() {
6962
PRImage: *prImage,
7063
ImageDigestExporterImage: *imageDigestExporterImage,
7164
}
65+
if err := images.Validate(); err != nil {
66+
log.Fatal(err)
67+
}
7268
sharedmain.MainWithContext(injection.WithNamespaceScope(signals.NewContext(), *namespace), ControllerLogKey,
7369
taskrun.NewController(*namespace, images),
7470
pipelinerun.NewController(*namespace, images),

pkg/apis/pipeline/images.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ limitations under the License.
1616

1717
package pipeline
1818

19+
import (
20+
"fmt"
21+
"sort"
22+
)
23+
1924
// Images holds the images reference for a number of container images used
2025
// across tektoncd pipelines.
2126
type Images struct {
@@ -39,4 +44,34 @@ type Images struct {
3944
PRImage string
4045
// ImageDigestExporterImage is the container image containing our image digest exporter binary.
4146
ImageDigestExporterImage string
47+
48+
// NOTE: Make sure to add any new images to Validate below!
49+
}
50+
51+
// Validate returns an error if any image is not set.
52+
func (i Images) Validate() error {
53+
var unset []string
54+
for _, f := range []struct {
55+
v, name string
56+
}{
57+
{i.EntrypointImage, "entrypoint"},
58+
{i.NopImage, "nop"},
59+
{i.GitImage, "git"},
60+
{i.CredsImage, "creds"},
61+
{i.KubeconfigWriterImage, "kubeconfig-writer"},
62+
{i.ShellImage, "shell"},
63+
{i.GsutilImage, "gsutil"},
64+
{i.BuildGCSFetcherImage, "build-gcs-fetcher"},
65+
{i.PRImage, "pr"},
66+
{i.ImageDigestExporterImage, "imagedigest-exporter"},
67+
} {
68+
if f.v == "" {
69+
unset = append(unset, f.name)
70+
}
71+
}
72+
if len(unset) > 0 {
73+
sort.Strings(unset)
74+
return fmt.Errorf("found unset image flags: %s", unset)
75+
}
76+
return nil
4277
}

pkg/apis/pipeline/images_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package pipeline_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
7+
)
8+
9+
func TestValidate(t *testing.T) {
10+
valid := pipeline.Images{
11+
EntrypointImage: "set",
12+
NopImage: "set",
13+
GitImage: "set",
14+
CredsImage: "set",
15+
KubeconfigWriterImage: "set",
16+
ShellImage: "set",
17+
GsutilImage: "set",
18+
BuildGCSFetcherImage: "set",
19+
PRImage: "set",
20+
ImageDigestExporterImage: "set",
21+
}
22+
if err := valid.Validate(); err != nil {
23+
t.Errorf("valid Images returned error: %v", err)
24+
}
25+
26+
invalid := pipeline.Images{
27+
EntrypointImage: "set",
28+
NopImage: "set",
29+
GitImage: "", // unset!
30+
CredsImage: "set",
31+
KubeconfigWriterImage: "set",
32+
ShellImage: "", // unset!
33+
GsutilImage: "set",
34+
BuildGCSFetcherImage: "", // unset!
35+
PRImage: "", // unset!
36+
ImageDigestExporterImage: "set",
37+
}
38+
wantErr := "found unset image flags: [build-gcs-fetcher git pr shell]"
39+
if err := invalid.Validate(); err == nil {
40+
t.Error("invalid Images expected error, got nil")
41+
} else if err.Error() != wantErr {
42+
t.Errorf("Unexpected error message: got %q, want %q", err.Error(), wantErr)
43+
}
44+
}

0 commit comments

Comments
 (0)