@@ -19,6 +19,7 @@ package upgrade
19
19
import (
20
20
"fmt"
21
21
"os"
22
+ "path/filepath"
22
23
"strings"
23
24
"time"
24
25
@@ -47,6 +48,8 @@ const (
47
48
type StaticPodPathManager interface {
48
49
// MoveFile should move a file from oldPath to newPath
49
50
MoveFile (oldPath , newPath string ) error
51
+ // KubernetesDir is the directory Kubernetes owns for storing various configuration files
52
+ KubernetesDir () string
50
53
// RealManifestPath gets the file path for the component in the "real" static pod manifest directory used by the kubelet
51
54
RealManifestPath (component string ) string
52
55
// RealManifestDir should point to the static pod manifest directory used by the kubelet
@@ -67,6 +70,7 @@ type StaticPodPathManager interface {
67
70
68
71
// KubeStaticPodPathManager is a real implementation of StaticPodPathManager that is used when upgrading a static pod cluster
69
72
type KubeStaticPodPathManager struct {
73
+ kubernetesDir string
70
74
realManifestDir string
71
75
tempManifestDir string
72
76
backupManifestDir string
@@ -77,9 +81,10 @@ type KubeStaticPodPathManager struct {
77
81
}
78
82
79
83
// NewKubeStaticPodPathManager creates a new instance of KubeStaticPodPathManager
80
- func NewKubeStaticPodPathManager (realDir , tempDir , backupDir , backupEtcdDir string , keepManifestDir , keepEtcdDir bool ) StaticPodPathManager {
84
+ func NewKubeStaticPodPathManager (kubernetesDir , tempDir , backupDir , backupEtcdDir string , keepManifestDir , keepEtcdDir bool ) StaticPodPathManager {
81
85
return & KubeStaticPodPathManager {
82
- realManifestDir : realDir ,
86
+ kubernetesDir : kubernetesDir ,
87
+ realManifestDir : filepath .Join (kubernetesDir , constants .ManifestsSubDirName ),
83
88
tempManifestDir : tempDir ,
84
89
backupManifestDir : backupDir ,
85
90
backupEtcdDir : backupEtcdDir ,
@@ -89,28 +94,34 @@ func NewKubeStaticPodPathManager(realDir, tempDir, backupDir, backupEtcdDir stri
89
94
}
90
95
91
96
// NewKubeStaticPodPathManagerUsingTempDirs creates a new instance of KubeStaticPodPathManager with temporary directories backing it
92
- func NewKubeStaticPodPathManagerUsingTempDirs (realManifestDir string , saveManifestsDir , saveEtcdDir bool ) (StaticPodPathManager , error ) {
93
- upgradedManifestsDir , err := constants .CreateTempDirForKubeadm ("kubeadm-upgraded-manifests" )
97
+ func NewKubeStaticPodPathManagerUsingTempDirs (kubernetesDir string , saveManifestsDir , saveEtcdDir bool ) (StaticPodPathManager , error ) {
98
+
99
+ upgradedManifestsDir , err := constants .CreateTempDirForKubeadm (kubernetesDir , "kubeadm-upgraded-manifests" )
94
100
if err != nil {
95
101
return nil , err
96
102
}
97
- backupManifestsDir , err := constants .CreateTimestampDirForKubeadm ("kubeadm-backup-manifests" )
103
+ backupManifestsDir , err := constants .CreateTimestampDirForKubeadm (kubernetesDir , "kubeadm-backup-manifests" )
98
104
if err != nil {
99
105
return nil , err
100
106
}
101
- backupEtcdDir , err := constants .CreateTimestampDirForKubeadm ("kubeadm-backup-etcd" )
107
+ backupEtcdDir , err := constants .CreateTimestampDirForKubeadm (kubernetesDir , "kubeadm-backup-etcd" )
102
108
if err != nil {
103
109
return nil , err
104
110
}
105
111
106
- return NewKubeStaticPodPathManager (realManifestDir , upgradedManifestsDir , backupManifestsDir , backupEtcdDir , saveManifestsDir , saveEtcdDir ), nil
112
+ return NewKubeStaticPodPathManager (kubernetesDir , upgradedManifestsDir , backupManifestsDir , backupEtcdDir , saveManifestsDir , saveEtcdDir ), nil
107
113
}
108
114
109
115
// MoveFile should move a file from oldPath to newPath
110
116
func (spm * KubeStaticPodPathManager ) MoveFile (oldPath , newPath string ) error {
111
117
return os .Rename (oldPath , newPath )
112
118
}
113
119
120
+ // KubernetesDir should point to the directory Kubernetes owns for storing various configuration files
121
+ func (spm * KubeStaticPodPathManager ) KubernetesDir () string {
122
+ return spm .kubernetesDir
123
+ }
124
+
114
125
// RealManifestPath gets the file path for the component in the "real" static pod manifest directory used by the kubelet
115
126
func (spm * KubeStaticPodPathManager ) RealManifestPath (component string ) string {
116
127
return constants .GetStaticPodFilepath (component , spm .realManifestDir )
@@ -202,7 +213,7 @@ func upgradeComponent(component string, renewCerts bool, waiter apiclient.Waiter
202
213
// if certificate renewal should be performed
203
214
if renewCerts {
204
215
// renew all the certificates used by the current component
205
- if err := renewCertsByComponent (cfg , constants .KubernetesDir , component ); err != nil {
216
+ if err := renewCertsByComponent (cfg , pathMgr .KubernetesDir () , component ); err != nil {
206
217
return rollbackOldManifests (recoverManifests , errors .Wrapf (err , "failed to renew certificates for component %q" , component ), pathMgr , recoverEtcd )
207
218
}
208
219
}
@@ -452,7 +463,7 @@ func StaticPodControlPlane(client clientset.Interface, waiter apiclient.Waiter,
452
463
453
464
if renewCerts {
454
465
// renew the certificate embedded in the admin.conf file
455
- err := renewEmbeddedCertsByName (cfg , constants .KubernetesDir , constants .AdminKubeConfigFileName )
466
+ err := renewEmbeddedCertsByName (cfg , pathMgr .KubernetesDir () , constants .AdminKubeConfigFileName )
456
467
if err != nil {
457
468
return rollbackOldManifests (recoverManifests , errors .Wrapf (err , "failed to upgrade the %s certificates" , constants .AdminKubeConfigFileName ), pathMgr , false )
458
469
}
0 commit comments