Skip to content

Commit 916edd9

Browse files
authored
Merge pull request kubernetes#86861 from SataQiu/fix-kubeadm-20200106
kubeadm upgrades always persist the etcd backup for stacked
2 parents 02ac661 + 72559ec commit 916edd9

File tree

5 files changed

+18
-65
lines changed

5 files changed

+18
-65
lines changed

cmd/kubeadm/app/cmd/upgrade/apply.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,5 @@ func PerformControlPlaneUpgrade(flags *applyFlags, client clientset.Interface, w
220220
return upgrade.DryRunStaticPodUpgrade(flags.kustomizeDir, internalcfg)
221221
}
222222

223-
// Don't save etcd backup directory if etcd is HA, as this could cause corruption
224223
return upgrade.PerformStaticPodUpgrade(client, waiter, internalcfg, flags.etcdUpgrade, flags.renewCerts, flags.kustomizeDir)
225224
}

cmd/kubeadm/app/phases/upgrade/staticpods.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,8 +591,8 @@ func renewCertsByComponent(cfg *kubeadmapi.InitConfiguration, component string,
591591

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

598598
// PerformStaticPodUpgrade performs the upgrade of the control plane components for a static pod hosted cluster

cmd/kubeadm/app/phases/upgrade/staticpods_test.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ func getEmbeddedCerts(tmpDir, kubeConfig string) ([]*x509.Certificate, error) {
900900

901901
func TestGetPathManagerForUpgrade(t *testing.T) {
902902

903-
haEtcd := &kubeadmapi.InitConfiguration{
903+
externalEtcd := &kubeadmapi.InitConfiguration{
904904
ClusterConfiguration: kubeadmapi.ClusterConfiguration{
905905
Etcd: kubeadmapi.Etcd{
906906
External: &kubeadmapi.ExternalEtcd{
@@ -910,7 +910,7 @@ func TestGetPathManagerForUpgrade(t *testing.T) {
910910
},
911911
}
912912

913-
noHAEtcd := &kubeadmapi.InitConfiguration{}
913+
stackedEtcd := &kubeadmapi.InitConfiguration{}
914914

915915
tests := []struct {
916916
name string
@@ -919,23 +919,29 @@ func TestGetPathManagerForUpgrade(t *testing.T) {
919919
shouldDeleteEtcd bool
920920
}{
921921
{
922-
name: "ha etcd but no etcd upgrade",
923-
cfg: haEtcd,
922+
name: "external etcd but no etcd upgrade",
923+
cfg: externalEtcd,
924924
etcdUpgrade: false,
925925
shouldDeleteEtcd: true,
926926
},
927927
{
928-
name: "non-ha etcd with etcd upgrade",
929-
cfg: noHAEtcd,
928+
name: "external etcd with etcd upgrade",
929+
cfg: externalEtcd,
930930
etcdUpgrade: true,
931-
shouldDeleteEtcd: false,
931+
shouldDeleteEtcd: true,
932932
},
933933
{
934-
name: "ha etcd and etcd upgrade",
935-
cfg: haEtcd,
936-
etcdUpgrade: true,
934+
name: "stacked etcd but no etcd upgrade",
935+
cfg: stackedEtcd,
936+
etcdUpgrade: false,
937937
shouldDeleteEtcd: true,
938938
},
939+
{
940+
name: "stacked etcd with etcd upgrade",
941+
cfg: stackedEtcd,
942+
etcdUpgrade: true,
943+
shouldDeleteEtcd: false,
944+
},
939945
}
940946

941947
for _, test := range tests {

cmd/kubeadm/app/util/etcd/etcd.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,6 @@ func (c *Client) WaitForClusterAvailable(retries int, retryInterval time.Duratio
421421
return false, errors.New("timeout waiting for etcd cluster to be available")
422422
}
423423

424-
// CheckConfigurationIsHA returns true if the given InitConfiguration etcd block appears to be an HA configuration.
425-
func CheckConfigurationIsHA(cfg *kubeadmapi.Etcd) bool {
426-
return cfg.External != nil && len(cfg.External.Endpoints) > 1
427-
}
428-
429424
// GetClientURL creates an HTTPS URL that uses the configured advertise
430425
// address and client port for the API controller
431426
func GetClientURL(localEndpoint *kubeadmapi.APIEndpoint) string {

cmd/kubeadm/app/util/etcd/etcd_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,6 @@ import (
2525
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
2626
)
2727

28-
func TestCheckConfigurationIsHA(t *testing.T) {
29-
var tests = []struct {
30-
name string
31-
cfg *kubeadmapi.Etcd
32-
expected bool
33-
}{
34-
{
35-
name: "HA etcd",
36-
cfg: &kubeadmapi.Etcd{
37-
External: &kubeadmapi.ExternalEtcd{
38-
Endpoints: []string{"10.100.0.1:2379", "10.100.0.2:2379", "10.100.0.3:2379"},
39-
},
40-
},
41-
expected: true,
42-
},
43-
{
44-
name: "single External etcd",
45-
cfg: &kubeadmapi.Etcd{
46-
External: &kubeadmapi.ExternalEtcd{
47-
Endpoints: []string{"10.100.0.1:2379"},
48-
},
49-
},
50-
expected: false,
51-
},
52-
{
53-
name: "local etcd",
54-
cfg: &kubeadmapi.Etcd{
55-
Local: &kubeadmapi.LocalEtcd{},
56-
},
57-
expected: false,
58-
},
59-
{
60-
name: "empty etcd struct",
61-
cfg: &kubeadmapi.Etcd{},
62-
expected: false,
63-
},
64-
}
65-
66-
for _, test := range tests {
67-
t.Run(test.name, func(t *testing.T) {
68-
if isHA := CheckConfigurationIsHA(test.cfg); isHA != test.expected {
69-
t.Errorf("expected isHA to be %v, got %v", test.expected, isHA)
70-
}
71-
})
72-
}
73-
}
74-
7528
func testGetURL(t *testing.T, getURLFunc func(*kubeadmapi.APIEndpoint) string, port int) {
7629
portStr := strconv.Itoa(port)
7730
var tests = []struct {

0 commit comments

Comments
 (0)