GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: preserve user-speciffide registry on OpenShift redeploy · knative/func@d707c8b

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • cmd
    • deploy.go
  • pkg
    • config
      • config.go
      • config_test.go
    • k8s
      • openshift.go
      • openshift_unit_test.go
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎cmd/deploy.go‎

Copy file name to clipboardExpand all lines: cmd/deploy.go
+1-3Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,7 @@ func runDeploy(cmd *cobra.Command, newClient ClientFactory) (err error) {
291291
// also update the registry because there is a registry per namespace,
292292
// and their name includes the namespace.
293293
// This saves needing a manual flag ``--registry={destination namespace registry}``
294-
if changingNamespace(f) && k8s.IsOpenShift() {
295-
// TODO(lkingland): this appears to force use of the openshift
296-
// internal registry.
294+
if changingNamespace(f) && k8s.IsOpenShift() && k8s.IsOpenShiftInternalRegistry(f.Registry) {
297295
f.Registry = "image-registry.openshift-image-registry.svc:5000/" + f.Namespace
298296
if cfg.Verbose {
299297
fmt.Fprintf(cmd.OutOrStdout(), "Info: Overriding openshift registry to %s\n", f.Registry)
Collapse file

‎pkg/config/config.go‎

Copy file name to clipboardExpand all lines: pkg/config/config.go
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,15 @@ func (c Global) Configure(f fn.Function) fn.Function {
154154
f.Deploy.Namespace = c.Namespace
155155
}
156156
if c.Registry != "" {
157-
f.Registry = c.Registry
157+
// Apply the config registry unless it's an auto-detected OpenShift
158+
// internal registry that would overwrite a user-configured external
159+
// registry. This prevents OpenShift auto-detection (via RegistryDefault)
160+
// from silently overriding a previously stored registry on redeploy.
161+
// Explicit sources (--registry flag, FUNC_REGISTRY env, global config)
162+
// set non-OpenShift values and are always applied.
163+
if f.Registry == "" || !k8s.IsOpenShiftInternalRegistry(c.Registry) {
164+
f.Registry = c.Registry
165+
}
158166
}
159167
return f
160168
}
Collapse file

‎pkg/config/config_test.go‎

Copy file name to clipboardExpand all lines: pkg/config/config_test.go
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,31 @@ func TestConfigure(t *testing.T) {
269269
t.Error("empty cfg.Registry should not mutate f")
270270
}
271271

272+
// An auto-detected OpenShift internal registry should not overwrite
273+
// a function's stored external registry. This is the key guard for
274+
// https://github.com/knative/func/issues/2172
275+
f = fn.Function{Registry: "docker.io/user"}
276+
cfg = config.Global{Registry: "image-registry.openshift-image-registry.svc:5000/ns"}
277+
f = cfg.Configure(f)
278+
if f.Registry != "docker.io/user" {
279+
t.Errorf("auto-detected OpenShift registry should not overwrite stored external registry, got %q", f.Registry)
280+
}
281+
282+
// But when the function has no registry yet, the OpenShift default should apply.
283+
f = fn.Function{}
284+
f = cfg.Configure(f)
285+
if f.Registry != "image-registry.openshift-image-registry.svc:5000/ns" {
286+
t.Errorf("OpenShift registry should be applied when function has no registry, got %q", f.Registry)
287+
}
288+
289+
// An explicit (non-OpenShift) registry in config should always apply,
290+
// even when the function already has a registry.
291+
f = fn.Function{Registry: "docker.io/user"}
292+
cfg = config.Global{Registry: "quay.io/org"}
293+
f = cfg.Configure(f)
294+
if f.Registry != "quay.io/org" {
295+
t.Errorf("explicit config registry should override function registry, got %q", f.Registry)
296+
}
272297
}
273298

274299
// TestGet_Invalid ensures that attempting to get the value of a nonexistent
Collapse file

‎pkg/k8s/openshift.go‎

Copy file name to clipboardExpand all lines: pkg/k8s/openshift.go
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"crypto/x509"
66
"encoding/pem"
77
"errors"
8+
"strings"
89
"sync"
910
"time"
1011

@@ -93,6 +94,12 @@ func GetDefaultOpenShiftRegistry() string {
9394
return openShiftRegistryHostPort + "/" + ns
9495
}
9596

97+
// IsOpenShiftInternalRegistry returns true if the given registry string
98+
// refers to the OpenShift internal image registry.
99+
func IsOpenShiftInternalRegistry(registry string) bool {
100+
return strings.HasPrefix(registry, openShiftRegistryHost)
101+
}
102+
96103
func GetOpenShiftDockerCredentialLoaders() []creds.CredentialsCallback {
97104
conf := GetClientConfig()
98105

Collapse file

‎pkg/k8s/openshift_unit_test.go‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package k8s
2+
3+
import "testing"
4+
5+
func TestIsOpenShiftInternalRegistry(t *testing.T) {
6+
tests := []struct {
7+
name string
8+
registry string
9+
want bool
10+
}{
11+
{"internal with port and namespace", "image-registry.openshift-image-registry.svc:5000/mynamespace", true},
12+
{"internal without port", "image-registry.openshift-image-registry.svc/mynamespace", true},
13+
{"internal host only", "image-registry.openshift-image-registry.svc", true},
14+
{"docker.io", "docker.io/user", false},
15+
{"ghcr.io", "ghcr.io/user", false},
16+
{"quay.io", "quay.io/user", false},
17+
{"empty string", "", false},
18+
}
19+
for _, tt := range tests {
20+
t.Run(tt.name, func(t *testing.T) {
21+
if got := IsOpenShiftInternalRegistry(tt.registry); got != tt.want {
22+
t.Errorf("IsOpenShiftInternalRegistry(%q) = %v, want %v", tt.registry, got, tt.want)
23+
}
24+
})
25+
}
26+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.