Skip to content

Commit 8de593b

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 d3ba81d commit 8de593b

File tree

3 files changed

+86
-20
lines changed

3 files changed

+86
-20
lines changed

cmd/controller/main.go

Lines changed: 16 additions & 20 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,26 +35,18 @@ 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", "tianon/true", "The container image used to stop sidecars")
40-
affinityAssistantImage = flag.String("affinity-assistant-image", "nginx", "The container image used for the Affinity Assistant")
41-
gitImage = flag.String("git-image", "override-with-git:latest",
42-
"The container image containing our Git binary.")
43-
credsImage = flag.String("creds-image", "override-with-creds:latest",
44-
"The container image for preparing our Build's credentials.")
45-
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "override-with-kubeconfig-writer:latest",
46-
"The container image containing our kubeconfig writer binary.")
47-
shellImage = flag.String("shell-image", "busybox", "The container image containing a shell")
48-
gsutilImage = flag.String("gsutil-image", "google/cloud-sdk",
49-
"The container image containing gsutil")
50-
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "gcr.io/cloud-builders/gcs-fetcher:latest",
51-
"The container image containing our GCS fetcher binary.")
52-
prImage = flag.String("pr-image", "override-with-pr:latest",
53-
"The container image containing our PR binary.")
54-
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "override-with-imagedigest-exporter-image:latest",
55-
"The container image containing our image digest exporter binary.")
56-
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+
affinityAssistantImage = flag.String("affinity-assistant-image", "", "The container image used for the Affinity Assistant")
41+
gitImage = flag.String("git-image", "", "The container image containing our Git binary.")
42+
credsImage = flag.String("creds-image", "", "The container image for preparing our Build's credentials.")
43+
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "", "The container image containing our kubeconfig writer binary.")
44+
shellImage = flag.String("shell-image", "", "The container image containing a shell")
45+
gsutilImage = flag.String("gsutil-image", "", "The container image containing gsutil")
46+
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "", "The container image containing our GCS fetcher binary.")
47+
prImage = flag.String("pr-image", "", "The container image containing our PR binary.")
48+
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
49+
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
5750
)
5851

5952
func main() {
@@ -71,6 +64,9 @@ func main() {
7164
PRImage: *prImage,
7265
ImageDigestExporterImage: *imageDigestExporterImage,
7366
}
67+
if err := images.Validate(); err != nil {
68+
log.Fatal(err)
69+
}
7470
sharedmain.MainWithContext(injection.WithNamespaceScope(signals.NewContext(), *namespace), ControllerLogKey,
7571
taskrun.NewController(*namespace, images),
7672
pipelinerun.NewController(*namespace, images),

pkg/apis/pipeline/images.go

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

1717
package pipeline
1818

19+
import "fmt"
20+
1921
// Images holds the images reference for a number of container images used
2022
// across tektoncd pipelines.
2123
type Images struct {
@@ -42,3 +44,26 @@ type Images struct {
4244
// ImageDigestExporterImage is the container image containing our image digest exporter binary.
4345
ImageDigestExporterImage string
4446
}
47+
48+
// Validate returns an error if any image is not set.
49+
func (i Images) Validate() error {
50+
m := map[string]string{
51+
i.EntrypointImage: "entrypoint",
52+
i.NopImage: "nop",
53+
i.AffinityAssistantImage: "affinity assistant",
54+
i.GitImage: "git",
55+
i.CredsImage: "creds",
56+
i.KubeconfigWriterImage: "kubeconfig writer",
57+
i.ShellImage: "shell",
58+
i.GsutilImage: "gsutil",
59+
i.BuildGCSFetcherImage: "gcs fetcher",
60+
i.PRImage: "pr",
61+
i.ImageDigestExporterImage: "image digest exporter",
62+
}
63+
for k, v := range m {
64+
if k == "" {
65+
return fmt.Errorf("%s image is unset", v)
66+
}
67+
}
68+
return nil
69+
}

pkg/apis/pipeline/images_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
AffinityAssistantImage: "set",
14+
GitImage: "set",
15+
CredsImage: "set",
16+
KubeconfigWriterImage: "set",
17+
ShellImage: "set",
18+
GsutilImage: "set",
19+
BuildGCSFetcherImage: "set",
20+
PRImage: "set",
21+
ImageDigestExporterImage: "set",
22+
}
23+
if err := valid.Validate(); err != nil {
24+
t.Errorf("valid Images returned error: %v", err)
25+
}
26+
27+
invalid := pipeline.Images{
28+
EntrypointImage: "set",
29+
NopImage: "set",
30+
GitImage: "", // unset!
31+
CredsImage: "set",
32+
KubeconfigWriterImage: "set",
33+
ShellImage: "set",
34+
GsutilImage: "set",
35+
BuildGCSFetcherImage: "set",
36+
PRImage: "set",
37+
ImageDigestExporterImage: "set",
38+
}
39+
wantErr := "git image is unset"
40+
if err := invalid.Validate(); err == nil {
41+
t.Error("invalid Images expected error, got nil")
42+
} else if err.Error() != wantErr {
43+
t.Errorf("Unexpected error message: got %q, want %q", err.Error(), wantErr)
44+
}
45+
}

0 commit comments

Comments
 (0)