Detect that a reference mapping is incorrect in release
If someone screws up their image reference, we need to halt because
we can't process it.
@@ -35,6 +35,9 @@ func NewImageMapperFromImageStreamFile(path string, input *imageapi.ImageStream,
if tag.From == nil || tag.From.Kind != "DockerImage" {
continue
}
+ if len(tag.From.Name) == 0 {
+ return nil, fmt.Errorf("Image file %q did not specify a valid target location for tag %q - no from.name for the tag", path, tag.Name)
+ }
ref := ImageReference{SourceRepository: tag.From.Name}
for _, inputTag := range input.Spec.Tags {
if inputTag.Name == tag.Name {
@@ -59,16 +62,26 @@ type ImageReference struct {
TargetPullSpec string
}
+func NopManifestMapper(data []byte) ([]byte, error) {
+ return data, nil
+}
+
func NewImageMapper(images map[string]ImageReference) (ManifestMapper, error) {
repositories := make([]string, 0, len(images))
bySource := make(map[string]string)
for name, ref := range images {
+ if len(ref.SourceRepository) == 0 {
+ return nil, fmt.Errorf("an empty source repository is not allowed for name %q", name)
+ }
if existing, ok := bySource[ref.SourceRepository]; ok {
return nil, fmt.Errorf("the source repository %q was defined more than once (for %q and %q)", ref.SourceRepository, existing, name)
}
bySource[ref.SourceRepository] = name
repositories = append(repositories, regexp.QuoteMeta(ref.SourceRepository))
}
+ if len(repositories) == 0 {
+ return NopManifestMapper, nil
+ }
pattern := fmt.Sprintf(patternImageFormat, strings.Join(repositories, "|"))
re := regexp.MustCompile(pattern)
@@ -84,7 +97,7 @@ func NewImageMapper(images map[string]ImageReference) (ManifestMapper, error) {
ref := images[name]
suffix := parts[3]
- glog.V(2).Infof("found repository %q with locator %q in the input, switching to %q", string(repository), string(suffix), ref.TargetPullSpec)
+ glog.V(2).Infof("found repository %q with locator %q in the input, switching to %q (from pattern %s)", string(repository), string(suffix), ref.TargetPullSpec, pattern)
switch {
case len(suffix) == 0:
// TODO: we found a repository, but no tag or digest - leave it alone for now
