From 03deff471e0b8efd3250056cf9a6435a9469648f Mon Sep 17 00:00:00 2001 From: niusmallnan Date: Thu, 10 Jan 2019 16:20:57 +0800 Subject: [PATCH] Do not use the previous network settings on DigitalOcean --- pkg/init/cloudinit/cloudinit.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/pkg/init/cloudinit/cloudinit.go b/pkg/init/cloudinit/cloudinit.go index 42174e5b..dbf6cab4 100644 --- a/pkg/init/cloudinit/cloudinit.go +++ b/pkg/init/cloudinit/cloudinit.go @@ -62,9 +62,16 @@ func CloudInit(cfg *config.CloudConfig) (*config.CloudConfig, error) { } if len(stateConfig.Rancher.Network.Interfaces) > 0 { - cfg.Rancher.Network = stateConfig.Rancher.Network - if err := config.Set("rancher.network", stateConfig.Rancher.Network); err != nil { - log.Error(err) + // DO also uses static networking, but this IP may change if: + // 1. not using Floating IP + // 2. creating a droplet with a snapshot, the snapshot cached the previous IP + if onlyDigitalOcean(cfg.Rancher.CloudInit.Datasources) { + log.Info("Do not use the previous network settings on DigitalOcean") + } else { + cfg.Rancher.Network = stateConfig.Rancher.Network + if err := config.Set("rancher.network", stateConfig.Rancher.Network); err != nil { + log.Error(err) + } } } @@ -113,3 +120,16 @@ func onlyConfigDrive(datasources []string) bool { } return false } + +func onlyDigitalOcean(datasources []string) bool { + if len(datasources) != 1 { + return false + } + for _, ds := range datasources { + parts := strings.SplitN(ds, ":", 2) + if parts[0] == "digitalocean" { + return true + } + } + return false +}