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

imagerepo: Continue scan for unconfigured provider #290

Merged
merged 1 commit into from
Jul 26, 2022
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
20 changes: 13 additions & 7 deletions controllers/imagerepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"github.com/fluxcd/pkg/runtime/predicates"

imagev1 "github.com/fluxcd/image-reflector-controller/api/v1beta1"
"github.com/fluxcd/image-reflector-controller/internal/registry"
"github.com/fluxcd/image-reflector-controller/internal/registry/login"
)

Expand Down Expand Up @@ -257,13 +258,18 @@ func (r *ImageRepositoryReconciler) scan(ctx context.Context, imageRepo *imagev1
auth, authErr = login.NewManager().Login(ctx, imageRepo.Spec.Image, ref, r.ProviderOptions)
}
if authErr != nil {
imagev1.SetImageRepositoryReadiness(
imageRepo,
metav1.ConditionFalse,
imagev1.ReconciliationFailedReason,
authErr.Error(),
)
return authErr
// If it's not unconfigured provider error, abort reconciliation.
// Continue reconciliation if it's unconfigured providers for scanning
// public repositories.
if !errors.Is(authErr, registry.ErrUnconfiguredProvider) {
imagev1.SetImageRepositoryReadiness(
imageRepo,
metav1.ConditionFalse,
imagev1.ReconciliationFailedReason,
authErr.Error(),
)
return authErr
}
}
if auth != nil {
options = append(options, remote.WithAuth(auth))
Expand Down
40 changes: 40 additions & 0 deletions controllers/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"
"testing"
"time"

"github.com/fluxcd/pkg/apis/meta"
"github.com/google/go-containerregistry/pkg/authn"
Expand Down Expand Up @@ -492,3 +493,42 @@ func TestImageRepositoryReconciler_authRegistryWithServiceAccount(t *testing.T)
// Cleanup.
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
}

func TestImageRepositoryReconciler_ScanPublicRepos(t *testing.T) {
tests := []struct {
name string
image string
}{
{"gcr", "k8s.gcr.io/coredns/coredns"},
{"ghcr", "ghcr.io/stefanprodan/podinfo"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)
repo := imagev1.ImageRepository{
Spec: imagev1.ImageRepositorySpec{
Interval: metav1.Duration{Duration: time.Hour},
Image: tt.image,
},
}
objectName := types.NamespacedName{
Name: "public-repo" + randStringRunes(5),
Namespace: "default",
}
repo.Name = objectName.Name
repo.Namespace = objectName.Namespace

ctx, cancel := context.WithTimeout(context.TODO(), contextTimeout)
defer cancel()
g.Expect(testEnv.Create(ctx, &repo)).To(Succeed())

g.Eventually(func() bool {
err := testEnv.Get(ctx, objectName, &repo)
return err == nil && repo.Status.LastScanResult != nil
}, timeout, interval).Should(BeTrue())
g.Expect(repo.Status.LastScanResult.TagCount).ToNot(BeZero())
g.Expect(testEnv.Delete(ctx, &repo)).To(Succeed())
})
}
}