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
1ac744c3
Unverified
Commit
1ac744c3
authored
Dec 08, 2021
by
Manuel Buil
Committed by
GitHub
Dec 08, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4680 from manuelbuil/ha-verify-1.20
[Release 1.20] Verify new control plane nodes joining the cluster share the same config as cluster members
parents
6d3c31ad
5bd8eb78
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
15 deletions
+53
-15
bootstrap.go
pkg/cluster/bootstrap.go
+33
-0
types.go
pkg/daemons/config/types.go
+20
-15
No files found.
pkg/cluster/bootstrap.go
View file @
1ac744c3
...
@@ -3,9 +3,11 @@ package cluster
...
@@ -3,9 +3,11 @@ package cluster
import
(
import
(
"bytes"
"bytes"
"context"
"context"
"encoding/json"
"errors"
"errors"
"os"
"os"
"path/filepath"
"path/filepath"
"reflect"
"github.com/rancher/k3s/pkg/bootstrap"
"github.com/rancher/k3s/pkg/bootstrap"
"github.com/rancher/k3s/pkg/clientaccess"
"github.com/rancher/k3s/pkg/clientaccess"
...
@@ -134,6 +136,10 @@ func (c *Cluster) bootstrap(ctx context.Context) error {
...
@@ -134,6 +136,10 @@ func (c *Cluster) bootstrap(ctx context.Context) error {
// bootstrap managed database via HTTPS
// bootstrap managed database via HTTPS
if
c
.
runtime
.
HTTPBootstrap
{
if
c
.
runtime
.
HTTPBootstrap
{
// Assuming we should just compare on managed databases
if
err
:=
c
.
compareConfig
();
err
!=
nil
{
return
err
}
return
c
.
httpBootstrap
()
return
c
.
httpBootstrap
()
}
}
...
@@ -156,3 +162,30 @@ func (c *Cluster) Snapshot(ctx context.Context, config *config.Control) error {
...
@@ -156,3 +162,30 @@ func (c *Cluster) Snapshot(ctx context.Context, config *config.Control) error {
}
}
return
c
.
managedDB
.
Snapshot
(
ctx
,
config
)
return
c
.
managedDB
.
Snapshot
(
ctx
,
config
)
}
}
// compareConfig verifies that the config of the joining control plane node coincides with the cluster's config
func
(
c
*
Cluster
)
compareConfig
()
error
{
agentClientAccessInfo
,
err
:=
clientaccess
.
ParseAndValidateTokenForUser
(
c
.
config
.
JoinURL
,
c
.
config
.
Token
,
"node"
)
if
err
!=
nil
{
return
err
}
serverConfig
,
err
:=
clientaccess
.
Get
(
"/v1-"
+
version
.
Program
+
"/config"
,
agentClientAccessInfo
)
if
err
!=
nil
{
return
err
}
clusterControl
:=
&
config
.
Control
{}
if
err
:=
json
.
Unmarshal
(
serverConfig
,
clusterControl
);
err
!=
nil
{
return
err
}
// We are saving IPs of ClusterIPRanges and ServiceIPRanges in 4-bytes representation but json decodes in 16-byte
c
.
config
.
CriticalControlArgs
.
ClusterIPRange
.
IP
.
To16
()
c
.
config
.
CriticalControlArgs
.
ServiceIPRange
.
IP
.
To16
()
if
!
reflect
.
DeepEqual
(
clusterControl
.
CriticalControlArgs
,
c
.
config
.
CriticalControlArgs
)
{
logrus
.
Debugf
(
"This is the server CriticalControlArgs: %#v"
,
clusterControl
.
CriticalControlArgs
)
logrus
.
Debugf
(
"This is the local CriticalControlArgs: %#v"
,
c
.
config
.
CriticalControlArgs
)
return
errors
.
New
(
"Unable to join cluster due to critical configuration value mismatch"
)
}
return
nil
}
pkg/daemons/config/types.go
View file @
1ac744c3
...
@@ -93,7 +93,23 @@ type Agent struct {
...
@@ -93,7 +93,23 @@ type Agent struct {
ProtectKernelDefaults
bool
ProtectKernelDefaults
bool
}
}
// CriticalControlArgs contains parameters that all control plane nodes in HA must share
type
CriticalControlArgs
struct
{
ClusterDNS
net
.
IP
ClusterDomain
string
ClusterIPRange
*
net
.
IPNet
DisableCCM
bool
DisableKubeProxy
bool
DisableNPC
bool
Disables
map
[
string
]
bool
FlannelBackend
string
NoCoreDNS
bool
ServiceIPRange
*
net
.
IPNet
Skips
map
[
string
]
bool
}
type
Control
struct
{
type
Control
struct
{
CriticalControlArgs
AdvertisePort
int
AdvertisePort
int
AdvertiseIP
string
AdvertiseIP
string
// The port which kubectl clients can access k8s
// The port which kubectl clients can access k8s
...
@@ -105,34 +121,23 @@ type Control struct {
...
@@ -105,34 +121,23 @@ type Control struct {
APIServerBindAddress
string
APIServerBindAddress
string
AgentToken
string
`json:"-"`
AgentToken
string
`json:"-"`
Token
string
`json:"-"`
Token
string
`json:"-"`
ClusterIPRange
*
net
.
IPNet
ServiceIPRange
*
net
.
IPNet
ServiceNodePortRange
*
utilnet
.
PortRange
ServiceNodePortRange
*
utilnet
.
PortRange
ClusterDNS
net
.
IP
ClusterDomain
string
NoCoreDNS
bool
KubeConfigOutput
string
KubeConfigOutput
string
KubeConfigMode
string
KubeConfigMode
string
DataDir
string
DataDir
string
Skips
map
[
string
]
bool
Disables
map
[
string
]
bool
Datastore
endpoint
.
Config
Datastore
endpoint
.
Config
DisableAPIServer
bool
DisableControllerManager
bool
DisableETCD
bool
DisableScheduler
bool
ExtraAPIArgs
[]
string
ExtraAPIArgs
[]
string
ExtraControllerArgs
[]
string
ExtraControllerArgs
[]
string
ExtraCloudControllerArgs
[]
string
ExtraCloudControllerArgs
[]
string
ExtraSchedulerAPIArgs
[]
string
ExtraSchedulerAPIArgs
[]
string
NoLeaderElect
bool
NoLeaderElect
bool
JoinURL
string
JoinURL
string
FlannelBackend
string
IPSECPSK
string
IPSECPSK
string
DefaultLocalStoragePath
string
DefaultLocalStoragePath
string
DisableCCM
bool
DisableNPC
bool
DisableKubeProxy
bool
DisableAPIServer
bool
DisableControllerManager
bool
DisableScheduler
bool
DisableETCD
bool
ClusterInit
bool
ClusterInit
bool
ClusterReset
bool
ClusterReset
bool
ClusterResetRestorePath
string
ClusterResetRestorePath
string
...
...
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