Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure: enable CustomData if the userdata has cloud-init format #546

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions platform/api/azure/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v5"

"github.com/flatcar/mantle/platform/conf"
"github.com/flatcar/mantle/util"
)

Expand All @@ -52,7 +53,7 @@ func (a *API) getVMRG(rg string) string {
return vmrg
}

func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string, ip *armnetwork.PublicIPAddress, nic *armnetwork.Interface) armcompute.VirtualMachine {
func (a *API) getVMParameters(name, sshkey, storageAccountURI string, userdata *conf.Conf, ip *armnetwork.PublicIPAddress, nic *armnetwork.Interface) armcompute.VirtualMachine {
osProfile := armcompute.OSProfile{
AdminUsername: to.Ptr("core"),
ComputerName: &name,
Expand All @@ -69,7 +70,7 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
}

// Encode userdata to base64.
ud := base64.StdEncoding.EncodeToString([]byte(userdata))
ud := base64.StdEncoding.EncodeToString(userdata.Bytes())

var imgRef *armcompute.ImageReference
var plan *armcompute.Plan
Expand Down Expand Up @@ -164,7 +165,7 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
// I don't think it would be an issue to have empty user-data set but better
// to be safe than sorry.
if ud != "" {
if a.Opts.UseUserData {
if a.Opts.UseUserData && userdata.IsIgnition() {
plog.Infof("using user-data")
vm.Properties.UserData = &ud
} else {
Expand All @@ -181,7 +182,7 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
return vm
}

func (a *API) CreateInstance(name, userdata, sshkey, resourceGroup, storageAccount string, network Network) (*Machine, error) {
func (a *API) CreateInstance(name, sshkey, resourceGroup, storageAccount string, userdata *conf.Conf, network Network) (*Machine, error) {
// only VMs are created in the user supplied resource group, kola still manages a resource group
// for the gallery and storage account.
vmResourceGroup := a.getVMRG(resourceGroup)
Expand All @@ -203,7 +204,7 @@ func (a *API) CreateInstance(name, userdata, sshkey, resourceGroup, storageAccou
return nil, fmt.Errorf("couldn't get NIC name")
}

vmParams := a.getVMParameters(name, userdata, sshkey, fmt.Sprintf("https://%s.blob.core.windows.net/", storageAccount), ip, nic)
vmParams := a.getVMParameters(name, sshkey, fmt.Sprintf("https://%s.blob.core.windows.net/", storageAccount), userdata, ip, nic)
plog.Infof("Creating Instance %s", name)

clean := func() {
Expand Down
2 changes: 1 addition & 1 deletion platform/machine/azure/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (ac *cluster) NewMachine(userdata *conf.UserData) (platform.Machine, error)
return nil, err
}

instance, err := ac.flight.Api.CreateInstance(ac.vmname(), conf.String(), ac.sshKey, ac.ResourceGroup, ac.StorageAccount, ac.Network)
instance, err := ac.flight.Api.CreateInstance(ac.vmname(), ac.sshKey, ac.ResourceGroup, ac.StorageAccount, conf, ac.Network)
if err != nil {
return nil, err
}
Expand Down