Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## 2.6.0-beta.1 (Unreleased)

- Supported spot virtual machine for agent pool of `KubernetesCluster`.

## 2.5.0 (2021-05-28)
- Supported system-assigned managed identity and auto-scaler profile for `KubernetesCluster`.
- Supported auto-scaling, availability zones, node labels and taints for agent pool of `KubernetesCluster`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.azure.resourcemanager.containerservice.models.ManagedClusterAgentPoolProfile;
import com.azure.resourcemanager.containerservice.models.OSType;
import com.azure.resourcemanager.containerservice.models.PowerState;
import com.azure.resourcemanager.containerservice.models.ScaleSetEvictionPolicy;
import com.azure.resourcemanager.containerservice.models.ScaleSetPriority;
import com.azure.resourcemanager.resources.fluentcore.arm.ResourceUtils;
import com.azure.resourcemanager.resources.fluentcore.arm.models.implementation.ChildResourceImpl;
import com.azure.resourcemanager.resources.fluentcore.utils.ResourceManagerUtils;
Expand Down Expand Up @@ -132,6 +134,21 @@ public int maximumNodeSize() {
return ResourceManagerUtils.toPrimitiveInt(innerModel().maxCount());
}

@Override
public ScaleSetPriority virtualMachinePriority() {
return innerModel().scaleSetPriority();
}

@Override
public ScaleSetEvictionPolicy virtualMachineEvictionPolicy() {
return innerModel().scaleSetEvictionPolicy();
}

@Override
public Double virtualMachineMaximumPrice() {
return innerModel().spotMaxPrice().doubleValue();
}

