mirror of https://github.com/k3s-io/k3s
Merge pull request #73678 from ereslibre/do-not-create-etcd-datadir-dryrun
kubeadm: do not create etcd datastore if we are in dryrun modepull/564/head
commit
7d1dc61920
|
@ -463,6 +463,11 @@ func (j *joinData) PostInstallControlPlane(initConfiguration *kubeadmapi.InitCon
|
||||||
|
|
||||||
// in case of local etcd
|
// in case of local etcd
|
||||||
if initConfiguration.Etcd.External == nil {
|
if initConfiguration.Etcd.External == nil {
|
||||||
|
// creates target folder if doesn't exist already
|
||||||
|
if err := os.MkdirAll(initConfiguration.Etcd.Local.DataDir, 0700); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to create etcd directory %q", initConfiguration.Etcd.Local.DataDir)
|
||||||
|
}
|
||||||
|
|
||||||
// Adds a new etcd instance; in order to do this the new etcd instance should be "announced" to
|
// Adds a new etcd instance; in order to do this the new etcd instance should be "announced" to
|
||||||
// the existing etcd members before being created.
|
// the existing etcd members before being created.
|
||||||
// This operation must be executed after kubelet is already started in order to minimize the time
|
// This operation must be executed after kubelet is already started in order to minimize the time
|
||||||
|
|
|
@ -18,6 +18,7 @@ package phases
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
@ -43,6 +44,7 @@ var (
|
||||||
|
|
||||||
type etcdData interface {
|
type etcdData interface {
|
||||||
Cfg() *kubeadmapi.InitConfiguration
|
Cfg() *kubeadmapi.InitConfiguration
|
||||||
|
DryRun() bool
|
||||||
ManifestDir() string
|
ManifestDir() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +91,14 @@ func runEtcdPhaseLocal() func(c workflow.RunData) error {
|
||||||
|
|
||||||
// Add etcd static pod spec only if external etcd is not configured
|
// Add etcd static pod spec only if external etcd is not configured
|
||||||
if cfg.Etcd.External == nil {
|
if cfg.Etcd.External == nil {
|
||||||
|
// creates target folder if doesn't exist already
|
||||||
|
if !data.DryRun() {
|
||||||
|
if err := os.MkdirAll(cfg.Etcd.Local.DataDir, 0700); err != nil {
|
||||||
|
return errors.Wrapf(err, "failed to create etcd directory %q", cfg.Etcd.Local.DataDir)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("[dryrun] Would ensure that %q directory is present\n", cfg.Etcd.Local.DataDir)
|
||||||
|
}
|
||||||
fmt.Printf("[etcd] Creating static Pod manifest for local etcd in %q\n", data.ManifestDir())
|
fmt.Printf("[etcd] Creating static Pod manifest for local etcd in %q\n", data.ManifestDir())
|
||||||
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
if err := etcdphase.CreateLocalEtcdStaticPodManifestFile(data.ManifestDir(), cfg.NodeRegistration.Name, &cfg.ClusterConfiguration, &cfg.LocalAPIEndpoint); err != nil {
|
||||||
return errors.Wrap(err, "error creating local etcd static pod manifest file")
|
return errors.Wrap(err, "error creating local etcd static pod manifest file")
|
||||||
|
|
|
@ -18,7 +18,6 @@ package etcd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -51,14 +50,8 @@ func CreateLocalEtcdStaticPodManifestFile(manifestDir string, nodeName string, c
|
||||||
return errors.New("etcd static pod manifest cannot be generated for cluster using external etcd")
|
return errors.New("etcd static pod manifest cannot be generated for cluster using external etcd")
|
||||||
}
|
}
|
||||||
// gets etcd StaticPodSpec
|
// gets etcd StaticPodSpec
|
||||||
emptyInitialCluster := []etcdutil.Member{}
|
spec := GetEtcdPodSpec(cfg, endpoint, nodeName, []etcdutil.Member{})
|
||||||
|
|
||||||
// creates target folder if not already exists
|
|
||||||
if err := os.MkdirAll(cfg.Etcd.Local.DataDir, 0700); err != nil {
|
|
||||||
return errors.Wrapf(err, "failed to create etcd directory %q", cfg.Etcd.Local.DataDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
spec := GetEtcdPodSpec(cfg, endpoint, nodeName, emptyInitialCluster)
|
|
||||||
// writes etcd StaticPod to disk
|
// writes etcd StaticPod to disk
|
||||||
if err := staticpodutil.WriteStaticPodToDisk(kubeadmconstants.Etcd, manifestDir, spec); err != nil {
|
if err := staticpodutil.WriteStaticPodToDisk(kubeadmconstants.Etcd, manifestDir, spec); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -110,11 +103,6 @@ func CreateStackedEtcdStaticPodManifestFile(client clientset.Interface, manifest
|
||||||
fmt.Println("[etcd] Announced new etcd member joining to the existing etcd cluster")
|
fmt.Println("[etcd] Announced new etcd member joining to the existing etcd cluster")
|
||||||
klog.V(1).Infof("Updated etcd member list: %v", initialCluster)
|
klog.V(1).Infof("Updated etcd member list: %v", initialCluster)
|
||||||
|
|
||||||
// creates target folder if not already exists
|
|
||||||
if err := os.MkdirAll(cfg.Etcd.Local.DataDir, 0700); err != nil {
|
|
||||||
return errors.Wrapf(err, "failed to create etcd directory %q", cfg.Etcd.Local.DataDir)
|
|
||||||
}
|
|
||||||
|
|
||||||
klog.V(1).Info("Creating local etcd static pod manifest file")
|
klog.V(1).Info("Creating local etcd static pod manifest file")
|
||||||
// gets etcd StaticPodSpec, actualized for the current InitConfiguration and the new list of etcd members
|
// gets etcd StaticPodSpec, actualized for the current InitConfiguration and the new list of etcd members
|
||||||
spec := GetEtcdPodSpec(cfg, endpoint, nodeName, initialCluster)
|
spec := GetEtcdPodSpec(cfg, endpoint, nodeName, initialCluster)
|
||||||
|
|
Loading…
Reference in New Issue