Skip to content

Commit 3f960c3

Browse files
committed
fixup! simplify file name formatting
1 parent ab33f09 commit 3f960c3

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

pkg/handlers/generic/mutation/mirrors/containerd_files.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"net/url"
1111
"path"
12-
"regexp"
1312
"strings"
1413
"text/template"
1514

@@ -60,9 +59,7 @@ func (c containerdConfig) filePathFromURL() (string, error) {
6059
registryHostWithPath = path.Join(registryURL.Host, registryURL.Path)
6160
}
6261

63-
// replace all non-alphanumeric characters with "-"
64-
re := regexp.MustCompile(`[^a-zA-Z0-9]+`)
65-
replaced := re.ReplaceAllString(registryHostWithPath, "-")
62+
replaced := strings.ReplaceAll(registryHostWithPath, "/", "-")
6663

6764
return fmt.Sprintf(mirrorCACertPathOnRemoteFmt, replaced), nil
6865
}
@@ -114,7 +111,10 @@ func generateContainerdHostsFile(
114111
var registryCACertPathOnRemote string
115112
registryCACertPathOnRemote, err = config.filePathFromURL()
116113
if err != nil {
117-
return nil, fmt.Errorf("failed generating CA certificate file path from URL: %w", err)
114+
return nil, fmt.Errorf(
115+
"failed generating CA certificate file path from URL: %w",
116+
err,
117+
)
118118
}
119119
input.CACertPath = registryCACertPathOnRemote
120120
}

pkg/handlers/generic/mutation/mirrors/containerd_files_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func Test_generateContainerdHostsFile(t *testing.T) {
8585
Append: false,
8686
Content: `[host."https://mymirror.com/v2"]
8787
capabilities = ["pull", "resolve"]
88-
ca = "/etc/certs/mymirror-com.pem"
88+
ca = "/etc/certs/mymirror.com.pem"
8989
# don't rely on Containerd to add the v2/ suffix
9090
# there is a bug where it is added incorrectly for mirrors with a path
9191
override_path = true
@@ -105,6 +105,10 @@ func Test_generateContainerdHostsFile(t *testing.T) {
105105
URL: "https://myregistry.com",
106106
CACert: "myregistrycert",
107107
},
108+
{
109+
URL: "https://172.100.0.10:5000/myproject",
110+
CACert: "myregistrycert",
111+
},
108112
},
109113
want: &cabpkv1.File{
110114
Path: "/etc/containerd/certs.d/_default/hosts.toml",
@@ -114,12 +118,14 @@ func Test_generateContainerdHostsFile(t *testing.T) {
114118
Append: false,
115119
Content: `[host."https://mymirror.com/v2"]
116120
capabilities = ["pull", "resolve"]
117-
ca = "/etc/certs/mymirror-com.pem"
121+
ca = "/etc/certs/mymirror.com.pem"
118122
# don't rely on Containerd to add the v2/ suffix
119123
# there is a bug where it is added incorrectly for mirrors with a path
120124
override_path = true
121125
[host."https://myregistry.com/v2"]
122-
ca = "/etc/certs/myregistry-com.pem"
126+
ca = "/etc/certs/myregistry.com.pem"
127+
[host."https://172.100.0.10:5000/v2/myproject"]
128+
ca = "/etc/certs/172.100.0.10:5000-myproject.pem"
123129
`,
124130
},
125131
wantErr: nil,
@@ -139,7 +145,7 @@ func Test_generateContainerdHostsFile(t *testing.T) {
139145
Encoding: "",
140146
Append: false,
141147
Content: `[host."https://myregistry.com/v2"]
142-
ca = "/etc/certs/myregistry-com.pem"
148+
ca = "/etc/certs/myregistry.com.pem"
143149
`,
144150
},
145151
wantErr: nil,
@@ -184,7 +190,7 @@ func Test_generateRegistryCACertFiles(t *testing.T) {
184190
},
185191
want: []cabpkv1.File{
186192
{
187-
Path: "/etc/certs/registry-example-com.pem",
193+
Path: "/etc/certs/registry.example.com.pem",
188194
Owner: "",
189195
Permissions: "0600",
190196
Encoding: "",

pkg/handlers/generic/mutation/mirrors/inject_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ var _ = Describe("Generate Global mirror patches", func() {
102102
"path", "/etc/containerd/certs.d/_default/hosts.toml",
103103
),
104104
gomega.HaveKeyWithValue(
105-
"path", "/etc/certs/registry-example-com.pem",
105+
"path", "/etc/certs/registry.example.com.pem",
106106
),
107107
gomega.HaveKeyWithValue(
108108
"path", "/etc/caren/containerd/patches/registry-config.toml",
@@ -180,7 +180,7 @@ var _ = Describe("Generate Global mirror patches", func() {
180180
"path", "/etc/containerd/certs.d/_default/hosts.toml",
181181
),
182182
gomega.HaveKeyWithValue(
183-
"path", "/etc/certs/registry-example-com.pem",
183+
"path", "/etc/certs/registry.example.com.pem",
184184
),
185185
gomega.HaveKeyWithValue(
186186
"path", "/etc/caren/containerd/patches/registry-config.toml",

0 commit comments

Comments
 (0)