You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# NOTE: Make sure the resulted ETCD_NAME agrees with --name in etcd.manifest: https://github.com/kubernetes/kubernetes/blob/e7ca64fbe16d0c4b6c7b36aecde9cd75042b2828/cluster/gce/manifests/etcd.manifest#L27
Copy file name to clipboardExpand all lines: cluster/images/etcd/migrate/migrate.go
+27-98Lines changed: 27 additions & 98 deletions
Original file line number
Diff line number
Diff line change
@@ -18,16 +18,14 @@ package main
18
18
19
19
import (
20
20
"fmt"
21
-
"os"
22
21
"path/filepath"
23
22
24
23
"github.com/spf13/cobra"
25
24
"k8s.io/klog/v2"
26
25
)
27
26
28
27
const (
29
-
versionFilename="version.txt"
30
-
defaultPortuint64=18629
28
+
versionFilename="version.txt"
31
29
)
32
30
33
31
var (
@@ -46,94 +44,43 @@ a target etcd version, this tool will upgrade or downgrade the etcd data from th
46
44
opts=migrateOpts{}
47
45
)
48
46
49
-
typemigrateOptsstruct {
50
-
namestring
51
-
portuint64
52
-
peerListenUrlsstring
53
-
peerAdvertiseUrlsstring
54
-
binDirstring
55
-
dataDirstring
56
-
bundledVersionStringstring
57
-
etcdDataPrefixstring
58
-
ttlKeysDirectorystring
59
-
initialClusterstring
60
-
targetVersionstring
61
-
targetStoragestring
62
-
etcdServerArgsstring
63
-
}
64
-
65
47
funcmain() {
66
-
flags:=migrateCmd.Flags()
67
-
flags.StringVar(&opts.name, "name", "", "etcd cluster member name. Defaults to etcd-{hostname}")
68
-
flags.Uint64Var(&opts.port, "port", defaultPort, "etcd client port to use during migration operations. This should be a different port than typically used by etcd to avoid clients accidentally connecting during upgrade/downgrade operations.")
69
-
flags.StringVar(&opts.peerListenUrls, "listen-peer-urls", "", "etcd --listen-peer-urls flag, required for HA clusters")
70
-
flags.StringVar(&opts.peerAdvertiseUrls, "initial-advertise-peer-urls", "", "etcd --initial-advertise-peer-urls flag, required for HA clusters")
71
-
flags.StringVar(&opts.binDir, "bin-dir", "/usr/local/bin", "directory of etcd and etcdctl binaries, must contain etcd-<version> and etcdctl-<version> for each version listed in bindled-versions")
72
-
flags.StringVar(&opts.dataDir, "data-dir", "", "etcd data directory of etcd server to migrate")
73
-
flags.StringVar(&opts.bundledVersionString, "bundled-versions", "", "comma separated list of etcd binary versions present under the bin-dir")
74
-
flags.StringVar(&opts.etcdDataPrefix, "etcd-data-prefix", "/registry", "etcd key prefix under which all objects are kept")
75
-
flags.StringVar(&opts.ttlKeysDirectory, "ttl-keys-directory", "", "etcd key prefix under which all keys with TTLs are kept. Defaults to {etcd-data-prefix}/events")
76
-
flags.StringVar(&opts.initialCluster, "initial-cluster", "", "comma separated list of name=endpoint pairs. Defaults to etcd-{hostname}=http://localhost:2380")
77
-
flags.StringVar(&opts.targetVersion, "target-version", "", "version of etcd to migrate to. Format must be '<major>.<minor>.<patch>'")
78
-
flags.StringVar(&opts.targetStorage, "target-storage", "", "storage version of etcd to migrate to, one of: etcd2, etcd3")
79
-
flags.StringVar(&opts.etcdServerArgs, "etcd-server-extra-args", "", "additional etcd server args for starting etcd servers during migration steps, --peer-* TLS cert flags should be added for etcd clusters with more than 1 member that use mutual TLS for peer communication.")
48
+
registerFlags(migrateCmd.Flags(), &opts)
80
49
err:=migrateCmd.Execute()
81
50
iferr!=nil {
82
-
fmt.Printf("Failed to execute migratecmd: %s", err)
51
+
klog.Errorf("Failed to execute migratecmd: %s", err)
83
52
}
84
53
}
85
54
86
-
// runMigrate validates the command line flags and starts the migration.
55
+
// runMigrate starts the migration.
87
56
funcrunMigrate() {
88
-
ifopts.name=="" {
89
-
hostname, err:=os.Hostname()
90
-
iferr!=nil {
91
-
klog.Errorf("Error while getting hostname to supply default --name: %v", err)
0 commit comments