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
32d62c57
Commit
32d62c57
authored
Jan 30, 2023
by
Brad Davidson
Committed by
Brad Davidson
Feb 09, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use default address family when adding kubernetes service address to SAN list
Signed-off-by:
Brad Davidson
<
brad.davidson@rancher.com
>
parent
a92f163c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
5 deletions
+17
-5
server.go
pkg/cli/server/server.go
+4
-5
net.go
pkg/util/net.go
+13
-0
No files found.
pkg/cli/server/server.go
View file @
32d62c57
...
@@ -204,18 +204,17 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
...
@@ -204,18 +204,17 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
}
}
if
serverConfig
.
ControlConfig
.
PrivateIP
==
""
&&
len
(
cmds
.
AgentConfig
.
NodeIP
)
!=
0
{
if
serverConfig
.
ControlConfig
.
PrivateIP
==
""
&&
len
(
cmds
.
AgentConfig
.
NodeIP
)
!=
0
{
// ignoring the error here is fine since etcd will fall back to the interface's IPv4 address
serverConfig
.
ControlConfig
.
PrivateIP
=
util
.
GetFirstValidIPString
(
cmds
.
AgentConfig
.
NodeIP
)
serverConfig
.
ControlConfig
.
PrivateIP
,
_
,
_
=
util
.
GetFirstString
(
cmds
.
AgentConfig
.
NodeIP
)
}
}
// if not set, try setting advertise-ip from agent node-external-ip
// if not set, try setting advertise-ip from agent node-external-ip
if
serverConfig
.
ControlConfig
.
AdvertiseIP
==
""
&&
len
(
cmds
.
AgentConfig
.
NodeExternalIP
)
!=
0
{
if
serverConfig
.
ControlConfig
.
AdvertiseIP
==
""
&&
len
(
cmds
.
AgentConfig
.
NodeExternalIP
)
!=
0
{
serverConfig
.
ControlConfig
.
AdvertiseIP
,
_
,
_
=
util
.
GetFirst
String
(
cmds
.
AgentConfig
.
NodeExternalIP
)
serverConfig
.
ControlConfig
.
AdvertiseIP
=
util
.
GetFirstValidIP
String
(
cmds
.
AgentConfig
.
NodeExternalIP
)
}
}
// if not set, try setting advertise-ip from agent node-ip
// if not set, try setting advertise-ip from agent node-ip
if
serverConfig
.
ControlConfig
.
AdvertiseIP
==
""
&&
len
(
cmds
.
AgentConfig
.
NodeIP
)
!=
0
{
if
serverConfig
.
ControlConfig
.
AdvertiseIP
==
""
&&
len
(
cmds
.
AgentConfig
.
NodeIP
)
!=
0
{
serverConfig
.
ControlConfig
.
AdvertiseIP
,
_
,
_
=
util
.
GetFirst
String
(
cmds
.
AgentConfig
.
NodeIP
)
serverConfig
.
ControlConfig
.
AdvertiseIP
=
util
.
GetFirstValidIP
String
(
cmds
.
AgentConfig
.
NodeIP
)
}
}
// if we ended up with any advertise-ips, ensure they're added to the SAN list;
// if we ended up with any advertise-ips, ensure they're added to the SAN list;
...
@@ -297,7 +296,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
...
@@ -297,7 +296,7 @@ func run(app *cli.Context, cfg *cmds.Server, leaderControllers server.CustomCont
}
}
// the apiserver service does not yet support dual-stack operation
// the apiserver service does not yet support dual-stack operation
_
,
apiServerServiceIP
,
err
:=
controlplane
.
ServiceIPRange
(
*
serverConfig
.
ControlConfig
.
ServiceIPRange
)
_
,
apiServerServiceIP
,
err
:=
controlplane
.
ServiceIPRange
(
*
serverConfig
.
ControlConfig
.
ServiceIPRange
s
[
0
]
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/util/net.go
View file @
32d62c57
...
@@ -189,6 +189,19 @@ func ParseStringSliceToIPs(s cli.StringSlice) ([]net.IP, error) {
...
@@ -189,6 +189,19 @@ func ParseStringSliceToIPs(s cli.StringSlice) ([]net.IP, error) {
return
ips
,
nil
return
ips
,
nil
}
}
// GetFirstValidIPString returns the first valid address from a list of IP address strings,
// without preference for IP family. If no address are found, an empty string is returned.
func
GetFirstValidIPString
(
s
cli
.
StringSlice
)
string
{
for
_
,
unparsedIP
:=
range
s
{
for
_
,
v
:=
range
strings
.
Split
(
unparsedIP
,
","
)
{
if
ip
:=
net
.
ParseIP
(
v
);
ip
!=
nil
{
return
v
}
}
}
return
""
}
// GetFirstIP returns the first IPv4 address from the list of IP addresses.
// GetFirstIP returns the first IPv4 address from the list of IP addresses.
// If no IPv4 addresses are found, returns the first IPv6 address
// If no IPv4 addresses are found, returns the first IPv6 address
// if neither of IPv4 or IPv6 are found an error is raised.
// if neither of IPv4 or IPv6 are found an error is raised.
...
...
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