Skip to content

Commit 39ab2d5

Browse files
authored
Merge pull request #1192 from sudo-bmitch/pr-validation-rm-warnings
Remove validation warnings to stdout
2 parents 036563a + a977bd3 commit 39ab2d5

File tree

1 file changed

+2
-82
lines changed

1 file changed

+2
-82
lines changed

schema/validator.go

Lines changed: 2 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"io"
23-
"os"
2423
"regexp"
2524

2625
digest "github.com/opencontainers/go-digest"
@@ -93,7 +92,8 @@ func (v Validator) validateSchema(src io.Reader) error {
9392
return fmt.Errorf("failed to add spec file %s: %w", file.Name(), err)
9493
}
9594
if len(specURLs[file.Name()]) == 0 {
96-
fmt.Fprintf(os.Stderr, "warning: spec file has no aliases: %s", file.Name())
95+
// this would be a bug in the validation code itself, add any missing entry to schema.go
96+
return fmt.Errorf("spec file has no aliases: %s", file.Name())
9797
}
9898
for _, specURL := range specURLs[file.Name()] {
9999
err = c.AddResource(specURL, bytes.NewReader(specBuf))
@@ -139,20 +139,6 @@ func validateManifest(buf []byte) error {
139139
return fmt.Errorf("manifest format mismatch: %w", err)
140140
}
141141

142-
if header.Config.MediaType != string(v1.MediaTypeImageConfig) {
143-
fmt.Printf("warning: config %s has an unknown media type: %s\n", header.Config.Digest, header.Config.MediaType)
144-
}
145-
146-
for _, layer := range header.Layers {
147-
if layer.MediaType != string(v1.MediaTypeImageLayer) &&
148-
layer.MediaType != string(v1.MediaTypeImageLayerGzip) &&
149-
layer.MediaType != string(v1.MediaTypeImageLayerZstd) &&
150-
layer.MediaType != string(v1.MediaTypeImageLayerNonDistributable) && //nolint:staticcheck
151-
layer.MediaType != string(v1.MediaTypeImageLayerNonDistributableGzip) && //nolint:staticcheck
152-
layer.MediaType != string(v1.MediaTypeImageLayerNonDistributableZstd) { //nolint:staticcheck
153-
fmt.Printf("warning: layer %s has an unknown media type: %s\n", layer.Digest, layer.MediaType)
154-
}
155-
}
156142
return nil
157143
}
158144

@@ -167,7 +153,6 @@ func validateDescriptor(buf []byte) error {
167153
err = header.Digest.Validate()
168154
if errors.Is(err, digest.ErrDigestUnsupported) {
169155
// we ignore unsupported algorithms
170-
fmt.Printf("warning: unsupported digest: %q: %v\n", header.Digest, err)
171156
return nil
172157
}
173158
return err
@@ -181,17 +166,6 @@ func validateIndex(buf []byte) error {
181166
return fmt.Errorf("index format mismatch: %w", err)
182167
}
183168

184-
for _, manifest := range header.Manifests {
185-
if manifest.MediaType != string(v1.MediaTypeImageManifest) {
186-
fmt.Printf("warning: manifest %s has an unknown media type: %s\n", manifest.Digest, manifest.MediaType)
187-
}
188-
if manifest.Platform != nil {
189-
checkPlatform(manifest.Platform.OS, manifest.Platform.Architecture)
190-
checkArchitecture(manifest.Platform.Architecture, manifest.Platform.Variant)
191-
}
192-
193-
}
194-
195169
return nil
196170
}
197171

@@ -203,9 +177,6 @@ func validateConfig(buf []byte) error {
203177
return fmt.Errorf("config format mismatch: %w", err)
204178
}
205179

206-
checkPlatform(header.OS, header.Architecture)
207-
checkArchitecture(header.Architecture, header.Variant)
208-
209180
envRegexp := regexp.MustCompile(`^[^=]+=.*$`)
210181
for _, e := range header.Config.Env {
211182
if !envRegexp.MatchString(e) {
@@ -215,54 +186,3 @@ func validateConfig(buf []byte) error {
215186

216187
return nil
217188
}
218-
219-
func checkArchitecture(Architecture string, Variant string) {
220-
validCombins := map[string][]string{
221-
"arm": {"", "v6", "v7", "v8"},
222-
"arm64": {"", "v8"},
223-
"386": {""},
224-
"amd64": {""},
225-
"ppc64": {""},
226-
"ppc64le": {""},
227-
"mips64": {""},
228-
"mips64le": {""},
229-
"s390x": {""},
230-
"riscv64": {""},
231-
}
232-
for arch, variants := range validCombins {
233-
if arch == Architecture {
234-
for _, variant := range variants {
235-
if variant == Variant {
236-
return
237-
}
238-
}
239-
fmt.Printf("warning: combination of architecture %q and variant %q is not valid.\n", Architecture, Variant)
240-
}
241-
}
242-
fmt.Printf("warning: architecture %q is not supported yet.\n", Architecture)
243-
}
244-
245-
func checkPlatform(OS string, Architecture string) {
246-
validCombins := map[string][]string{
247-
"android": {"arm"},
248-
"darwin": {"386", "amd64", "arm", "arm64"},
249-
"dragonfly": {"amd64"},
250-
"freebsd": {"386", "amd64", "arm"},
251-
"linux": {"386", "amd64", "arm", "arm64", "ppc64", "ppc64le", "mips64", "mips64le", "s390x", "riscv64"},
252-
"netbsd": {"386", "amd64", "arm"},
253-
"openbsd": {"386", "amd64", "arm"},
254-
"plan9": {"386", "amd64"},
255-
"solaris": {"amd64"},
256-
"windows": {"386", "amd64"}}
257-
for os, archs := range validCombins {
258-
if os == OS {
259-
for _, arch := range archs {
260-
if arch == Architecture {
261-
return
262-
}
263-
}
264-
fmt.Printf("warning: combination of os %q and architecture %q is invalid.\n", OS, Architecture)
265-
}
266-
}
267-
fmt.Printf("warning: operating system %q of the bundle is not supported yet.\n", OS)
268-
}

0 commit comments

Comments
 (0)