Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 15 additions & 19 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package main

import (
"flag"
"log"

"github.com/tektoncd/pipeline/pkg/apis/pipeline"
"github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun"
Expand All @@ -34,25 +35,17 @@ const (
)

var (
entrypointImage = flag.String("entrypoint-image", "override-with-entrypoint:latest",
"The container image containing our entrypoint binary.")
nopImage = flag.String("nop-image", "override-with-nop:latest", "The container image used to stop sidecars")
gitImage = flag.String("git-image", "override-with-git:latest",
"The container image containing our Git binary.")
credsImage = flag.String("creds-image", "override-with-creds:latest",
"The container image for preparing our Build's credentials.")
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "override-with-kubeconfig-writer:latest",
"The container image containing our kubeconfig writer binary.")
shellImage = flag.String("shell-image", "busybox", "The container image containing a shell")
gsutilImage = flag.String("gsutil-image", "google/cloud-sdk",
"The container image containing gsutil")
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "gcr.io/cloud-builders/gcs-fetcher:latest",
"The container image containing our GCS fetcher binary.")
prImage = flag.String("pr-image", "override-with-pr:latest",
"The container image containing our PR binary.")
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "override-with-imagedigest-exporter-image:latest",
"The container image containing our image digest exporter binary.")
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
entrypointImage = flag.String("entrypoint-image", "", "The container image containing our entrypoint binary.")
nopImage = flag.String("nop-image", "", "The container image used to stop sidecars")
gitImage = flag.String("git-image", "", "The container image containing our Git binary.")
credsImage = flag.String("creds-image", "", "The container image for preparing our Build's credentials.")
kubeconfigWriterImage = flag.String("kubeconfig-writer-image", "", "The container image containing our kubeconfig writer binary.")
shellImage = flag.String("shell-image", "", "The container image containing a shell")
gsutilImage = flag.String("gsutil-image", "", "The container image containing gsutil")
buildGCSFetcherImage = flag.String("build-gcs-fetcher-image", "", "The container image containing our GCS fetcher binary.")
prImage = flag.String("pr-image", "", "The container image containing our PR binary.")
imageDigestExporterImage = flag.String("imagedigest-exporter-image", "", "The container image containing our image digest exporter binary.")
namespace = flag.String("namespace", corev1.NamespaceAll, "Namespace to restrict informer to. Optional, defaults to all namespaces.")
)

func main() {
Expand All @@ -69,6 +62,9 @@ func main() {
PRImage: *prImage,
ImageDigestExporterImage: *imageDigestExporterImage,
}
if err := images.Validate(); err != nil {
log.Fatal(err)
}
sharedmain.MainWithContext(injection.WithNamespaceScope(signals.NewContext(), *namespace), ControllerLogKey,
taskrun.NewController(*namespace, images),
pipelinerun.NewController(*namespace, images),
Expand Down
35 changes: 35 additions & 0 deletions pkg/apis/pipeline/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ limitations under the License.

package pipeline

import (
"fmt"
"sort"
)

// Images holds the images reference for a number of container images used
// across tektoncd pipelines.
type Images struct {
Expand All @@ -39,4 +44,34 @@ type Images struct {
PRImage string
// ImageDigestExporterImage is the container image containing our image digest exporter binary.
ImageDigestExporterImage string

// NOTE: Make sure to add any new images to Validate below!
}

// Validate returns an error if any image is not set.
func (i Images) Validate() error {
var unset []string
for _, f := range []struct {
v, name string
}{
{i.EntrypointImage, "entrypoint"},
{i.NopImage, "nop"},
{i.GitImage, "git"},
{i.CredsImage, "creds"},
{i.KubeconfigWriterImage, "kubeconfig-writer"},
{i.ShellImage, "shell"},
{i.GsutilImage, "gsutil"},
{i.BuildGCSFetcherImage, "build-gcs-fetcher"},
{i.PRImage, "pr"},
{i.ImageDigestExporterImage, "imagedigest-exporter"},
} {
if f.v == "" {
unset = append(unset, f.name)
}
}
if len(unset) > 0 {
sort.Strings(unset)
return fmt.Errorf("found unset image flags: %s", unset)
}
return nil
}
44 changes: 44 additions & 0 deletions pkg/apis/pipeline/images_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package pipeline_test

import (
"testing"

"github.com/tektoncd/pipeline/pkg/apis/pipeline"
)

func TestValidate(t *testing.T) {
valid := pipeline.Images{
EntrypointImage: "set",
NopImage: "set",
GitImage: "set",
CredsImage: "set",
KubeconfigWriterImage: "set",
ShellImage: "set",
GsutilImage: "set",
BuildGCSFetcherImage: "set",
PRImage: "set",
ImageDigestExporterImage: "set",
}
if err := valid.Validate(); err != nil {
t.Errorf("valid Images returned error: %v", err)
}

invalid := pipeline.Images{
EntrypointImage: "set",
NopImage: "set",
GitImage: "", // unset!
CredsImage: "set",
KubeconfigWriterImage: "set",
ShellImage: "", // unset!
GsutilImage: "set",
BuildGCSFetcherImage: "", // unset!
PRImage: "", // unset!
ImageDigestExporterImage: "set",
}
wantErr := "found unset image flags: [build-gcs-fetcher git pr shell]"
if err := invalid.Validate(); err == nil {
t.Error("invalid Images expected error, got nil")
} else if err.Error() != wantErr {
t.Errorf("Unexpected error message: got %q, want %q", err.Error(), wantErr)
}
}