Skip to content

Commit 592c6c2

Browse files
awesomenixk8s-ci-robot
authored andcommitted
Remove hardcoded values from virtual machines, respect values from machineconfig instead (#147)
1 parent d40b704 commit 592c6c2

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

pkg/cloud/azure/actuators/machine/actuator.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
191191
Name: scope.Machine.Name,
192192
NICName: networkInterfaceSpec.Name,
193193
SSHKeyData: string(decoded),
194+
Size: scope.MachineConfig.VMSize,
195+
OSDisk: scope.MachineConfig.OSDisk,
196+
Image: scope.MachineConfig.Image,
194197
}
198+
195199
err = virtualmachines.NewService(scope.Scope).CreateOrUpdate(context.Background(), vmSpec)
196200
if err != nil {
197201
klog.Errorf("failed to create or get machine: %+v", err)

pkg/cloud/azure/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package azure
1818

1919
const (
20+
// DefaultUserName is the default username for created vm
21+
DefaultUserName = "capi"
2022
// DefaultVnetName is the default name for the cluster's virtual network.
2123
DefaultVnetName = "ClusterAPIVnet"
2224
// DefaultVnetCIDR is the default Vnet CIDR

pkg/cloud/azure/services/virtualmachines/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ go_library(
99
importpath = "sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/virtualmachines",
1010
visibility = ["//visibility:public"],
1111
deps = [
12+
"//pkg/apis/azureprovider/v1alpha1:go_default_library",
1213
"//pkg/cloud/azure:go_default_library",
1314
"//pkg/cloud/azure/actuators:go_default_library",
1415
"//pkg/cloud/azure/services/networkinterfaces:go_default_library",

pkg/cloud/azure/services/virtualmachines/virtualmachines.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ import (
2121
"crypto/rand"
2222
"crypto/rsa"
2323
"encoding/base64"
24+
"fmt"
2425

2526
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-10-01/compute"
2627
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-12-01/network"
2728
"github.com/Azure/go-autorest/autorest/to"
2829
"github.com/pkg/errors"
2930
"golang.org/x/crypto/ssh"
3031
"k8s.io/klog"
32+
"sigs.k8s.io/cluster-api-provider-azure/pkg/apis/azureprovider/v1alpha1"
3133
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure"
3234
"sigs.k8s.io/cluster-api-provider-azure/pkg/cloud/azure/services/networkinterfaces"
3335
)
@@ -37,6 +39,9 @@ type Spec struct {
3739
Name string
3840
NICName string
3941
SSHKeyData string
42+
Size string
43+
Image v1alpha1.Image
44+
OSDisk v1alpha1.OSDisk
4045
}
4146

4247
// Get provides information about a virtual network.
@@ -101,29 +106,34 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
101106
Location: to.StringPtr(s.Scope.ClusterConfig.Location),
102107
VirtualMachineProperties: &compute.VirtualMachineProperties{
103108
HardwareProfile: &compute.HardwareProfile{
104-
VMSize: compute.VirtualMachineSizeTypes("Standard_DS2_v2"),
109+
VMSize: compute.VirtualMachineSizeTypes(vmSpec.Size),
105110
},
106111
StorageProfile: &compute.StorageProfile{
107112
ImageReference: &compute.ImageReference{
108-
Publisher: to.StringPtr("Canonical"),
109-
Offer: to.StringPtr("UbuntuServer"),
110-
Sku: to.StringPtr("18.04-LTS"),
111-
Version: to.StringPtr("latest"),
113+
Publisher: to.StringPtr(vmSpec.Image.Publisher),
114+
Offer: to.StringPtr(vmSpec.Image.Offer),
115+
Sku: to.StringPtr(vmSpec.Image.SKU),
116+
Version: to.StringPtr(vmSpec.Image.Version),
112117
},
113118
OsDisk: &compute.OSDisk{
119+
Name: to.StringPtr(fmt.Sprintf("%s_OSDisk", vmSpec.Name)),
120+
OsType: compute.OperatingSystemTypes(vmSpec.OSDisk.OSType),
114121
CreateOption: compute.DiskCreateOptionTypesFromImage,
115-
DiskSizeGB: to.Int32Ptr(64),
122+
DiskSizeGB: to.Int32Ptr(vmSpec.OSDisk.DiskSizeGB),
123+
ManagedDisk: &compute.ManagedDiskParameters{
124+
StorageAccountType: compute.StorageAccountTypes(vmSpec.OSDisk.ManagedDisk.StorageAccountType),
125+
},
116126
},
117127
},
118128
OsProfile: &compute.OSProfile{
119129
ComputerName: to.StringPtr(vmSpec.Name),
120-
AdminUsername: to.StringPtr("azureuser"),
130+
AdminUsername: to.StringPtr(azure.DefaultUserName),
121131
AdminPassword: to.StringPtr(randomPassword),
122132
LinuxConfiguration: &compute.LinuxConfiguration{
123133
SSH: &compute.SSHConfiguration{
124134
PublicKeys: &[]compute.SSHPublicKey{
125135
{
126-
Path: to.StringPtr("/home/azureuser/.ssh/authorized_keys"),
136+
Path: to.StringPtr(fmt.Sprintf("/home/%s/.ssh/authorized_keys", azure.DefaultUserName)),
127137
KeyData: to.StringPtr(sshKeyData),
128138
},
129139
},

0 commit comments

Comments
 (0)