Skip to content
Open
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
4 changes: 2 additions & 2 deletions api/hypershift/v1beta1/nodepool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type NodePool struct {
// +kubebuilder:validation:XValidation:rule="!has(self.replicas) || !has(self.autoScaling)", message="Both replicas or autoScaling should not be set"
// +kubebuilder:validation:XValidation:rule="self.arch != 's390x' || has(self.platform.kubevirt)", message="s390x is only supported on KubeVirt platform"
// +kubebuilder:validation:XValidation:rule="!has(self.platform.aws) || !has(self.platform.aws.imageType) || self.platform.aws.imageType != 'Windows' || self.arch == 'amd64'", message="ImageType 'Windows' requires arch 'amd64' (AWS only)"
// +kubebuilder:validation:XValidation:rule="!has(self.autoScaling) || self.autoScaling.min > 0 || self.platform.type == 'AWS'", message="Scale-from-zero (autoScaling.min=0) is currently only supported for AWS platform"
// +kubebuilder:validation:XValidation:rule="!has(self.autoScaling) || self.autoScaling.min > 0 || self.platform.type == 'AWS' || self.platform.type == 'Azure'", message="Scale-from-zero (autoScaling.min=0) is currently only supported for AWS and Azure platforms"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
type NodePoolSpec struct {
// clusterName is the name of the HostedCluster this NodePool belongs to.
// If a HostedCluster with this name doesn't exist, the controller will no-op until it exists.
Expand Down Expand Up @@ -501,7 +501,7 @@ type NodePoolManagement struct {
// +kubebuilder:validation:XValidation:rule="self.max >= self.min", message="max must be equal or greater than min"
type NodePoolAutoScaling struct {
// min is the minimum number of nodes to maintain in the pool.
// Can be set to 0 for scale-from-zero for AWS platform.
// Can be set to 0 for scale-from-zero for AWS and Azure platforms.
// Must be >= 0 and <= .Max.
//
// +kubebuilder:validation:Minimum=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
min:
description: |-
min is the minimum number of nodes to maintain in the pool.
Can be set to 0 for scale-from-zero for AWS platform.
Can be set to 0 for scale-from-zero for AWS and Azure platforms.
Must be >= 0 and <= .Max.
format: int32
minimum: 0
Expand Down Expand Up @@ -1518,9 +1518,9 @@ spec:
rule: '!has(self.platform.aws) || !has(self.platform.aws.imageType)
|| self.platform.aws.imageType != ''Windows'' || self.arch == ''amd64'''
- message: Scale-from-zero (autoScaling.min=0) is currently only supported
for AWS platform
for AWS and Azure platforms
rule: '!has(self.autoScaling) || self.autoScaling.min > 0 || self.platform.type
== ''AWS'''
== ''AWS'' || self.platform.type == ''Azure'''
status:
description: status is the latest observed status of the NodePool.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
min:
description: |-
min is the minimum number of nodes to maintain in the pool.
Can be set to 0 for scale-from-zero for AWS platform.
Can be set to 0 for scale-from-zero for AWS and Azure platforms.
Must be >= 0 and <= .Max.
format: int32
minimum: 0
Expand Down Expand Up @@ -1787,9 +1787,9 @@ spec:
rule: '!has(self.platform.aws) || !has(self.platform.aws.imageType)
|| self.platform.aws.imageType != ''Windows'' || self.arch == ''amd64'''
- message: Scale-from-zero (autoScaling.min=0) is currently only supported
for AWS platform
for AWS and Azure platforms
rule: '!has(self.autoScaling) || self.autoScaling.min > 0 || self.platform.type
== ''AWS'''
== ''AWS'' || self.platform.type == ''Azure'''
status:
description: status is the latest observed status of the NodePool.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ spec:
min:
description: |-
min is the minimum number of nodes to maintain in the pool.
Can be set to 0 for scale-from-zero for AWS platform.
Can be set to 0 for scale-from-zero for AWS and Azure platforms.
Must be >= 0 and <= .Max.
format: int32
minimum: 0
Expand Down Expand Up @@ -1705,9 +1705,9 @@ spec:
rule: '!has(self.platform.aws) || !has(self.platform.aws.imageType)
|| self.platform.aws.imageType != ''Windows'' || self.arch == ''amd64'''
- message: Scale-from-zero (autoScaling.min=0) is currently only supported
for AWS platform
for AWS and Azure platforms
rule: '!has(self.autoScaling) || self.autoScaling.min > 0 || self.platform.type
== ''AWS'''
== ''AWS'' || self.platform.type == ''Azure'''
status:
description: status is the latest observed status of the NodePool.
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tests:
id: "subnet-01234567"
type: AWS

- name: when autoScaling min=0 on Azure platform it should fail
- name: when autoScaling min=0 on Azure platform it should pass
initial: |
apiVersion: hypershift.openshift.io/v1beta1
kind: NodePool
Expand All @@ -56,7 +56,6 @@ tests:
diskStorageAccountType: Premium_LRS
subnetID: "/subscriptions/12345678-1234-5678-9012-123456789012/resourceGroups/test-rg/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/test-subnet"
type: Azure
expectedError: "Scale-from-zero (autoScaling.min=0) is currently only supported for AWS platform"

- name: when autoScaling min=0 on Agent platform it should fail
initial: |
Expand All @@ -77,7 +76,7 @@ tests:
agent: {}
type: Agent

expectedError: "Scale-from-zero (autoScaling.min=0) is currently only supported for AWS platform"
expectedError: "Scale-from-zero (autoScaling.min=0) is currently only supported for AWS and Azure platforms"

- name: when autoScaling min=0 on KubeVirt platform it should fail
initial: |
Expand All @@ -101,7 +100,7 @@ tests:
persistent:
size: 32Gi
type: KubeVirt
expectedError: "Scale-from-zero (autoScaling.min=0) is currently only supported for AWS platform"
expectedError: "Scale-from-zero (autoScaling.min=0) is currently only supported for AWS and Azure platforms"

- name: when autoScaling min=1 on Azure platform it should pass
initial: |
Expand Down

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

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

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

7 changes: 2 additions & 5 deletions cmd/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,18 +291,15 @@ func (o *Options) validateScaleFromZeroConfig() []error {
return nil
}
var errs []error
supportedProviders := set.New("aws")
// Check mutual exclusivity - only one of file or secret should be provided
supportedProviders := set.New("aws", "azure")
if len(o.ScaleFromZeroCreds) != 0 && len(o.ScaleFromZeroCredentialsSecret) != 0 {
errs = append(errs, fmt.Errorf("only one of --scale-from-zero-creds or --scale-from-zero-secret is supported"))
}
// Provider is required when using scale-from-zero credentials
if len(o.ScaleFromZeroProvider) == 0 {
errs = append(errs, fmt.Errorf("--scale-from-zero-provider is required when using scale-from-zero credentials"))
} else if !supportedProviders.Has(o.ScaleFromZeroProvider) {
errs = append(errs, fmt.Errorf("invalid --scale-from-zero-provider: %s (must be one of: %v)", o.ScaleFromZeroProvider, supportedProviders.UnsortedList()))
}
// Validate credentials file exists and is accessible if provided
if len(o.ScaleFromZeroCreds) > 0 {
if _, err := os.Stat(o.ScaleFromZeroCreds); err != nil {
if os.IsNotExist(err) {
Expand Down Expand Up @@ -435,7 +432,7 @@ func NewCommand() *cobra.Command {
cmd.PersistentFlags().StringSliceVar(&opts.PlatformsToInstall, "limit-crd-install", opts.PlatformsToInstall, "Used to limit the CRDs that are installed to a per platform basis (example: --limit-crd-install=AWS,Azure). If this flag is not specified, all CRDs for all platforms will be installed. Valid, case-insensitive values are: AWS, Azure, IBMCloud, KubeVirt, Agent, OpenStack, GCP.")
cmd.PersistentFlags().StringToStringVar(&opts.AdditionalOperatorEnvVars, "additional-operator-env-vars", opts.AdditionalOperatorEnvVars, "Set of additional environment variables to be set on the HyperShift Operator deployment.")
cmd.PersistentFlags().BoolVar(&opts.EnableAuditLogPersistence, "enable-audit-log-persistence", opts.EnableAuditLogPersistence, "If true, enables persistent audit logs with automatic snapshots for kube-apiserver pods")
cmd.PersistentFlags().StringVar(&opts.ScaleFromZeroProvider, "scale-from-zero-provider", opts.ScaleFromZeroProvider, "Platform type for scale-from-zero autoscaling (aws)")
cmd.PersistentFlags().StringVar(&opts.ScaleFromZeroProvider, "scale-from-zero-provider", opts.ScaleFromZeroProvider, "Platform type for scale-from-zero autoscaling (aws, azure)")
cmd.PersistentFlags().StringVar(&opts.ScaleFromZeroCreds, "scale-from-zero-creds", opts.ScaleFromZeroCreds, "Path to credentials file for scale-from-zero instance type queries")
cmd.PersistentFlags().StringVar(&opts.ScaleFromZeroCredentialsSecret, "scale-from-zero-secret", opts.ScaleFromZeroCredentialsSecret, "Name of existing secret containing scale-from-zero credentials (alternative to --scale-from-zero-creds)")
cmd.PersistentFlags().StringVar(&opts.ScaleFromZeroCredentialsSecretKey, "scale-from-zero-secret-key", opts.ScaleFromZeroCredentialsSecretKey, "Key within the scale-from-zero credentials secret (default: credentials)")
Expand Down
2 changes: 1 addition & 1 deletion docs/content/reference/aggregated-docs.md

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

2 changes: 1 addition & 1 deletion docs/content/reference/api.md

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

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.21.1
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/authorization/armauthorization/v2 v2.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.7.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/dns/armdns v1.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/msi/armmsi v1.3.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v5 v5.2.0
Expand Down Expand Up @@ -137,7 +138,6 @@ require (
cloud.google.com/go/compute/metadata v0.9.0 // indirect
cyphar.com/go-pathrs v0.2.1 // indirect
github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v5 v5.7.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azsecrets v1.4.0 // indirect
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect
Expand Down
15 changes: 8 additions & 7 deletions hypershift-operator/controllers/nodepool/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const (
// and let nodepool, hostedcluster, and client be fields of CAPI / interface methods.
type CAPI struct {
*Token
capiClusterName string
capiClusterName string
scaleFromZeroPlatform hyperv1.PlatformType
upsert.ApplyProvider
}

Expand Down Expand Up @@ -472,7 +473,7 @@ func (c *CAPI) reconcileMachineDeployment(ctx context.Context, log logr.Logger,
}
}

setMachineDeploymentReplicas(nodePool, machineDeployment)
setMachineDeploymentReplicas(nodePool, machineDeployment, c.scaleFromZeroPlatform)

if updated := c.propagateVersionAndTemplate(log, machineDeployment, machineTemplateCR); updated {
return nil
Expand Down Expand Up @@ -756,7 +757,7 @@ func (c *CAPI) reconcileMachineHealthCheck(ctx context.Context,

// setMachineDeploymentReplicas sets wanted replicas:
// If autoscaling is enabled we reconcile min/max annotations and leave replicas untouched.
func setMachineDeploymentReplicas(nodePool *hyperv1.NodePool, machineDeployment *capiv1.MachineDeployment) {
func setMachineDeploymentReplicas(nodePool *hyperv1.NodePool, machineDeployment *capiv1.MachineDeployment, scaleFromZeroPlatform hyperv1.PlatformType) {
if machineDeployment.Annotations == nil {
machineDeployment.Annotations = make(map[string]string)
}
Expand All @@ -773,7 +774,7 @@ func setMachineDeploymentReplicas(nodePool *hyperv1.NodePool, machineDeployment
// NodePools from being permanently stuck at 0 replicas on platforms that don't support
// scale-from-zero metadata.
effectiveMin := ptr.Deref(nodePool.Spec.AutoScaling.Min, 0)
if effectiveMin == 0 && nodePool.Spec.Platform.Type != hyperv1.AWSPlatform {
if effectiveMin == 0 && nodePool.Spec.Platform.Type != hyperv1.AWSPlatform && nodePool.Spec.Platform.Type != scaleFromZeroPlatform {
effectiveMin = 1
}

Expand Down Expand Up @@ -957,7 +958,7 @@ func (c *CAPI) reconcileMachineSet(ctx context.Context,
}
machineSet.Spec.Template.Annotations[nodePoolAnnotationTaints] = taintsInJSON

setMachineSetReplicas(nodePool, machineSet)
setMachineSetReplicas(nodePool, machineSet, c.scaleFromZeroPlatform)

isUpdating := false
// Propagate version and userData Secret to the MachineSet.
Expand Down Expand Up @@ -1064,7 +1065,7 @@ func machineSetInPlaceRolloutIsComplete(machineSet *capiv1.MachineSet) bool {

// setMachineSetReplicas sets wanted replicas:
// If autoscaling is enabled we reconcile min/max annotations and leave replicas untouched.
func setMachineSetReplicas(nodePool *hyperv1.NodePool, machineSet *capiv1.MachineSet) {
func setMachineSetReplicas(nodePool *hyperv1.NodePool, machineSet *capiv1.MachineSet, scaleFromZeroPlatform hyperv1.PlatformType) {
if machineSet.Annotations == nil {
machineSet.Annotations = make(map[string]string)
}
Expand All @@ -1081,7 +1082,7 @@ func setMachineSetReplicas(nodePool *hyperv1.NodePool, machineSet *capiv1.Machin
// NodePools from being permanently stuck at 0 replicas on platforms that don't support
// scale-from-zero metadata.
effectiveMin := ptr.Deref(nodePool.Spec.AutoScaling.Min, 0)
if effectiveMin == 0 && nodePool.Spec.Platform.Type != hyperv1.AWSPlatform {
if effectiveMin == 0 && nodePool.Spec.Platform.Type != hyperv1.AWSPlatform && nodePool.Spec.Platform.Type != scaleFromZeroPlatform {
effectiveMin = 1
}

Expand Down
Loading