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