mirror of https://github.com/kubernetes/kops.git
azure: Switch to using UserData instead of deprecated CustomData
This commit is contained in:
parent
b32d725355
commit
9e4335b506
|
|
@ -110,7 +110,7 @@ func (b *VMScaleSetModelBuilder) buildVMScaleSetTask(
|
|||
t.SSHPublicKey = fi.String(string(b.SSHPublicKeys[0]))
|
||||
}
|
||||
|
||||
if t.CustomData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig); err != nil {
|
||||
if t.UserData, err = b.BootstrapScriptBuilder.ResourceNodeUp(c, ig); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,15 @@ func (c *mockVMScaleSetsClient) List(ctx context.Context, resourceGroupName stri
|
|||
return c.vmsses, nil
|
||||
}
|
||||
|
||||
func (c *mockVMScaleSetsClient) Get(ctx context.Context, resourceGroupName string, vmssName string) (*compute.VirtualMachineScaleSet, error) {
|
||||
for _, vmss := range c.vmsses {
|
||||
if *vmss.Name == vmssName {
|
||||
return &vmss, nil
|
||||
}
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (c *mockVMScaleSetsClient) Delete(ctx context.Context, resourceGroupName, vmssName string) error {
|
||||
return fmt.Errorf("unimplemented")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
type VMScaleSetsClient interface {
|
||||
CreateOrUpdate(ctx context.Context, resourceGroupName, vmScaleSetName string, parameters compute.VirtualMachineScaleSet) (*compute.VirtualMachineScaleSet, error)
|
||||
List(ctx context.Context, resourceGroupName string) ([]compute.VirtualMachineScaleSet, error)
|
||||
Get(ctx context.Context, resourceGroupName string, vmssName string) (*compute.VirtualMachineScaleSet, error)
|
||||
Delete(ctx context.Context, resourceGroupName, vmssName string) error
|
||||
}
|
||||
|
||||
|
|
@ -63,6 +64,14 @@ func (c *vmScaleSetsClientImpl) List(ctx context.Context, resourceGroupName stri
|
|||
return l, nil
|
||||
}
|
||||
|
||||
func (c *vmScaleSetsClientImpl) Get(ctx context.Context, resourceGroupName string, vmssName string) (*compute.VirtualMachineScaleSet, error) {
|
||||
vmss, err := c.c.Get(ctx, resourceGroupName, vmssName, compute.UserData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &vmss, nil
|
||||
}
|
||||
|
||||
func (c *vmScaleSetsClientImpl) Delete(ctx context.Context, resourceGroupName, vmssName string) error {
|
||||
future, err := c.c.Delete(ctx, resourceGroupName, vmssName, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -403,6 +403,15 @@ func (c *MockVMScaleSetsClient) List(ctx context.Context, resourceGroupName stri
|
|||
return l, nil
|
||||
}
|
||||
|
||||
// Get Returns a specified VM Scale Set.
|
||||
func (c *MockVMScaleSetsClient) Get(ctx context.Context, resourceGroupName string, vmssName string) (*compute.VirtualMachineScaleSet, error) {
|
||||
vmss, ok := c.VMSSes[vmssName]
|
||||
if !ok {
|
||||
return nil, nil
|
||||
}
|
||||
return &vmss, nil
|
||||
}
|
||||
|
||||
// Delete deletes a specified VM Scale Set.
|
||||
func (c *MockVMScaleSetsClient) Delete(ctx context.Context, resourceGroupName, vmssName string) error {
|
||||
// Ignore resourceGroupName for simplicity.
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ type VMScaleSet struct {
|
|||
// AdmnUser specifies the name of the administrative account.
|
||||
AdminUser *string
|
||||
SSHPublicKey *string
|
||||
// CustomData is the user data configuration
|
||||
CustomData fi.Resource
|
||||
// UserData is the user data configuration
|
||||
UserData fi.Resource
|
||||
Tags map[string]*string
|
||||
Zones []string
|
||||
PrincipalID *string
|
||||
|
|
@ -153,17 +153,10 @@ func (s *VMScaleSet) CompareWithID() *string {
|
|||
// Find discovers the VMScaleSet in the cloud provider.
|
||||
func (s *VMScaleSet) Find(c *fi.Context) (*VMScaleSet, error) {
|
||||
cloud := c.Cloud.(azure.AzureCloud)
|
||||
l, err := cloud.VMScaleSet().List(context.TODO(), *s.ResourceGroup.Name)
|
||||
if err != nil {
|
||||
found, err := cloud.VMScaleSet().Get(context.TODO(), *s.ResourceGroup.Name, *s.Name)
|
||||
if err != nil && !strings.Contains(err.Error(), "ResourceNotFound") {
|
||||
return nil, err
|
||||
}
|
||||
var found *compute.VirtualMachineScaleSet
|
||||
for _, v := range l {
|
||||
if *v.Name == *s.Name {
|
||||
found = &v
|
||||
break
|
||||
}
|
||||
}
|
||||
if found == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
@ -204,9 +197,11 @@ func (s *VMScaleSet) Find(c *fi.Context) (*VMScaleSet, error) {
|
|||
return nil, fmt.Errorf("unexpected number of SSH keys found for VM ScaleSet %s: %d", *s.Name, len(sshKeys))
|
||||
}
|
||||
|
||||
// TODO(kenji): Do not check custom data as Azure doesn't
|
||||
// populate (https://github.com/Azure/azure-cli/issues/5866).
|
||||
// Find a way to work around this.
|
||||
userData, err := base64.StdEncoding.DecodeString(*profile.UserData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode user data: %w", err)
|
||||
}
|
||||
|
||||
vmss := &VMScaleSet{
|
||||
Name: s.Name,
|
||||
Lifecycle: s.Lifecycle,
|
||||
|
|
@ -228,6 +223,7 @@ func (s *VMScaleSet) Find(c *fi.Context) (*VMScaleSet, error) {
|
|||
ComputerNamePrefix: osProfile.ComputerNamePrefix,
|
||||
AdminUser: osProfile.AdminUsername,
|
||||
SSHPublicKey: sshKeys[0].KeyData,
|
||||
UserData: fi.NewBytesResource(userData),
|
||||
Tags: found.Tags,
|
||||
PrincipalID: found.Identity.PrincipalID,
|
||||
}
|
||||
|
|
@ -281,10 +277,10 @@ func (s *VMScaleSet) RenderAzure(t *azure.AzureAPITarget, a, e, changes *VMScale
|
|||
name := *e.Name
|
||||
|
||||
var customData *string
|
||||
if e.CustomData != nil {
|
||||
d, err := fi.ResourceAsBytes(e.CustomData)
|
||||
if e.UserData != nil {
|
||||
d, err := fi.ResourceAsBytes(e.UserData)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error rendering CustomData: %s", err)
|
||||
return fmt.Errorf("error rendering UserData: %s", err)
|
||||
}
|
||||
customData = to.StringPtr(base64.StdEncoding.EncodeToString(d))
|
||||
}
|
||||
|
|
@ -292,7 +288,6 @@ func (s *VMScaleSet) RenderAzure(t *azure.AzureAPITarget, a, e, changes *VMScale
|
|||
osProfile := &compute.VirtualMachineScaleSetOSProfile{
|
||||
ComputerNamePrefix: e.ComputerNamePrefix,
|
||||
AdminUsername: e.AdminUser,
|
||||
CustomData: customData,
|
||||
LinuxConfiguration: &compute.LinuxConfiguration{
|
||||
SSH: &compute.SSHConfiguration{
|
||||
PublicKeys: &[]compute.SSHPublicKey{
|
||||
|
|
@ -367,6 +362,7 @@ func (s *VMScaleSet) RenderAzure(t *azure.AzureAPITarget, a, e, changes *VMScale
|
|||
VirtualMachineProfile: &compute.VirtualMachineScaleSetVMProfile{
|
||||
OsProfile: osProfile,
|
||||
StorageProfile: e.StorageProfile.VirtualMachineScaleSetStorageProfile,
|
||||
UserData: customData,
|
||||
NetworkProfile: &compute.VirtualMachineScaleSetNetworkProfile{
|
||||
NetworkInterfaceConfigurations: &[]compute.VirtualMachineScaleSetNetworkConfiguration{
|
||||
networkConfig,
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func newTestVMScaleSet() *VMScaleSet {
|
|||
ComputerNamePrefix: to.StringPtr("cprefix"),
|
||||
AdminUser: to.StringPtr("admin"),
|
||||
SSHPublicKey: to.StringPtr("ssh"),
|
||||
CustomData: fi.NewStringResource("custom"),
|
||||
UserData: fi.NewStringResource("custom"),
|
||||
Tags: map[string]*string{},
|
||||
Zones: []string{"zone1"},
|
||||
}
|
||||
|
|
@ -113,17 +113,17 @@ func TestVMScaleSetRenderAzure(t *testing.T) {
|
|||
if a, e := *actual.Sku.Capacity, *expected.Capacity; a != e {
|
||||
t.Errorf("unexpected SKU Capacity: expected %d, but got %d", e, a)
|
||||
}
|
||||
actualCData, err := base64.StdEncoding.DecodeString(
|
||||
*actual.VirtualMachineProfile.OsProfile.CustomData)
|
||||
actualUserData, err := base64.StdEncoding.DecodeString(
|
||||
*actual.VirtualMachineProfile.UserData)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to decode custom data: %s", err)
|
||||
t.Fatalf("failed to decode user data: %s", err)
|
||||
}
|
||||
expectedCData, err := fi.ResourceAsBytes(expected.CustomData)
|
||||
expectedUserData, err := fi.ResourceAsBytes(expected.UserData)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get custom data: %s", err)
|
||||
t.Fatalf("failed to get user data: %s", err)
|
||||
}
|
||||
if !bytes.Equal(actualCData, expectedCData) {
|
||||
t.Errorf("unexpected custom data: expected %v, but got %v", expectedCData, actualCData)
|
||||
if !bytes.Equal(actualUserData, expectedUserData) {
|
||||
t.Errorf("unexpected user data: expected %v, but got %v", expectedUserData, actualUserData)
|
||||
}
|
||||
|
||||
if expected.PrincipalID == nil {
|
||||
|
|
@ -158,11 +158,10 @@ func TestVMScaleSetFind(t *testing.T) {
|
|||
}
|
||||
|
||||
// Create a VM ScaleSet.
|
||||
customData := []byte("custom")
|
||||
userData := []byte("custom")
|
||||
osProfile := &compute.VirtualMachineScaleSetOSProfile{
|
||||
ComputerNamePrefix: to.StringPtr("prefix"),
|
||||
AdminUsername: to.StringPtr("admin"),
|
||||
CustomData: to.StringPtr(base64.RawStdEncoding.EncodeToString(customData)),
|
||||
LinuxConfiguration: &compute.LinuxConfiguration{
|
||||
SSH: &compute.SSHConfiguration{
|
||||
PublicKeys: &[]compute.SSHPublicKey{
|
||||
|
|
@ -248,6 +247,7 @@ func TestVMScaleSetFind(t *testing.T) {
|
|||
VirtualMachineProfile: &compute.VirtualMachineScaleSetVMProfile{
|
||||
OsProfile: osProfile,
|
||||
StorageProfile: storageProfile,
|
||||
UserData: to.StringPtr(base64.RawStdEncoding.EncodeToString(userData)),
|
||||
NetworkProfile: &compute.VirtualMachineScaleSetNetworkProfile{
|
||||
NetworkInterfaceConfigurations: &[]compute.VirtualMachineScaleSetNetworkConfiguration{
|
||||
networkConfig,
|
||||
|
|
|
|||
Loading…
Reference in New Issue