Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
fe2ca9ec
Commit
fe2ca9ec
authored
Mar 07, 2024
by
Brad Davidson
Committed by
Brad Davidson
Mar 07, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Warn and suppress duplicate registry mirror endpoints
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
9bd4c8a9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
+86
-0
config.go
pkg/agent/containerd/config.go
+6
-0
config_test.go
pkg/agent/containerd/config_test.go
+80
-0
No files found.
pkg/agent/containerd/config.go
View file @
fe2ca9ec
...
@@ -99,6 +99,9 @@ func getHostConfigs(registry *registries.Registry, noDefaultEndpoint bool, mirro
...
@@ -99,6 +99,9 @@ func getHostConfigs(registry *registries.Registry, noDefaultEndpoint bool, mirro
}
}
}
}
// track which endpoints we've already seen to avoid creating duplicates
seenEndpoint
:=
map
[
string
]
bool
{}
// TODO: rewrites are currently copied from the mirror settings into each endpoint.
// TODO: rewrites are currently copied from the mirror settings into each endpoint.
// In the future, we should allow for per-endpoint rewrites, instead of expecting
// In the future, we should allow for per-endpoint rewrites, instead of expecting
// all mirrors to have the same structure. This will require changes to the registries.yaml
// all mirrors to have the same structure. This will require changes to the registries.yaml
...
@@ -107,7 +110,10 @@ func getHostConfigs(registry *registries.Registry, noDefaultEndpoint bool, mirro
...
@@ -107,7 +110,10 @@ func getHostConfigs(registry *registries.Registry, noDefaultEndpoint bool, mirro
registryName
,
url
,
override
,
err
:=
normalizeEndpointAddress
(
endpoint
,
mirrorAddr
)
registryName
,
url
,
override
,
err
:=
normalizeEndpointAddress
(
endpoint
,
mirrorAddr
)
if
err
!=
nil
{
if
err
!=
nil
{
logrus
.
Warnf
(
"Ignoring invalid endpoint URL %d=%s for %s: %v"
,
i
,
endpoint
,
host
,
err
)
logrus
.
Warnf
(
"Ignoring invalid endpoint URL %d=%s for %s: %v"
,
i
,
endpoint
,
host
,
err
)
}
else
if
_
,
ok
:=
seenEndpoint
[
url
.
String
()];
ok
{
logrus
.
Warnf
(
"Skipping duplicate endpoint URL %d=%s for %s"
,
i
,
endpoint
,
host
)
}
else
{
}
else
{
seenEndpoint
[
url
.
String
()]
=
true
var
rewrites
map
[
string
]
string
var
rewrites
map
[
string
]
string
// Do not apply rewrites to the embedded registry endpoint
// Do not apply rewrites to the embedded registry endpoint
if
url
.
Host
!=
mirrorAddr
{
if
url
.
Host
!=
mirrorAddr
{
...
...
pkg/agent/containerd/config_test.go
View file @
fe2ca9ec
...
@@ -476,6 +476,86 @@ func Test_UnitGetHostConfigs(t *testing.T) {
...
@@ -476,6 +476,86 @@ func Test_UnitGetHostConfigs(t *testing.T) {
},
},
},
},
{
{
name
:
"registry with mirror endpoint - duplicate endpoints"
,
args
:
args
{
registryContent
:
`
mirrors:
docker.io:
endpoint:
- registry.example.com
- registry.example.com
`
,
},
want
:
HostConfigs
{
"docker.io"
:
templates
.
HostConfig
{
Program
:
"k3s"
,
Default
:
&
templates
.
RegistryEndpoint
{
URL
:
u
(
"https://registry-1.docker.io/v2"
),
},
Endpoints
:
[]
templates
.
RegistryEndpoint
{
{
URL
:
u
(
"https://registry.example.com/v2"
),
},
},
},
},
},
{
name
:
"registry with mirror endpoint - duplicate endpoints in different formats"
,
args
:
args
{
registryContent
:
`
mirrors:
docker.io:
endpoint:
- registry.example.com
- https://registry.example.com
- https://registry.example.com/v2
`
,
},
want
:
HostConfigs
{
"docker.io"
:
templates
.
HostConfig
{
Program
:
"k3s"
,
Default
:
&
templates
.
RegistryEndpoint
{
URL
:
u
(
"https://registry-1.docker.io/v2"
),
},
Endpoints
:
[]
templates
.
RegistryEndpoint
{
{
URL
:
u
(
"https://registry.example.com/v2"
),
},
},
},
},
},
{
name
:
"registry with mirror endpoint - duplicate endpoints in different positions"
,
args
:
args
{
registryContent
:
`
mirrors:
docker.io:
endpoint:
- https://registry.example.com
- https://registry.example.org
- https://registry.example.com
`
,
},
want
:
HostConfigs
{
"docker.io"
:
templates
.
HostConfig
{
Program
:
"k3s"
,
Default
:
&
templates
.
RegistryEndpoint
{
URL
:
u
(
"https://registry-1.docker.io/v2"
),
},
Endpoints
:
[]
templates
.
RegistryEndpoint
{
{
URL
:
u
(
"https://registry.example.com/v2"
),
},
{
URL
:
u
(
"https://registry.example.org/v2"
),
},
},
},
},
},
{
name
:
"registry with mirror endpoint - localhost and port only"
,
name
:
"registry with mirror endpoint - localhost and port only"
,
args
:
args
{
args
:
args
{
registryContent
:
`
registryContent
:
`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment