Skip to content

Commit

Permalink
kubeadm upgrades always persist the etcd backup for stacked
Browse files Browse the repository at this point in the history
  • Loading branch information
SataQiu committed Jan 6, 2020
1 parent 13b5eff commit 72559ec
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 65 deletions.
1 change: 0 additions & 1 deletion cmd/kubeadm/app/cmd/upgrade/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,5 @@ func PerformControlPlaneUpgrade(flags *applyFlags, client clientset.Interface, w
return upgrade.DryRunStaticPodUpgrade(flags.kustomizeDir, internalcfg)
}

// Don't save etcd backup directory if etcd is HA, as this could cause corruption
return upgrade.PerformStaticPodUpgrade(client, waiter, internalcfg, flags.etcdUpgrade, flags.renewCerts, flags.kustomizeDir)
}
4 changes: 2 additions & 2 deletions cmd/kubeadm/app/phases/upgrade/staticpods.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ func renewCertsByComponent(cfg *kubeadmapi.InitConfiguration, component string,

// GetPathManagerForUpgrade returns a path manager properly configured for the given InitConfiguration.
func GetPathManagerForUpgrade(kubernetesDir, kustomizeDir string, internalcfg *kubeadmapi.InitConfiguration, etcdUpgrade bool) (StaticPodPathManager, error) {
isHAEtcd := etcdutil.CheckConfigurationIsHA(&internalcfg.Etcd)
return NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir, true, etcdUpgrade && !isHAEtcd)
isExternalEtcd := internalcfg.Etcd.External != nil
return NewKubeStaticPodPathManagerUsingTempDirs(kubernetesDir, kustomizeDir, true, etcdUpgrade && !isExternalEtcd)
}

// PerformStaticPodUpgrade performs the upgrade of the control plane components for a static pod hosted cluster
Expand Down
26 changes: 16 additions & 10 deletions cmd/kubeadm/app/phases/upgrade/staticpods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func getEmbeddedCerts(tmpDir, kubeConfig string) ([]*x509.Certificate, error) {

func TestGetPathManagerForUpgrade(t *testing.T) {

haEtcd := &kubeadmapi.InitConfiguration{
externalEtcd := &kubeadmapi.InitConfiguration{
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
Etcd: kubeadmapi.Etcd{
External: &kubeadmapi.ExternalEtcd{
Expand All @@ -910,7 +910,7 @@ func TestGetPathManagerForUpgrade(t *testing.T) {
},
}

noHAEtcd := &kubeadmapi.InitConfiguration{}
stackedEtcd := &kubeadmapi.InitConfiguration{}

tests := []struct {
name string
Expand All @@ -919,23 +919,29 @@ func TestGetPathManagerForUpgrade(t *testing.T) {
shouldDeleteEtcd bool
}{
{
name: "ha etcd but no etcd upgrade",
cfg: haEtcd,
name: "external etcd but no etcd upgrade",
cfg: externalEtcd,
etcdUpgrade: false,
shouldDeleteEtcd: true,
},
{
name: "non-ha etcd with etcd upgrade",
cfg: noHAEtcd,
name: "external etcd with etcd upgrade",
cfg: externalEtcd,
etcdUpgrade: true,
shouldDeleteEtcd: false,
shouldDeleteEtcd: true,
},
{
name: "ha etcd and etcd upgrade",
cfg: haEtcd,
etcdUpgrade: true,
name: "stacked etcd but no etcd upgrade",
cfg: stackedEtcd,
etcdUpgrade: false,
shouldDeleteEtcd: true,
},
{
name: "stacked etcd with etcd upgrade",
cfg: stackedEtcd,
etcdUpgrade: true,
shouldDeleteEtcd: false,
},
}

for _, test := range tests {
Expand Down
5 changes: 0 additions & 5 deletions cmd/kubeadm/app/util/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,6 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
return false, errors.New("timeout waiting for etcd cluster to be available")
}

// CheckConfigurationIsHA returns true if the given InitConfiguration etcd block appears to be an HA configuration.
func CheckConfigurationIsHA(cfg *kubeadmapi.Etcd) bool {
return cfg.External != nil && len(cfg.External.Endpoints) > 1
}

// GetClientURL creates an HTTPS URL that uses the configured advertise
// address and client port for the API controller
func GetClientURL(localEndpoint *kubeadmapi.APIEndpoint) string {
Expand Down
47 changes: 0 additions & 47 deletions cmd/kubeadm/app/util/etcd/etcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,6 @@ import (
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
)

func TestCheckConfigurationIsHA(t *testing.T) {
var tests = []struct {
name string
cfg *kubeadmapi.Etcd
expected bool
}{
{
name: "HA etcd",
cfg: &kubeadmapi.Etcd{
External: &kubeadmapi.ExternalEtcd{
Endpoints: []string{"10.100.0.1:2379", "10.100.0.2:2379", "10.100.0.3:2379"},
},
},
expected: true,
},
{
name: "single External etcd",
cfg: &kubeadmapi.Etcd{
External: &kubeadmapi.ExternalEtcd{
Endpoints: []string{"10.100.0.1:2379"},
},
},
expected: false,
},
{
name: "local etcd",
cfg: &kubeadmapi.Etcd{
Local: &kubeadmapi.LocalEtcd{},
},
expected: false,
},
{
name: "empty etcd struct",
cfg: &kubeadmapi.Etcd{},
expected: false,
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if isHA := CheckConfigurationIsHA(test.cfg); isHA != test.expected {
t.Errorf("expected isHA to be %v, got %v", test.expected, isHA)
}
})
}
}

func testGetURL(t *testing.T, getURLFunc func(*kubeadmapi.APIEndpoint) string, port int) {
portStr := strconv.Itoa(port)
var tests = []struct {
Expand Down

0 comments on commit 72559ec

Please sign in to comment.