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

chore: remove Virtual Machine ScaleSets support. #243

Merged
merged 1 commit into from
Apr 30, 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ ginkgoBuild: generate
make -C ./test/e2e ginkgo-build

test: generate
ginkgo -mod=vendor -junit-report -skip-package test/e2e -fail-fast -r -v -tags=fast .
ginkgo -mod=vendor -junit-report test/junit/junit.xml -skip-package test/e2e -fail-fast -r -v -tags=fast .

.PHONY: test-style
test-style: validate-go validate-shell validate-copyright-headers
Expand Down
37 changes: 3 additions & 34 deletions cmd/addpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/Azure/aks-engine-azurestack/pkg/helpers"
"github.com/Azure/aks-engine-azurestack/pkg/i18n"
"github.com/Azure/aks-engine-azurestack/pkg/operations"
"github.com/Azure/go-autorest/autorest/to"
"github.com/leonelquinteros/gotext"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -144,16 +143,6 @@ func (apc *addPoolCmd) load() error {
return errors.Wrap(err, "error parsing the agent pool")
}

// Assign VMSSName property based on the new pool being added to the end of the existing AgentPoolProfiles array
if apc.nodePool.IsVirtualMachineScaleSets() {
numExistingPools := len(apc.containerService.Properties.AgentPoolProfiles)
// we can reuse the value of numExistingPools due to array index beginning at "0"
apc.nodePool.VMSSName = apc.containerService.Properties.GetAgentVMPrefix(apc.nodePool, numExistingPools)
if apc.nodePool.VMSSName == "" {
return errors.Errorf("unable to compute a VMSSName property value from new pool definition")
}
}

if apc.containerService.Properties.IsCustomCloudProfile() {
if err = writeCustomCloudProfile(apc.containerService); err != nil {
return errors.Wrap(err, "error writing custom cloud profile")
Expand Down Expand Up @@ -216,18 +205,6 @@ func (apc *addPoolCmd) run(cmd *cobra.Command, args []string) error {
orchestratorInfo := apc.containerService.Properties.OrchestratorProfile
winPoolIndex := -1

if apc.nodePool.IsVirtualMachineScaleSets() {
for vmssListPage, err := apc.client.ListVirtualMachineScaleSets(ctx, apc.resourceGroupName); vmssListPage.NotDone(); err = vmssListPage.NextWithContext(ctx) {
if err != nil {
return errors.Wrap(err, "failed to get VMSS list in the resource group")
}
for _, vmss := range vmssListPage.Values() {
if apc.nodePool.VMSSName == to.String(vmss.Name) {
return errors.New("A VMSS node pool with the given name already exists in the cluster")
}
}
}
}
translator := engine.Context{
Translator: &i18n.Translator{
Locale: apc.locale,
Expand Down Expand Up @@ -288,17 +265,9 @@ func (apc *addPoolCmd) run(cmd *cobra.Command, args []string) error {
}
}

if apc.nodePool.IsVirtualMachineScaleSets() {
err = transformer.NormalizeForK8sVMASScalingUp(apc.logger, templateJSON)
if err != nil {
return errors.Wrapf(err, "error transforming the template for scaling template %s", apc.apiModelPath)
}
addValue(parametersJSON, apc.nodePool.Name+"Count", 0)
} else {
err = transformer.NormalizeForK8sAddVMASPool(apc.logger, templateJSON)
if err != nil {
return errors.Wrap(err, "error transforming the template to add a VMAS node pool")
}
err = transformer.NormalizeForK8sAddVMASPool(apc.logger, templateJSON)
if err != nil {
return errors.Wrap(err, "error transforming the template to add a VMAS node pool")
}

random := rand.New(rand.NewSource(time.Now().UnixNano()))
Expand Down
11 changes: 0 additions & 11 deletions cmd/rotate_certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,6 @@ func (rcc *rotateCertsCmd) waitForVMsRunning(nodes []string) error {
if err := ops.WaitForVMsRunning(rcc.armClient, rcc.resourceGroupName, nodes, rotateCertsDefaultInterval, rotateCertsDefaultTimeout); err != nil {
return errors.Wrap(err, "waiting for VMs to reach the running state")
}
} else {
vmssName := fmt.Sprintf("%svmss", rcc.cs.Properties.GetMasterVMPrefix())
count := rcc.cs.Properties.MasterProfile.Count
if err := ops.WaitForVMSSIntancesRunning(rcc.armClient, rcc.resourceGroupName, vmssName, count, rotateCertsDefaultInterval, rotateCertsDefaultTimeout); err != nil {
return errors.Wrap(err, "waiting for VMs to reach the running state")
}
}
return nil
}
Expand All @@ -640,11 +634,6 @@ func (rcc *rotateCertsCmd) rebootNodes(nodes ...string) error {
return errors.Wrapf(err, "rebooting host %s", node)
}
}
} else {
vmssName := fmt.Sprintf("%svmss", rcc.cs.Properties.GetMasterVMPrefix())
if err := rcc.armClient.RestartVirtualMachineScaleSets(rcc.resourceGroupName, vmssName); err != nil {
return errors.Wrapf(err, "rebooting vmss %s", vmssName)
}
}
return nil
}
Expand Down
30 changes: 0 additions & 30 deletions cmd/rotatecerts/arm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,6 @@ func (arm *ARMClientWrapper) GetVirtualMachinePowerState(resourceGroup, vmName s
return status, err
}

// GetVirtualMachineScaleSetInstancePowerState restarts the specified scale set virtual machine instance
func (arm *ARMClientWrapper) GetVirtualMachineScaleSetInstancePowerState(resourceGroup, vmssName, instanceID string) (string, error) {
var err error
status := ""
err = retry.OnError(arm.backoff, arm.retryFunc, func() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
status, err = arm.client.GetVirtualMachineScaleSetInstancePowerState(ctx, resourceGroup, vmssName, instanceID)
if err != nil {
return errors.Wrap(err, "fetching virtual machine resource")
}
return nil
})
return status, err
}

