Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return a failure instead of an error if no pinned images are found #1197

Merged
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
8 changes: 7 additions & 1 deletion internal/policy/operator/certified_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func (p *certifiedImagesCheck) dataToValidate(ctx context.Context, imagePath str
func (p *certifiedImagesCheck) validate(ctx context.Context, imageDigests []string) (bool, error) {
logger := logr.FromContextOrDiscard(ctx)

if len(imageDigests) == 0 {
logger.Info("warning: pinned images are expected but none were discovered")
return false, nil
}

pyxisImages, err := p.imageFinder.FindImagesByDigest(ctx, imageDigests)
if err != nil {
return false, err
Expand All @@ -99,7 +104,8 @@ func (p *certifiedImagesCheck) validate(ctx context.Context, imageDigests []stri
p.nonCertifiedImages = append(p.nonCertifiedImages, fullImg)
}
}
return true, nil

return len(p.nonCertifiedImages) == 0, nil
}

func (p *certifiedImagesCheck) Name() string {
Expand Down
12 changes: 6 additions & 6 deletions internal/policy/operator/certified_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,23 @@ spec:
AfterEach(func() {
certifiedImagesCheck.imageFinder = &certifiedImageFinder{}
})
It("should still succeed", func() {
It("should fail", func() {
certifiedImagesCheck.imageFinder = &uncertifiedImageFinder{}
result, err := certifiedImagesCheck.Validate(context.TODO(), imageRef)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
Expect(result).To(BeFalse())
Expect(certifiedImagesCheck.nonCertifiedImages).To(HaveLen(1))
})
})
When("an image in the CSV is not in Pyxis", func() {
AfterEach(func() {
certifiedImagesCheck.imageFinder = &certifiedImageFinder{}
})
It("should still succeed", func() {
It("should fail", func() {
certifiedImagesCheck.imageFinder = &missingImageFinder{}
result, err := certifiedImagesCheck.Validate(context.TODO(), imageRef)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
Expect(result).To(BeFalse())
Expect(certifiedImagesCheck.nonCertifiedImages).To(HaveLen(1))
})
})
Expand All @@ -184,7 +184,7 @@ spec:
})
})
When("the images in the CSV aren't pinned", func() {
It("should succeed, but mark the image as non-certified", func() {
It("should fail", func() {
csvContents := `kind: ClusterServiceVersion
apiVersion: operators.coreos.com/v1alpha1
spec:
Expand All @@ -200,7 +200,7 @@ spec:
Expect(os.WriteFile(filepath.Join(imageRef.ImageFSPath, manifestsDir, clusterServiceVersionFilename), []byte(csvContents), 0o644)).To(Succeed())
result, err := certifiedImagesCheck.Validate(context.TODO(), imageRef)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
Expect(result).To(BeFalse())
Expect(certifiedImagesCheck.nonCertifiedImages).To(HaveLen(1))
})
})
Expand Down