mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
kubeadm cleanup: master -> control-plane (cont.3)
This commit is contained in:
parent
b77e4e2417
commit
57d04cafee
@ -52,8 +52,8 @@ func EnsureProxyAddon(cfg *kubeadmapi.ClusterConfiguration, localEndpoint *kubea
|
|||||||
return errors.Wrap(err, "error when creating kube-proxy service account")
|
return errors.Wrap(err, "error when creating kube-proxy service account")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate Master Enpoint kubeconfig file
|
// Generate ControlPlane Enpoint kubeconfig file
|
||||||
masterEndpoint, err := kubeadmutil.GetMasterEndpoint(cfg.ControlPlaneEndpoint, localEndpoint)
|
controlPlaneEndpoint, err := kubeadmutil.GetControlPlaneEndpoint(cfg.ControlPlaneEndpoint, localEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -72,7 +72,7 @@ func EnsureProxyAddon(cfg *kubeadmapi.ClusterConfiguration, localEndpoint *kubea
|
|||||||
ProxyConfigMap string
|
ProxyConfigMap string
|
||||||
ProxyConfigMapKey string
|
ProxyConfigMapKey string
|
||||||
}{
|
}{
|
||||||
MasterEndpoint: masterEndpoint,
|
MasterEndpoint: controlPlaneEndpoint,
|
||||||
ProxyConfig: prefixBytes.String(),
|
ProxyConfig: prefixBytes.String(),
|
||||||
ProxyConfigMap: constants.KubeProxyConfigMap,
|
ProxyConfigMap: constants.KubeProxyConfigMap,
|
||||||
ProxyConfigMapKey: constants.KubeProxyConfigMapKey,
|
ProxyConfigMapKey: constants.KubeProxyConfigMapKey,
|
||||||
|
@ -135,7 +135,7 @@ func getKubeConfigSpecs(cfg *kubeadmapi.InitConfiguration) (map[string]*kubeConf
|
|||||||
return nil, errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
|
return nil, errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
masterEndpoint, err := kubeadmutil.GetMasterEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
masterEndpoint, err := kubeadmutil.GetControlPlaneEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -285,7 +285,7 @@ func WriteKubeConfigWithClientCert(out io.Writer, cfg *kubeadmapi.InitConfigurat
|
|||||||
return errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
|
return errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
masterEndpoint, err := kubeadmutil.GetMasterEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
masterEndpoint, err := kubeadmutil.GetControlPlaneEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -312,7 +312,7 @@ func WriteKubeConfigWithToken(out io.Writer, cfg *kubeadmapi.InitConfiguration,
|
|||||||
return errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
|
return errors.Wrap(err, "couldn't create a kubeconfig; the CA files couldn't be loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
masterEndpoint, err := kubeadmutil.GetMasterEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
masterEndpoint, err := kubeadmutil.GetControlPlaneEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ func TestGetKubeConfigSpecs(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Asserts InitConfiguration values injected into spec
|
// Asserts InitConfiguration values injected into spec
|
||||||
masterEndpoint, err := kubeadmutil.GetMasterEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
masterEndpoint, err := kubeadmutil.GetControlPlaneEndpoint(cfg.ControlPlaneEndpoint, &cfg.LocalAPIEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ import (
|
|||||||
// - GET /nodes/<node-name> -- must return a valid Node
|
// - GET /nodes/<node-name> -- must return a valid Node
|
||||||
// - ...all other, unknown GETs/LISTs will be logged
|
// - ...all other, unknown GETs/LISTs will be logged
|
||||||
type InitDryRunGetter struct {
|
type InitDryRunGetter struct {
|
||||||
masterName string
|
controlPlaneName string
|
||||||
serviceSubnet string
|
serviceSubnet string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,9 +48,9 @@ type InitDryRunGetter struct {
|
|||||||
var _ DryRunGetter = &InitDryRunGetter{}
|
var _ DryRunGetter = &InitDryRunGetter{}
|
||||||
|
|
||||||
// NewInitDryRunGetter creates a new instance of the InitDryRunGetter struct
|
// NewInitDryRunGetter creates a new instance of the InitDryRunGetter struct
|
||||||
func NewInitDryRunGetter(masterName string, serviceSubnet string) *InitDryRunGetter {
|
func NewInitDryRunGetter(controlPlaneName string, serviceSubnet string) *InitDryRunGetter {
|
||||||
return &InitDryRunGetter{
|
return &InitDryRunGetter{
|
||||||
masterName: masterName,
|
controlPlaneName: controlPlaneName,
|
||||||
serviceSubnet: serviceSubnet,
|
serviceSubnet: serviceSubnet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,16 +122,16 @@ func (idr *InitDryRunGetter) handleKubernetesService(action core.GetAction) (boo
|
|||||||
|
|
||||||
// handleGetNode returns a fake node object for the purpose of moving kubeadm init forwards.
|
// handleGetNode returns a fake node object for the purpose of moving kubeadm init forwards.
|
||||||
func (idr *InitDryRunGetter) handleGetNode(action core.GetAction) (bool, runtime.Object, error) {
|
func (idr *InitDryRunGetter) handleGetNode(action core.GetAction) (bool, runtime.Object, error) {
|
||||||
if action.GetName() != idr.masterName || action.GetResource().Resource != "nodes" {
|
if action.GetName() != idr.controlPlaneName || action.GetResource().Resource != "nodes" {
|
||||||
// We can't handle this event
|
// We can't handle this event
|
||||||
return false, nil, nil
|
return false, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return true, &v1.Node{
|
return true, &v1.Node{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: idr.masterName,
|
Name: idr.controlPlaneName,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"kubernetes.io/hostname": idr.masterName,
|
"kubernetes.io/hostname": idr.controlPlaneName,
|
||||||
},
|
},
|
||||||
Annotations: map[string]string{},
|
Annotations: map[string]string{},
|
||||||
},
|
},
|
||||||
|
@ -27,9 +27,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestHandleGetAction(t *testing.T) {
|
func TestHandleGetAction(t *testing.T) {
|
||||||
masterName := "master-foo"
|
controlPlaneName := "control-plane-foo"
|
||||||
serviceSubnet := "10.96.0.1/12"
|
serviceSubnet := "10.96.0.1/12"
|
||||||
idr := NewInitDryRunGetter(masterName, serviceSubnet)
|
idr := NewInitDryRunGetter(controlPlaneName, serviceSubnet)
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
name string
|
name string
|
||||||
@ -47,9 +47,9 @@ func TestHandleGetAction(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "get nodes",
|
name: "get nodes",
|
||||||
action: core.NewRootGetAction(schema.GroupVersionResource{Version: "v1", Resource: "nodes"}, masterName),
|
action: core.NewRootGetAction(schema.GroupVersionResource{Version: "v1", Resource: "nodes"}, controlPlaneName),
|
||||||
expectedHandled: true,
|
expectedHandled: true,
|
||||||
expectedObjectJSON: []byte(`{"metadata":{"name":"master-foo","creationTimestamp":null,"labels":{"kubernetes.io/hostname":"master-foo"}},"spec":{},"status":{"daemonEndpoints":{"kubeletEndpoint":{"Port":0}},"nodeInfo":{"machineID":"","systemUUID":"","bootID":"","kernelVersion":"","osImage":"","containerRuntimeVersion":"","kubeletVersion":"","kubeProxyVersion":"","operatingSystem":"","architecture":""}}}`),
|
expectedObjectJSON: []byte(`{"metadata":{"name":"control-plane-foo","creationTimestamp":null,"labels":{"kubernetes.io/hostname":"control-plane-foo"}},"spec":{},"status":{"daemonEndpoints":{"kubeletEndpoint":{"Port":0}},"nodeInfo":{"machineID":"","systemUUID":"","bootID":"","kernelVersion":"","osImage":"","containerRuntimeVersion":"","kubeletVersion":"","kubeProxyVersion":"","operatingSystem":"","architecture":""}}}`),
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -80,7 +80,7 @@ func TestHandleGetAction(t *testing.T) {
|
|||||||
expectedObjectJSON: []byte(``),
|
expectedObjectJSON: []byte(``),
|
||||||
expectedErr: false,
|
expectedErr: false,
|
||||||
},
|
},
|
||||||
{ // an ask for an other node than the master should not be answered
|
{ // an ask for an other node than the control-plane should not be answered
|
||||||
name: "get other-node",
|
name: "get other-node",
|
||||||
action: core.NewRootGetAction(schema.GroupVersionResource{Version: "v1", Resource: "nodes"}, "other-node"),
|
action: core.NewRootGetAction(schema.GroupVersionResource{Version: "v1", Resource: "nodes"}, "other-node"),
|
||||||
expectedHandled: false,
|
expectedHandled: false,
|
||||||
|
@ -34,11 +34,11 @@ import (
|
|||||||
|
|
||||||
// SetJoinDynamicDefaults checks and sets configuration values for the JoinConfiguration object
|
// SetJoinDynamicDefaults checks and sets configuration values for the JoinConfiguration object
|
||||||
func SetJoinDynamicDefaults(cfg *kubeadmapi.JoinConfiguration) error {
|
func SetJoinDynamicDefaults(cfg *kubeadmapi.JoinConfiguration) error {
|
||||||
addMasterTaint := false
|
addControlPlaneTaint := false
|
||||||
if cfg.ControlPlane != nil {
|
if cfg.ControlPlane != nil {
|
||||||
addMasterTaint = true
|
addControlPlaneTaint = true
|
||||||
}
|
}
|
||||||
if err := SetNodeRegistrationDynamicDefaults(&cfg.NodeRegistration, addMasterTaint); err != nil {
|
if err := SetNodeRegistrationDynamicDefaults(&cfg.NodeRegistration, addControlPlaneTaint); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,11 +28,11 @@ import (
|
|||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetMasterEndpoint returns a properly formatted endpoint for the control plane built according following rules:
|
// GetControlPlaneEndpoint returns a properly formatted endpoint for the control plane built according following rules:
|
||||||
// - If the controlPlaneEndpoint is defined, use it.
|
// - If the controlPlaneEndpoint is defined, use it.
|
||||||
// - if the controlPlaneEndpoint is defined but without a port number, use the controlPlaneEndpoint + localEndpoint.BindPort is used.
|
// - if the controlPlaneEndpoint is defined but without a port number, use the controlPlaneEndpoint + localEndpoint.BindPort is used.
|
||||||
// - Otherwise, in case the controlPlaneEndpoint is not defined, use the localEndpoint.AdvertiseAddress + the localEndpoint.BindPort.
|
// - Otherwise, in case the controlPlaneEndpoint is not defined, use the localEndpoint.AdvertiseAddress + the localEndpoint.BindPort.
|
||||||
func GetMasterEndpoint(controlPlaneEndpoint string, localEndpoint *kubeadmapi.APIEndpoint) (string, error) {
|
func GetControlPlaneEndpoint(controlPlaneEndpoint string, localEndpoint *kubeadmapi.APIEndpoint) (string, error) {
|
||||||
// parse the bind port
|
// parse the bind port
|
||||||
bindPortString := strconv.Itoa(int(localEndpoint.BindPort))
|
bindPortString := strconv.Itoa(int(localEndpoint.BindPort))
|
||||||
if _, err := ParsePort(bindPortString); err != nil {
|
if _, err := ParsePort(bindPortString); err != nil {
|
||||||
@ -45,8 +45,8 @@ func GetMasterEndpoint(controlPlaneEndpoint string, localEndpoint *kubeadmapi.AP
|
|||||||
return "", errors.Errorf("invalid value `%s` given for api.advertiseAddress", localEndpoint.AdvertiseAddress)
|
return "", errors.Errorf("invalid value `%s` given for api.advertiseAddress", localEndpoint.AdvertiseAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the master url using localEndpoint.AdvertiseAddress + the localEndpoint.BindPort
|
// set the control-plane url using localEndpoint.AdvertiseAddress + the localEndpoint.BindPort
|
||||||
masterURL := &url.URL{
|
controlPlaneURL := &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Host: net.JoinHostPort(ip.String(), bindPortString),
|
Host: net.JoinHostPort(ip.String(), bindPortString),
|
||||||
}
|
}
|
||||||
@ -69,14 +69,14 @@ func GetMasterEndpoint(controlPlaneEndpoint string, localEndpoint *kubeadmapi.AP
|
|||||||
port = bindPortString
|
port = bindPortString
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrides the master url using the controlPlaneAddress (and eventually the bindport)
|
// overrides the control-plane url using the controlPlaneAddress (and eventually the bindport)
|
||||||
masterURL = &url.URL{
|
controlPlaneURL = &url.URL{
|
||||||
Scheme: "https",
|
Scheme: "https",
|
||||||
Host: net.JoinHostPort(host, port),
|
Host: net.JoinHostPort(host, port),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return masterURL.String(), nil
|
return controlPlaneURL.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseHostPort parses a network address of the form "host:port", "ipv4:port", "[ipv6]:port" into host and port;
|
// ParseHostPort parses a network address of the form "host:port", "ipv4:port", "[ipv6]:port" into host and port;
|
||||||
|
@ -22,7 +22,7 @@ import (
|
|||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetMasterEndpoint(t *testing.T) {
|
func TestGetControlPlaneEndpoint(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
name string
|
name string
|
||||||
cfg *kubeadmapi.InitConfiguration
|
cfg *kubeadmapi.InitConfiguration
|
||||||
@ -198,7 +198,7 @@ func TestGetMasterEndpoint(t *testing.T) {
|
|||||||
|
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
t.Run(rt.name, func(t *testing.T) {
|
t.Run(rt.name, func(t *testing.T) {
|
||||||
actualEndpoint, actualError := GetMasterEndpoint(rt.cfg.ControlPlaneEndpoint, &rt.cfg.LocalAPIEndpoint)
|
actualEndpoint, actualError := GetControlPlaneEndpoint(rt.cfg.ControlPlaneEndpoint, &rt.cfg.LocalAPIEndpoint)
|
||||||
|
|
||||||
if (actualError != nil) && !rt.expectedError {
|
if (actualError != nil) && !rt.expectedError {
|
||||||
t.Errorf("%s unexpected failure: %v", rt.name, actualError)
|
t.Errorf("%s unexpected failure: %v", rt.name, actualError)
|
||||||
|
Loading…
Reference in New Issue
Block a user