// RestartVirtualMachine returns the virtual machine's Power state
func (arm *ARMClientWrapper) RestartVirtualMachine(resourceGroup, vmName string) error {
var err error
Expand All @@ -81,20 +65,6 @@ func (arm *ARMClientWrapper) RestartVirtualMachine(resourceGroup, vmName string)
return err
}

// RestartVirtualMachineScaleSets returns the scale set virtual machine instance's Power state
func (arm *ARMClientWrapper) RestartVirtualMachineScaleSets(resourceGroup, vmssName string) error {
var err error
err = retry.OnError(arm.backoff, arm.retryFunc, func() error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
if err = arm.client.RestartVirtualMachineScaleSets(ctx, resourceGroup, vmssName, nil); err != nil {
return errors.Wrap(err, "restarting virtual machine")
}
return nil
})
return err
}

func isVirtualMachineRunning(status string) bool {
return strings.EqualFold(status, "PowerState/running")
}
6 changes: 0 additions & 6 deletions cmd/rotatecerts/internal/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,6 @@ type ARMClient interface {
// RestartVirtualMachine restarts the specified virtual machine.
RestartVirtualMachine(resourceGroup, vmName string) error

// RestartVirtualMachineScaleSets restarts the specified virtual machine scale set.
RestartVirtualMachineScaleSets(resourceGroup, vmssName string) error

// GetVirtualMachinePowerState returns the virtual machine's Power state.
GetVirtualMachinePowerState(resourceGroup, vmName string) (string, error)

// GetVirtualMachineScaleSetInstancePowerState returns the virtual machine's Power state.
GetVirtualMachineScaleSetInstancePowerState(resourceGroup, vmssName, instanceID string) (string, error)
}
29 changes: 0 additions & 29 deletions cmd/rotatecerts/internal/mock_internal/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 0 additions & 31 deletions cmd/rotatecerts/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package rotatecerts

import (
"context"
"fmt"
"time"

"github.com/Azure/aks-engine-azurestack/cmd/rotatecerts/internal"
Expand Down Expand Up @@ -301,33 +300,3 @@ func WaitForVMsRunning(client internal.ARMClient, resourceGroupName string, requ
})
return err
}

// WaitForVMSSIntancesRunning checks that all required scale set VMs are running
func WaitForVMSSIntancesRunning(client internal.ARMClient, resourceGroupName, vmssName string, count int, interval, timeout time.Duration) error {
var err error
var successesCount int
err = wait.PollImmediate(interval, timeout, func() (bool, error) {
allRunning := true
for i := 0; i < count; i++ {
var state string
state, err = client.GetVirtualMachineScaleSetInstancePowerState(resourceGroupName, vmssName, fmt.Sprint(i))
if err != nil {
return false, nil
}
running := isVirtualMachineRunning(state)
if err != nil {
return false, err
}
allRunning = allRunning && running
}
if !allRunning {
return false, nil
}
successesCount++
if successesCount < 1 {
return false, nil
}
return true, nil
})
return err
}
40 changes: 0 additions & 40 deletions cmd/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"time"

"github.com/Azure/aks-engine-azurestack/pkg/armhelpers/utils"
"github.com/Azure/go-autorest/autorest/to"

