etcd.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // Copyright 2015 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package etcdmain
  15. import (
  16. "encoding/json"
  17. "fmt"
  18. "io/ioutil"
  19. "net/http"
  20. "os"
  21. "path/filepath"
  22. "reflect"
  23. "runtime"
  24. "strings"
  25. "time"
  26. "github.com/coreos/etcd/embed"
  27. "github.com/coreos/etcd/etcdserver"
  28. "github.com/coreos/etcd/etcdserver/api/etcdhttp"
  29. "github.com/coreos/etcd/etcdserver/api/v2discovery"
  30. "github.com/coreos/etcd/pkg/fileutil"
  31. pkgioutil "github.com/coreos/etcd/pkg/ioutil"
  32. "github.com/coreos/etcd/pkg/osutil"
  33. "github.com/coreos/etcd/pkg/transport"
  34. "github.com/coreos/etcd/pkg/types"
  35. "github.com/coreos/etcd/proxy/httpproxy"
  36. "github.com/coreos/etcd/version"
  37. "github.com/coreos/pkg/capnslog"
  38. "go.uber.org/zap"
  39. "google.golang.org/grpc"
  40. )
  41. type dirType string
  42. var plog = capnslog.NewPackageLogger("github.com/coreos/etcd", "etcdmain")
  43. var (
  44. dirMember = dirType("member")
  45. dirProxy = dirType("proxy")
  46. dirEmpty = dirType("empty")
  47. )
  48. func startEtcdOrProxyV2() {
  49. grpc.EnableTracing = false
  50. cfg := newConfig()
  51. defaultInitialCluster := cfg.ec.InitialCluster
  52. err := cfg.parse(os.Args[1:])
  53. if err != nil {
  54. lg := cfg.ec.GetLogger()
  55. if lg != nil {
  56. lg.Warn("failed to verify flags", zap.Error(err))
  57. } else {
  58. plog.Errorf("error verifying flags, %v. See 'etcd --help'.", err)
  59. }
  60. switch err {
  61. case embed.ErrUnsetAdvertiseClientURLsFlag:
  62. if lg != nil {
  63. lg.Warn("advertise client URLs are not set", zap.Error(err))
  64. } else {
  65. plog.Errorf("When listening on specific address(es), this etcd process must advertise accessible url(s) to each connected client.")
  66. }
  67. }
  68. os.Exit(1)
  69. }
  70. maxProcs, cpus := runtime.GOMAXPROCS(0), runtime.NumCPU()
  71. lg := cfg.ec.GetLogger()
  72. if lg != nil {
  73. lg.Info(
  74. "starting etcd",
  75. zap.String("etcd-version", version.Version),
  76. zap.String("git-sha", version.GitSHA),
  77. zap.String("go-version", runtime.Version()),
  78. zap.String("go-os", runtime.GOOS),
  79. zap.String("go-arch", runtime.GOARCH),
  80. zap.Int("max-cpu-set", maxProcs),
  81. zap.Int("max-cpu-available", cpus),
  82. )
  83. } else {
  84. plog.Infof("etcd Version: %s\n", version.Version)
  85. plog.Infof("Git SHA: %s\n", version.GitSHA)
  86. plog.Infof("Go Version: %s\n", runtime.Version())
  87. plog.Infof("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
  88. plog.Infof("setting maximum number of CPUs to %d, total number of available CPUs is %d", maxProcs, cpus)
  89. }
  90. defer func() {
  91. logger := cfg.ec.GetLogger()
  92. if logger != nil {
  93. logger.Sync()
  94. }
  95. }()
  96. defaultHost, dhErr := (&cfg.ec).UpdateDefaultClusterFromName(defaultInitialCluster)
  97. if defaultHost != "" {
  98. if lg != nil {
  99. lg.Info(
  100. "detected default host for advertise",
  101. zap.String("host", defaultHost),
  102. )
  103. } else {
  104. plog.Infof("advertising using detected default host %q", defaultHost)
  105. }
  106. }
  107. if dhErr != nil {
  108. if lg != nil {
  109. lg.Info("failed to detect default host", zap.Error(dhErr))
  110. } else {
  111. plog.Noticef("failed to detect default host (%v)", dhErr)
  112. }
  113. }
  114. if cfg.ec.Dir == "" {
  115. cfg.ec.Dir = fmt.Sprintf("%v.etcd", cfg.ec.Name)
  116. if lg != nil {
  117. lg.Warn(
  118. "'data-dir' was empty; using default",
  119. zap.String("data-dir", cfg.ec.Dir),
  120. )
  121. } else {
  122. plog.Warningf("no data-dir provided, using default data-dir ./%s", cfg.ec.Dir)
  123. }
  124. }
  125. var stopped <-chan struct{}
  126. var errc <-chan error
  127. which := identifyDataDirOrDie(cfg.ec.GetLogger(), cfg.ec.Dir)
  128. if which != dirEmpty {
  129. if lg != nil {
  130. lg.Info(
  131. "server has been already initialized",
  132. zap.String("data-dir", cfg.ec.Dir),
  133. zap.String("dir-type", string(which)),
  134. )
  135. } else {
  136. plog.Noticef("the server is already initialized as %v before, starting as etcd %v...", which, which)
  137. }
  138. switch which {
  139. case dirMember:
  140. stopped, errc, err = startEtcd(&cfg.ec)
  141. case dirProxy:
  142. err = startProxy(cfg)
  143. default:
  144. if lg != nil {
  145. lg.Panic(
  146. "unknown directory type",
  147. zap.String("dir-type", string(which)),
  148. )
  149. } else {
  150. plog.Panicf("unhandled dir type %v", which)
  151. }
  152. }
  153. } else {
  154. shouldProxy := cfg.isProxy()
  155. if !shouldProxy {
  156. stopped, errc, err = startEtcd(&cfg.ec)
  157. if derr, ok := err.(*etcdserver.DiscoveryError); ok && derr.Err == v2discovery.ErrFullCluster {
  158. if cfg.shouldFallbackToProxy() {
  159. if lg != nil {
  160. lg.Warn(
  161. "discovery cluster is full, falling back to proxy",
  162. zap.String("fallback-proxy", fallbackFlagProxy),
  163. zap.Error(err),
  164. )
  165. } else {
  166. plog.Noticef("discovery cluster full, falling back to %s", fallbackFlagProxy)
  167. }
  168. shouldProxy = true
  169. }
  170. } else if err != nil {
  171. if lg != nil {
  172. lg.Warn("failed to start etcd", zap.Error(err))
  173. }
  174. }
  175. }
  176. if shouldProxy {
  177. err = startProxy(cfg)
  178. }
  179. }
  180. if err != nil {
  181. if derr, ok := err.(*etcdserver.DiscoveryError); ok {
  182. switch derr.Err {
  183. case v2discovery.ErrDuplicateID:
  184. if lg != nil {
  185. lg.Warn(
  186. "member has been registered with discovery service",
  187. zap.String("name", cfg.ec.Name),
  188. zap.String("discovery-token", cfg.ec.Durl),
  189. zap.Error(derr.Err),
  190. )
  191. lg.Warn(
  192. "but could not find valid cluster configuration",
  193. zap.String("data-dir", cfg.ec.Dir),
  194. )
  195. lg.Warn("check data dir if previous bootstrap succeeded")
  196. lg.Warn("or use a new discovery token if previous bootstrap failed")
  197. } else {
  198. plog.Errorf("member %q has previously registered with discovery service token (%s).", cfg.ec.Name, cfg.ec.Durl)
  199. plog.Errorf("But etcd could not find valid cluster configuration in the given data dir (%s).", cfg.ec.Dir)
  200. plog.Infof("Please check the given data dir path if the previous bootstrap succeeded")
  201. plog.Infof("or use a new discovery token if the previous bootstrap failed.")
  202. }
  203. case v2discovery.ErrDuplicateName:
  204. if lg != nil {
  205. lg.Warn(
  206. "member with duplicated name has already been registered",
  207. zap.String("discovery-token", cfg.ec.Durl),
  208. zap.Error(derr.Err),
  209. )
  210. lg.Warn("cURL the discovery token URL for details")
  211. lg.Warn("do not reuse discovery token; generate a new one to bootstrap a cluster")
  212. } else {
  213. plog.Errorf("member with duplicated name has registered with discovery service token(%s).", cfg.ec.Durl)
  214. plog.Errorf("please check (cURL) the discovery token for more information.")
  215. plog.Errorf("please do not reuse the discovery token and generate a new one to bootstrap the cluster.")
  216. }
  217. default:
  218. if lg != nil {
  219. lg.Warn(
  220. "failed to bootstrap; discovery token was already used",
  221. zap.String("discovery-token", cfg.ec.Durl),
  222. zap.Error(err),
  223. )
  224. lg.Warn("do not reuse discovery token; generate a new one to bootstrap a cluster")
  225. } else {
  226. plog.Errorf("%v", err)
  227. plog.Infof("discovery token %s was used, but failed to bootstrap the cluster.", cfg.ec.Durl)
  228. plog.Infof("please generate a new discovery token and try to bootstrap again.")
  229. }
  230. }
  231. os.Exit(1)
  232. }
  233. if strings.Contains(err.Error(), "include") && strings.Contains(err.Error(), "--initial-cluster") {
  234. if lg != nil {
  235. lg.Warn("failed to start", zap.Error(err))
  236. } else {
  237. plog.Infof("%v", err)
  238. }
  239. if cfg.ec.InitialCluster == cfg.ec.InitialClusterFromName(cfg.ec.Name) {
  240. if lg != nil {
  241. lg.Warn("forgot to set --initial-cluster?")
  242. } else {
  243. plog.Infof("forgot to set --initial-cluster flag?")
  244. }
  245. }
  246. if types.URLs(cfg.ec.APUrls).String() == embed.DefaultInitialAdvertisePeerURLs {
  247. if lg != nil {
  248. lg.Warn("forgot to set --initial-advertise-peer-urls?")
  249. } else {
  250. plog.Infof("forgot to set --initial-advertise-peer-urls flag?")
  251. }
  252. }
  253. if cfg.ec.InitialCluster == cfg.ec.InitialClusterFromName(cfg.ec.Name) && len(cfg.ec.Durl) == 0 {
  254. if lg != nil {
  255. lg.Warn("--discovery flag is not set")
  256. } else {
  257. plog.Infof("if you want to use discovery service, please set --discovery flag.")
  258. }
  259. }
  260. os.Exit(1)
  261. }
  262. if lg != nil {
  263. lg.Fatal("discovery failed", zap.Error(err))
  264. } else {
  265. plog.Fatalf("%v", err)
  266. }
  267. }
  268. osutil.HandleInterrupts(lg)
  269. // At this point, the initialization of etcd is done.
  270. // The listeners are listening on the TCP ports and ready
  271. // for accepting connections. The etcd instance should be
  272. // joined with the cluster and ready to serve incoming
  273. // connections.
  274. notifySystemd(lg)
  275. select {
  276. case lerr := <-errc:
  277. // fatal out on listener errors
  278. if lg != nil {
  279. lg.Fatal("listener failed", zap.Error(err))
  280. } else {
  281. plog.Fatal(lerr)
  282. }
  283. case <-stopped:
  284. }
  285. osutil.Exit(0)
  286. }
  287. // startEtcd runs StartEtcd in addition to hooks needed for standalone etcd.
  288. func startEtcd(cfg *embed.Config) (<-chan struct{}, <-chan error, error) {
  289. e, err := embed.StartEtcd(cfg)
  290. if err != nil {
  291. return nil, nil, err
  292. }
  293. osutil.RegisterInterruptHandler(e.Close)
  294. select {
  295. case <-e.Server.ReadyNotify(): // wait for e.Server to join the cluster
  296. case <-e.Server.StopNotify(): // publish aborted from 'ErrStopped'
  297. }
  298. return e.Server.StopNotify(), e.Err(), nil
  299. }
  300. // startProxy launches an HTTP proxy for client communication which proxies to other etcd nodes.
  301. func startProxy(cfg *config) error {
  302. lg := cfg.ec.GetLogger()
  303. if lg != nil {
  304. lg.Info("v2 API proxy starting")
  305. } else {
  306. plog.Notice("proxy: this proxy supports v2 API only!")
  307. }
  308. clientTLSInfo := cfg.ec.ClientTLSInfo
  309. if clientTLSInfo.Empty() {
  310. // Support old proxy behavior of defaulting to PeerTLSInfo
  311. // for both client and peer connections.
  312. clientTLSInfo = cfg.ec.PeerTLSInfo
  313. }
  314. clientTLSInfo.InsecureSkipVerify = cfg.ec.ClientAutoTLS
  315. cfg.ec.PeerTLSInfo.InsecureSkipVerify = cfg.ec.PeerAutoTLS
  316. pt, err := transport.NewTimeoutTransport(
  317. clientTLSInfo,
  318. time.Duration(cfg.cp.ProxyDialTimeoutMs)*time.Millisecond,
  319. time.Duration(cfg.cp.ProxyReadTimeoutMs)*time.Millisecond,
  320. time.Duration(cfg.cp.ProxyWriteTimeoutMs)*time.Millisecond,
  321. )
  322. if err != nil {
  323. return err
  324. }
  325. pt.MaxIdleConnsPerHost = httpproxy.DefaultMaxIdleConnsPerHost
  326. if err = cfg.ec.PeerSelfCert(); err != nil {
  327. if lg != nil {
  328. lg.Fatal("failed to get self-signed certs for peer", zap.Error(err))
  329. } else {
  330. plog.Fatalf("could not get certs (%v)", err)
  331. }
  332. }
  333. tr, err := transport.NewTimeoutTransport(
  334. cfg.ec.PeerTLSInfo,
  335. time.Duration(cfg.cp.ProxyDialTimeoutMs)*time.Millisecond,
  336. time.Duration(cfg.cp.ProxyReadTimeoutMs)*time.Millisecond,
  337. time.Duration(cfg.cp.ProxyWriteTimeoutMs)*time.Millisecond,
  338. )
  339. if err != nil {
  340. return err
  341. }
  342. cfg.ec.Dir = filepath.Join(cfg.ec.Dir, "proxy")
  343. err = os.MkdirAll(cfg.ec.Dir, fileutil.PrivateDirMode)
  344. if err != nil {
  345. return err
  346. }
  347. var peerURLs []string
  348. clusterfile := filepath.Join(cfg.ec.Dir, "cluster")
  349. b, err := ioutil.ReadFile(clusterfile)
  350. switch {
  351. case err == nil:
  352. if cfg.ec.Durl != "" {
  353. if lg != nil {
  354. lg.Warn(
  355. "discovery token ignored since the proxy has already been initialized; valid cluster file found",
  356. zap.String("cluster-file", clusterfile),
  357. )
  358. } else {
  359. plog.Warningf("discovery token ignored since the proxy has already been initialized. Valid cluster file found at %q", clusterfile)
  360. }
  361. }
  362. if cfg.ec.DNSCluster != "" {
  363. if lg != nil {
  364. lg.Warn(
  365. "DNS SRV discovery ignored since the proxy has already been initialized; valid cluster file found",
  366. zap.String("cluster-file", clusterfile),
  367. )
  368. } else {
  369. plog.Warningf("DNS SRV discovery ignored since the proxy has already been initialized. Valid cluster file found at %q", clusterfile)
  370. }
  371. }
  372. urls := struct{ PeerURLs []string }{}
  373. err = json.Unmarshal(b, &urls)
  374. if err != nil {
  375. return err
  376. }
  377. peerURLs = urls.PeerURLs
  378. if lg != nil {
  379. lg.Info(
  380. "proxy using peer URLS from cluster file",
  381. zap.Strings("peer-urls", peerURLs),
  382. zap.String("cluster-file", clusterfile),
  383. )
  384. } else {
  385. plog.Infof("proxy: using peer urls %v from cluster file %q", peerURLs, clusterfile)
  386. }
  387. case os.IsNotExist(err):
  388. var urlsmap types.URLsMap
  389. urlsmap, _, err = cfg.ec.PeerURLsMapAndToken("proxy")
  390. if err != nil {
  391. return fmt.Errorf("error setting up initial cluster: %v", err)
  392. }
  393. if cfg.ec.Durl != "" {
  394. var s string
  395. s, err = v2discovery.GetCluster(lg, cfg.ec.Durl, cfg.ec.Dproxy)
  396. if err != nil {
  397. return err
  398. }
  399. if urlsmap, err = types.NewURLsMap(s); err != nil {
  400. return err
  401. }
  402. }
  403. peerURLs = urlsmap.URLs()
  404. if lg != nil {
  405. lg.Info("proxy using peer URLS", zap.Strings("peer-urls", peerURLs))
  406. } else {
  407. plog.Infof("proxy: using peer urls %v ", peerURLs)
  408. }
  409. default:
  410. return err
  411. }
  412. clientURLs := []string{}
  413. uf := func() []string {
  414. gcls, gerr := etcdserver.GetClusterFromRemotePeers(lg, peerURLs, tr)
  415. if gerr != nil {
  416. if lg != nil {
  417. lg.Warn(
  418. "failed to get cluster from remote peers",
  419. zap.Strings("peer-urls", peerURLs),
  420. zap.Error(gerr),
  421. )
  422. } else {
  423. plog.Warningf("proxy: %v", gerr)
  424. }
  425. return []string{}
  426. }
  427. clientURLs = gcls.ClientURLs()
  428. urls := struct{ PeerURLs []string }{gcls.PeerURLs()}
  429. b, jerr := json.Marshal(urls)
  430. if jerr != nil {
  431. if lg != nil {
  432. lg.Warn("proxy failed to marshal peer URLs", zap.Error(jerr))
  433. } else {
  434. plog.Warningf("proxy: error on marshal peer urls %s", jerr)
  435. }
  436. return clientURLs
  437. }
  438. err = pkgioutil.WriteAndSyncFile(clusterfile+".bak", b, 0600)
  439. if err != nil {
  440. if lg != nil {
  441. lg.Warn("proxy failed to write cluster file", zap.Error(err))
  442. } else {
  443. plog.Warningf("proxy: error on writing urls %s", err)
  444. }
  445. return clientURLs
  446. }
  447. err = os.Rename(clusterfile+".bak", clusterfile)
  448. if err != nil {
  449. if lg != nil {
  450. lg.Warn(
  451. "proxy failed to rename cluster file",
  452. zap.String("path", clusterfile),
  453. zap.Error(err),
  454. )
  455. } else {
  456. plog.Warningf("proxy: error on updating clusterfile %s", err)
  457. }
  458. return clientURLs
  459. }
  460. if !reflect.DeepEqual(gcls.PeerURLs(), peerURLs) {
  461. if lg != nil {
  462. lg.Info(
  463. "proxy updated peer URLs",
  464. zap.Strings("from", peerURLs),
  465. zap.Strings("to", gcls.PeerURLs()),
  466. )
  467. } else {
  468. plog.Noticef("proxy: updated peer urls in cluster file from %v to %v", peerURLs, gcls.PeerURLs())
  469. }
  470. }
  471. peerURLs = gcls.PeerURLs()
  472. return clientURLs
  473. }
  474. ph := httpproxy.NewHandler(pt, uf, time.Duration(cfg.cp.ProxyFailureWaitMs)*time.Millisecond, time.Duration(cfg.cp.ProxyRefreshIntervalMs)*time.Millisecond)
  475. ph = embed.WrapCORS(cfg.ec.CORS, ph)
  476. if cfg.isReadonlyProxy() {
  477. ph = httpproxy.NewReadonlyHandler(ph)
  478. }
  479. // setup self signed certs when serving https
  480. cHosts, cTLS := []string{}, false
  481. for _, u := range cfg.ec.LCUrls {
  482. cHosts = append(cHosts, u.Host)
  483. cTLS = cTLS || u.Scheme == "https"
  484. }
  485. for _, u := range cfg.ec.ACUrls {
  486. cHosts = append(cHosts, u.Host)
  487. cTLS = cTLS || u.Scheme == "https"
  488. }
  489. listenerTLS := cfg.ec.ClientTLSInfo
  490. if cfg.ec.ClientAutoTLS && cTLS {
  491. listenerTLS, err = transport.SelfCert(cfg.ec.GetLogger(), filepath.Join(cfg.ec.Dir, "clientCerts"), cHosts)
  492. if err != nil {
  493. if lg != nil {
  494. lg.Fatal("failed to initialize self-signed client cert", zap.Error(err))
  495. } else {
  496. plog.Fatalf("proxy: could not initialize self-signed client certs (%v)", err)
  497. }
  498. }
  499. }
  500. // Start a proxy server goroutine for each listen address
  501. for _, u := range cfg.ec.LCUrls {
  502. l, err := transport.NewListener(u.Host, u.Scheme, &listenerTLS)
  503. if err != nil {
  504. return err
  505. }
  506. host := u.String()
  507. go func() {
  508. if lg != nil {
  509. lg.Info("v2 proxy started listening on client requests", zap.String("host", host))
  510. } else {
  511. plog.Infof("v2 proxy started listening on client requests on %q", host)
  512. }
  513. mux := http.NewServeMux()
  514. etcdhttp.HandlePrometheus(mux) // v2 proxy just uses the same port
  515. mux.Handle("/", ph)
  516. plog.Fatal(http.Serve(l, mux))
  517. }()
  518. }
  519. return nil
  520. }
  521. // identifyDataDirOrDie returns the type of the data dir.
  522. // Dies if the datadir is invalid.
  523. func identifyDataDirOrDie(lg *zap.Logger, dir string) dirType {
  524. names, err := fileutil.ReadDir(dir)
  525. if err != nil {
  526. if os.IsNotExist(err) {
  527. return dirEmpty
  528. }
  529. if lg != nil {
  530. lg.Fatal("failed to list data directory", zap.String("dir", dir), zap.Error(err))
  531. } else {
  532. plog.Fatalf("error listing data dir: %s", dir)
  533. }
  534. }
  535. var m, p bool
  536. for _, name := range names {
  537. switch dirType(name) {
  538. case dirMember:
  539. m = true
  540. case dirProxy:
  541. p = true
  542. default:
  543. if lg != nil {
  544. lg.Warn(
  545. "found invalid file under data directory",
  546. zap.String("filename", name),
  547. zap.String("data-dir", dir),
  548. )
  549. } else {
  550. plog.Warningf("found invalid file/dir %s under data dir %s (Ignore this if you are upgrading etcd)", name, dir)
  551. }
  552. }
  553. }
  554. if m && p {
  555. if lg != nil {
  556. lg.Fatal("invalid datadir; both member and proxy directories exist")
  557. } else {
  558. plog.Fatal("invalid datadir. Both member and proxy directories exist.")
  559. }
  560. }
  561. if m {
  562. return dirMember
  563. }
  564. if p {
  565. return dirProxy
  566. }
  567. return dirEmpty
  568. }
  569. func checkSupportArch() {
  570. // TODO qualify arm64
  571. if runtime.GOARCH == "amd64" || runtime.GOARCH == "ppc64le" {
  572. return
  573. }
  574. // unsupported arch only configured via environment variable
  575. // so unset here to not parse through flag
  576. defer os.Unsetenv("ETCD_UNSUPPORTED_ARCH")
  577. if env, ok := os.LookupEnv("ETCD_UNSUPPORTED_ARCH"); ok && env == runtime.GOARCH {
  578. fmt.Printf("running etcd on unsupported architecture %q since ETCD_UNSUPPORTED_ARCH is set\n", env)
  579. return
  580. }
  581. fmt.Printf("etcd on unsupported platform without ETCD_UNSUPPORTED_ARCH=%s set\n", runtime.GOARCH)
  582. os.Exit(1)
  583. }