@Override
public KubernetesClusterAgentPoolImpl withVirtualMachineSize(ContainerServiceVMSizeTypes vmSize) {
this.innerModel().withVmSize(vmSize.toString());
Expand Down Expand Up @@ -260,4 +277,29 @@ public KubernetesClusterAgentPoolImpl withNodeTaints(List<String> nodeTaints) {
innerModel().withNodeTaints(nodeTaints);
return this;
}

@Override
public KubernetesClusterAgentPoolImpl withVirtualMachinePriority(ScaleSetPriority priority) {
innerModel().withScaleSetPriority(priority);
return this;
}

@Override
public KubernetesClusterAgentPoolImpl withSpotPriorityVirtualMachine() {
innerModel().withScaleSetPriority(ScaleSetPriority.SPOT);
return this;
}

@Override
public KubernetesClusterAgentPoolImpl withSpotPriorityVirtualMachine(ScaleSetEvictionPolicy policy) {
innerModel().withScaleSetPriority(ScaleSetPriority.SPOT);
innerModel().withScaleSetEvictionPolicy(policy);
return this;
}

@Override
public KubernetesClusterAgentPoolImpl withVirtualMachineMaximumPrice(Double maxPriceInUsDollars) {
innerModel().withSpotMaxPrice(maxPriceInUsDollars.floatValue());
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ public interface KubernetesClusterAgentPool
/** @return the maximum number of nodes for auto-scaling */
int maximumNodeSize();

/** @return the priority of each virtual machines in the agent pool */
ScaleSetPriority virtualMachinePriority();

/** @return the eviction policy of each virtual machines in the agent pool */
ScaleSetEvictionPolicy virtualMachineEvictionPolicy();

/** @return the maximum price of each spot virtual machines in the agent pool, -1 means pay-as-you-go prices */
Double virtualMachineMaximumPrice();

// Fluent interfaces

/**
Expand Down Expand Up @@ -282,6 +291,54 @@ interface WithAgentPoolMode<ParentT> {
WithAttach<ParentT> withAgentPoolMode(AgentPoolMode agentPoolMode);
}

/**
* The stage of a container service agent pool definition allowing to specify the priority of the virtual
* machine.
*
* @param <ParentT> the stage of the container service definition to return to after attaching this definition
*/
interface WithVMPriority<ParentT> {
/**
* Specifies the priority of the virtual machines.
*
* @param priority the priority
* @return the next stage of the definition
*/
WithAttach<ParentT> withVirtualMachinePriority(ScaleSetPriority priority);

/**
* Specify that virtual machines should be spot priority VMs.
*
* @return the next stage of the definition
*/
WithAttach<ParentT> withSpotPriorityVirtualMachine();

/**
* Specify that virtual machines should be spot priority VMs with provided eviction policy.
*
* @param policy eviction policy for the virtual machines.
* @return the next stage of the definition
*/
WithAttach<ParentT> withSpotPriorityVirtualMachine(ScaleSetEvictionPolicy policy);
}

/**
* The stage of a container service agent pool definition allowing to specify the agent pool mode.
*
* @param <ParentT> the stage of the container service definition to return to after attaching this definition
*/
interface WithBillingProfile<ParentT> {
/**
* Sets the maximum price for virtual machine in agent pool. This price is in US Dollars.
*
* Default is -1 if not specified, as up to pay-as-you-go prices.
*
* @param maxPriceInUsDollars the maximum price in US Dollars
* @return the next stage of the definition
*/
WithAttach<ParentT> withVirtualMachineMaximumPrice(Double maxPriceInUsDollars);
}

/**
* The final stage of a container service agent pool definition. At this stage, any remaining optional settings
* can be specified, or the container service agent pool can be attached to the parent container service
Expand All @@ -300,6 +357,8 @@ interface WithAttach<ParentT>
WithAutoScaling<ParentT>,
WithAvailabilityZones<ParentT>,
WithNodeLabelsTaints<ParentT>,
WithVMPriority<ParentT>,
WithBillingProfile<ParentT>,
Attachable.InDefinition<ParentT> {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import com.azure.resourcemanager.containerservice.models.KubernetesClusterAgentPool;
import com.azure.core.management.Region;
import com.azure.resourcemanager.containerservice.models.ManagedClusterPropertiesAutoScalerProfile;
import com.azure.resourcemanager.containerservice.models.ScaleSetEvictionPolicy;
import com.azure.resourcemanager.containerservice.models.ScaleSetPriority;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.Assertions;
Expand Down Expand Up @@ -240,6 +242,63 @@ public void canAutoScaleKubernetesCluster() throws Exception {
Assertions.assertEquals(0, agentPoolProfile3.nodeSize());
}

@Test
public void canCreateClusterWithSpotVM() throws Exception {
String aksName = generateRandomResourceName("aks", 15);
String dnsPrefix = generateRandomResourceName("dns", 10);
String agentPoolName = generateRandomResourceName("ap0", 10);
String agentPoolName1 = generateRandomResourceName("ap1", 10);
String agentPoolName2 = generateRandomResourceName("ap2", 10);

// create cluster
KubernetesCluster kubernetesCluster = containerServiceManager.kubernetesClusters().define(aksName)
.withRegion(Region.US_CENTRAL)
.withExistingResourceGroup(rgName)
.withDefaultVersion()
.withRootUsername("testaks")
.withSshKey(SSH_KEY)
.withSystemAssignedManagedServiceIdentity()
.defineAgentPool(agentPoolName)
.withVirtualMachineSize(ContainerServiceVMSizeTypes.STANDARD_D2_V2)
.withAgentPoolVirtualMachineCount(1)
.withAgentPoolType(AgentPoolType.VIRTUAL_MACHINE_SCALE_SETS)
.withAgentPoolMode(AgentPoolMode.SYSTEM)
.attach()
// spot vm
.defineAgentPool(agentPoolName1)
.withVirtualMachineSize(ContainerServiceVMSizeTypes.STANDARD_A2_V2)
.withAgentPoolVirtualMachineCount(1)
.withSpotPriorityVirtualMachine()
.attach()
.withDnsPrefix("mp1" + dnsPrefix)
.create();

// print config
System.out.println(new String(kubernetesCluster.adminKubeConfigContent(), StandardCharsets.UTF_8));

KubernetesClusterAgentPool agentPoolProfile = kubernetesCluster.agentPools().get(agentPoolName);
Assertions.assertTrue(agentPoolProfile.virtualMachinePriority() == null || agentPoolProfile.virtualMachinePriority() == ScaleSetPriority.REGULAR);

KubernetesClusterAgentPool agentPoolProfile1 = kubernetesCluster.agentPools().get(agentPoolName1);
Assertions.assertEquals(ScaleSetPriority.SPOT, agentPoolProfile1.virtualMachinePriority());
Assertions.assertEquals(ScaleSetEvictionPolicy.DELETE, agentPoolProfile1.virtualMachineEvictionPolicy());
Assertions.assertEquals(-1.0, agentPoolProfile1.virtualMachineMaximumPrice());

kubernetesCluster.update()
.defineAgentPool(agentPoolName2)
.withVirtualMachineSize(ContainerServiceVMSizeTypes.STANDARD_A2_V2)
.withAgentPoolVirtualMachineCount(1)
.withSpotPriorityVirtualMachine(ScaleSetEvictionPolicy.DEALLOCATE)
.withVirtualMachineMaximumPrice(100.0)
.attach()
Comment on lines +288 to +293

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sample here

.apply();

KubernetesClusterAgentPool agentPoolProfile2 = kubernetesCluster.agentPools().get(agentPoolName2);
Assertions.assertEquals(ScaleSetPriority.SPOT, agentPoolProfile2.virtualMachinePriority());
Assertions.assertEquals(ScaleSetEvictionPolicy.DEALLOCATE, agentPoolProfile2.virtualMachineEvictionPolicy());
Assertions.assertEquals(100.0, agentPoolProfile2.virtualMachineMaximumPrice());
}

/**
* Parse azure auth to hashmap
*
Expand Down
Loading