diff --git a/pkg/providers/alibaba/alibaba.go b/pkg/providers/alibaba/alibaba.go index 64bedc30..1abec59b 100644 --- a/pkg/providers/alibaba/alibaba.go +++ b/pkg/providers/alibaba/alibaba.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io/ioutil" "os" "reflect" "strconv" @@ -355,6 +356,7 @@ func (p *Alibaba) runInstances(num int, master bool, password string) error { request.SecurityGroupId = p.SecurityGroup request.Amount = requests.NewInteger(num) request.UniqueSuffix = requests.NewBoolean(false) + request.UserData = p.UserDataContent // check `--eip` value if !p.EIP { bandwidth, err := strconv.Atoi(p.InternetMaxBandwidthOut) @@ -687,6 +689,13 @@ func (p *Alibaba) CreateCheck() error { return fmt.Errorf("[%s] calling preflight error: must set `--zone` in specified region %s to create default vswitch or set exist `--vswitch` in specified region", p.GetProviderName(), p.Region) } + if p.UserDataPath != "" { + _, err = os.Stat(p.UserDataPath) + if err != nil { + return err + } + } + return nil } @@ -1028,6 +1037,16 @@ func (p *Alibaba) generateInstance(ssh *types.SSH) (*types.Cluster, error) { p.VpcCIDR = vpcCIDR } + if p.UserDataPath != "" { + userDataBytes, err := ioutil.ReadFile(p.UserDataPath) + if err != nil { + return nil, err + } + if len(userDataBytes) > 0 { + p.UserDataContent = base64.StdEncoding.EncodeToString(userDataBytes) + } + } + // run ecs master instances. if masterNum > 0 { p.Logger.Infof("[%s] prepare for %d of master instances", p.GetProviderName(), masterNum) diff --git a/pkg/providers/alibaba/flag.go b/pkg/providers/alibaba/flag.go index 3011708e..73fc8de7 100644 --- a/pkg/providers/alibaba/flag.go +++ b/pkg/providers/alibaba/flag.go @@ -286,6 +286,18 @@ func (p *Alibaba) sharedFlags() []types.Flag { V: p.TerwayMaxPoolSize, Usage: "Max pool size for terway ENI mode", }, + { + Name: "user-data-path", + P: &p.UserDataPath, + V: p.UserDataPath, + Usage: "file path of user data to make available to the ECS instance. For more information, see: https://help.aliyun.com/document_detail/108461.html", + }, + { + Name: "user-data-content", + P: &p.UserDataContent, + V: p.UserDataContent, + Usage: "user data content, must be base64-encoded text. For more information, see: https://help.aliyun.com/document_detail/108461.html", + }, } return fs diff --git a/pkg/providers/harvester/harvester.go b/pkg/providers/harvester/harvester.go index d0627f64..64415704 100644 --- a/pkg/providers/harvester/harvester.go +++ b/pkg/providers/harvester/harvester.go @@ -418,7 +418,7 @@ func (h *Harvester) runInstances(num int, master bool, ssh *types.SSH) error { Labels(h.setVMLabels(master)). PVCDisk(rootDiskName, builder.DiskBusVirtio, false, false, 1, h.DiskSize, "", pvcOption). CloudInitDisk(builder.CloudInitDiskName, builder.DiskBusVirtio, false, 0, *cloudInitSource). - EvictionStrategy(true).DefaultPodAntiAffinity().RunStrategy(kubevirtv1.RunStrategyRerunOnFailure) + EvictionStrategy(true).DefaultPodAntiAffinity().Run(false) if h.KeypairName != "" { vmBuilder = vmBuilder.SSHKey(h.KeypairName) diff --git a/pkg/providers/tencent/flag.go b/pkg/providers/tencent/flag.go index 0d9e6473..0cd9312f 100644 --- a/pkg/providers/tencent/flag.go +++ b/pkg/providers/tencent/flag.go @@ -299,6 +299,12 @@ func (p *Tencent) sharedFlags() []types.Flag { V: p.UserDataPath, Usage: "Set user data, i.e.( --user-data-path /file/path ), see: https://cloud.tencent.com/document/product/213/17525", }, + { + Name: "user-data-content", + P: &p.UserDataContent, + V: p.UserDataContent, + Usage: "Set user data content, must be base64-encoded text. see: https://cloud.tencent.com/document/product/213/17525", + }, } return fs diff --git a/pkg/providers/tencent/tencent.go b/pkg/providers/tencent/tencent.go index f7e1d737..783a9290 100644 --- a/pkg/providers/tencent/tencent.go +++ b/pkg/providers/tencent/tencent.go @@ -443,6 +443,16 @@ func (p *Tencent) generateInstance(ssh *types.SSH) (*types.Cluster, error) { p.Logger.Infof("[%s] launching instance with auto-generated password...", p.GetProviderName()) } + if p.UserDataPath != "" { + userDataBytes, err := ioutil.ReadFile(p.UserDataPath) + if err != nil { + return nil, err + } + if len(userDataBytes) > 0 { + p.UserDataContent = base64.StdEncoding.EncodeToString(userDataBytes) + } + } + // run ecs master instances. if masterNum > 0 { p.Logger.Infof("[%s] %d number of master instances will be created", p.GetProviderName(), masterNum) @@ -604,8 +614,8 @@ func (p *Tencent) deleteInstance(f bool) (string, error) { func (p *Tencent) CreateCheck() error { if p.UserDataPath != "" { _, err := os.Stat(p.UserDataPath) - if os.IsNotExist(err) { - return fmt.Errorf("[%s] calling preflight error: file %s is not exist, msg: %v", p.GetProviderName(), p.UserDataPath, err) + if err != nil { + return err } } if p.KeypairID != "" && p.SSHKeyPath == "" { @@ -749,8 +759,7 @@ func (p *Tencent) runInstances(num int, master bool, password string) error { diskSize, _ := strconv.ParseInt(p.SystemDiskSize, 10, 64) bandwidth, _ := strconv.ParseInt(p.InternetMaxBandwidthOut, 10, 64) - userdata, _ := ioutil.ReadFile(p.UserDataPath) - request.UserData = tencentCommon.StringPtr(base64.StdEncoding.EncodeToString(userdata)) + request.UserData = tencentCommon.StringPtr(p.UserDataContent) request.InstanceCount = tencentCommon.Int64Ptr(int64(num)) request.ImageId = tencentCommon.StringPtr(p.ImageID) request.InstanceType = tencentCommon.StringPtr(p.InstanceType) diff --git a/pkg/types/alibaba/alibaba.go b/pkg/types/alibaba/alibaba.go index 5b1fe560..825f6683 100644 --- a/pkg/types/alibaba/alibaba.go +++ b/pkg/types/alibaba/alibaba.go @@ -27,6 +27,8 @@ type Options struct { EIP bool `json:"eip,omitempty" yaml:"eip,omitempty"` Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` CloudControllerManager bool `json:"cloud-controller-manager" yaml:"cloud-controller-manager"` + UserDataPath string `json:"user-data-path,omitempty" yaml:"user-data-path,omitempty"` + UserDataContent string `json:"user-data-content,omitempty" yaml:"user-data-content,omitempty"` } // Terway struct for alibaba terway. diff --git a/pkg/types/tencent/tencent.go b/pkg/types/tencent/tencent.go index 32973dd5..b647edb1 100644 --- a/pkg/types/tencent/tencent.go +++ b/pkg/types/tencent/tencent.go @@ -41,6 +41,7 @@ type Options struct { Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` CloudControllerManager bool `json:"cloud-controller-manager" yaml:"cloud-controller-manager"` UserDataPath string `json:"user-data-path,omitempty" yaml:"user-data-path,omitempty"` + UserDataContent string `json:"user-data-content,omitempty" yaml:"user-data-content,omitempty"` } // CloudControllerManager struct for tencent cloud-controller-manager.