"github.com/Azure/aks-engine-azurestack/pkg/api"
"github.com/Azure/aks-engine-azurestack/pkg/armhelpers"
Expand Down Expand Up @@ -226,11 +225,6 @@ func (sc *scaleCmd) load() error {
}
}

// Back-compat logic to populate the VMSSName property for clusters built prior to VMSSName being a part of the API model spec
if sc.agentPool.IsVirtualMachineScaleSets() && sc.agentPool.VMSSName == "" {
sc.agentPool.VMSSName = sc.containerService.Properties.GetAgentVMPrefix(sc.agentPool, sc.agentPoolIndex)
}

//allows to identify VMs in the resource group that belong to this cluster.
sc.nameSuffix = sc.containerService.Properties.GetClusterID()
log.Debugf("Cluster ID used in all agent pools: %s", sc.nameSuffix)
Expand Down Expand Up @@ -411,40 +405,6 @@ func (sc *scaleCmd) run(cmd *cobra.Command, args []string) error {
return sc.saveAPIModel()
}
}
} else {
for vmssListPage, err := sc.client.ListVirtualMachineScaleSets(ctx, sc.resourceGroupName); vmssListPage.NotDone(); err = vmssListPage.NextWithContext(ctx) {
if err != nil {
return errors.Wrap(err, "failed to get VMSS list in the resource group")
}
for _, vmss := range vmssListPage.Values() {
vmssName := to.String(vmss.Name)
if sc.agentPool.VMSSName == vmssName {
log.Infof("found VMSS %s in resource group %s that correlates with node pool %s", vmssName, sc.resourceGroupName, sc.agentPoolToScale)
} else {
continue
}

if vmss.Sku != nil {
currentNodeCount = int(*vmss.Sku.Capacity)
if int(*vmss.Sku.Capacity) == sc.newDesiredAgentCount && !sc.updateVMSSModel {
sc.printScaleTargetEqualsExisting(currentNodeCount)
return nil
} else if int(*vmss.Sku.Capacity) > sc.newDesiredAgentCount {
log.Warnf("VMSS scale down is an alpha feature: VMSS VM nodes will not be cordoned and drained before scaling down!")
}
} else {
// Fall back to comparing against the known count value in the api model
if sc.agentPool.Count == sc.newDesiredAgentCount {
sc.printScaleTargetEqualsExisting(currentNodeCount)
return nil
}
}

currentNodeCount = int(*vmss.Sku.Capacity)
highestUsedIndex = 0
break
}
}
}

translator := engine.Context{
Expand Down
23 changes: 0 additions & 23 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ import (
"os"
"path/filepath"

"regexp"
"strings"
"time"

"github.com/Azure/aks-engine-azurestack/pkg/api"
"github.com/Azure/aks-engine-azurestack/pkg/api/common"
"github.com/Azure/aks-engine-azurestack/pkg/armhelpers"
"github.com/Azure/aks-engine-azurestack/pkg/armhelpers/utils"
"github.com/Azure/aks-engine-azurestack/pkg/engine"
"github.com/Azure/aks-engine-azurestack/pkg/helpers"
"github.com/Azure/aks-engine-azurestack/pkg/i18n"
Expand Down Expand Up @@ -390,7 +388,6 @@ func (uc *upgradeCmd) run(cmd *cobra.Command, args []string) error {
}
}

upgradeCluster.IsVMSSToBeUpgraded = isVMSSNameInAgentPoolsArray
upgradeCluster.CurrentVersion = uc.currentVersion

if err = upgradeCluster.UpgradeCluster(uc.client, kubeConfig, BuildTag); err != nil {
Expand Down Expand Up @@ -423,26 +420,6 @@ func (uc *upgradeCmd) run(cmd *cobra.Command, args []string) error {
return f.SaveFile(dir, file, b)
}

// isVMSSNameInAgentPoolsArray is a helper func to filter out any VMSS in the cluster resource group
// that are not participating in the aks-engine-created Kubernetes cluster
func isVMSSNameInAgentPoolsArray(vmss string, cs *api.ContainerService) bool {
for _, pool := range cs.Properties.AgentPoolProfiles {
if pool.AvailabilityProfile == api.VirtualMachineScaleSets {
if pool.OSType == api.Windows {
re := regexp.MustCompile(`^[0-9]{4}k8s[0]+`)
if re.FindString(vmss) != "" {
return true
}
} else {
if poolName, _, _ := utils.VmssNameParts(vmss); poolName == pool.Name {
return true
}
}
}
}
return false
}

// validateOSBaseImage checks if the OS image is available on the target cloud (ATM, Azure Stack only)
func (uc *upgradeCmd) validateOSBaseImage() error {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
Expand Down
Loading