Skip to content

Commit 6515b76

Browse files
committed
controller: add --allow-insecure-registry flag
Allow falling back to HTTP when resolving tag-based image refs against registries that do not serve TLS. Assisted-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Alice Frosi <afrosi@redhat.com>
1 parent dbbde4a commit 6515b76

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

cmd/controller/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ func main() {
3434
var enableLeaderElection bool
3535
var probeAddr string
3636
var tagResolutionInterval time.Duration
37+
var allowInsecureRegistry bool
3738
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
3839
flag.DurationVar(&tagResolutionInterval, "tag-resolution-interval", 5*time.Minute, "How often to re-resolve tag-based image refs.")
40+
flag.BoolVar(&allowInsecureRegistry, "allow-insecure-registry", false,
41+
"Allow falling back to HTTP when resolving tag-based image refs against registries that do not serve TLS.")
3942
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
4043
"Enable leader election for controller manager. "+
4144
"Enabling this will ensure there is only one active controller manager.")
@@ -68,7 +71,7 @@ func main() {
6871
Client: mgr.GetClient(),
6972
Scheme: mgr.GetScheme(),
7073
KubeClient: kubeClient,
71-
TagResolver: &registry.GGCRResolver{},
74+
TagResolver: &registry.GGCRResolver{AllowInsecure: allowInsecureRegistry},
7275
TagResolutionInterval: tagResolutionInterval,
7376
}).SetupWithManager(mgr); err != nil {
7477
setupLog.Error(err, "Failed to create controller", "controller", "bootcnodepool")

internal/registry/resolver.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,25 @@ type TagResolver interface {
1414
}
1515

1616
// GGCRResolver resolves image tags to digests using go-containerregistry.
17-
type GGCRResolver struct{}
17+
type GGCRResolver struct {
18+
// AllowInsecure enables fallback to HTTP when the HTTPS connection
19+
// to the registry fails.
20+
AllowInsecure bool
21+
}
1822

1923
func (r *GGCRResolver) Resolve(ctx context.Context, ref string) (string, error) {
2024
parsed, err := name.ParseReference(ref)
2125
if err != nil {
2226
return "", fmt.Errorf("parsing reference %q: %w", ref, err)
2327
}
2428
desc, err := remote.Get(parsed, remote.WithContext(ctx))
29+
if err != nil && r.AllowInsecure {
30+
insecure, parseErr := name.ParseReference(ref, name.Insecure)
31+
if parseErr != nil {
32+
return "", fmt.Errorf("parsing reference %q: %w", ref, parseErr)
33+
}
34+
desc, err = remote.Get(insecure, remote.WithContext(ctx))
35+
}
2536
if err != nil {
2637
return "", fmt.Errorf("fetching manifest for %q: %w", ref, err)
2738
}

0 commit comments

Comments
 (0)