Exemple #1
0
// bootstrapServer copies etcd & fleet into the instances and runs the scaleway bootstrap script.
// It then reboots the instances and waits until it is active again.
func (vp *scalewayProvider) bootstrapServer(instance providers.ClusterInstance, options providers.CreateInstanceOptions, machineID string) error {
	if err := vp.copyEtcd(instance); err != nil {
		vp.Logger.Errorf("copy etcd failed: %#v", err)
		return maskAny(err)
	}
	if err := vp.copyFleet(instance); err != nil {
		vp.Logger.Errorf("copy fleet failed: %#v", err)
		return maskAny(err)
	}

	// Bootstrap
	bootstrapOptions := struct {
		ScalewayProviderConfig
		providers.CreateInstanceOptions
		MachineID string
	}{
		ScalewayProviderConfig: vp.ScalewayProviderConfig,
		CreateInstanceOptions:  options,
		MachineID:              machineID,
	}
	bootstrap, err := templates.Render(bootstrapTemplate, bootstrapOptions)
	if err != nil {
		return maskAny(err)
	}
	vp.Logger.Infof("Running bootstrap on %s. This may take a while...", instance.Name)
	if err := instance.RunScript(vp.Logger, bootstrap, "/root/pulcy-bootstrap.sh"); err != nil {
		// Failed expected because of a reboot
		vp.Logger.Debugf("bootstrap failed (expected): %#v", err)
	}

	vp.Logger.Infof("Done running bootstrap on %s, rebooting...", instance.Name)
	if err := vp.client.PostServerAction(instance.ID, "reboot"); err != nil {
		vp.Logger.Errorf("reboot failed: %#v", err)
		return maskAny(err)
	}
	time.Sleep(time.Second * 5)
	if _, err := vp.waitUntilServerActive(instance.ID, false); err != nil {
		return maskAny(err)
	}

	vp.Logger.Infof("Created server %s %s\n", instance.ID, instance.Name)

	return nil
}