Skip to content

Commit

Permalink
feat: add latest_config field to vmss status output
Browse files Browse the repository at this point in the history
  • Loading branch information
kristina-solovyova committed Feb 16, 2024
1 parent 14bc0f1 commit a17a1f6
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ proxy_url = VALUE
| <a name="input_function_app_storage_account_prefix"></a> [function\_app\_storage\_account\_prefix](#input\_function\_app\_storage\_account\_prefix) | Weka storage account name prefix | `string` | `"weka"` | no |
| <a name="input_function_app_subnet_delegation_cidr"></a> [function\_app\_subnet\_delegation\_cidr](#input\_function\_app\_subnet\_delegation\_cidr) | Subnet delegation enables you to designate a specific subnet for an Azure PaaS service. | `string` | `"10.0.1.0/25"` | no |
| <a name="input_function_app_subnet_delegation_id"></a> [function\_app\_subnet\_delegation\_id](#input\_function\_app\_subnet\_delegation\_id) | Required to specify if subnet\_name were used to specify pre-defined subnets for weka. Function subnet delegation requires an additional subnet, and in the case of pre-defined networking this one also should be pre-defined | `string` | `""` | no |
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"1724b274e2e6e636b84109b2d459000f"` | no |
| <a name="input_function_app_version"></a> [function\_app\_version](#input\_function\_app\_version) | Function app code version (hash) | `string` | `"7b4b459de8ab86c1a9e0c43e34346274"` | no |
| <a name="input_get_weka_io_token"></a> [get\_weka\_io\_token](#input\_get\_weka\_io\_token) | The token to download the Weka release from get.weka.io. | `string` | `""` | no |
| <a name="input_hotspare"></a> [hotspare](#input\_hotspare) | Number of hotspares to set on weka cluster. Refer to https://docs.weka.io/overview/ssd-capacity-management#hot-spare | `number` | `1` | no |
| <a name="input_install_cluster_dpdk"></a> [install\_cluster\_dpdk](#input\_install\_cluster\_dpdk) | Install weka cluster with DPDK | `bool` | `true` | no |
Expand Down
32 changes: 31 additions & 1 deletion function-app/code/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -1315,11 +1315,34 @@ func GetScaleSetNameWithLatestConfiguration(ctx context.Context, subscriptionId,
err = fmt.Errorf("failed to read vmss state: %v", err)
return
}
return GetScaleSetNameWithLatestConfigurationFromState(ctx, subscriptionId, resourceGroupName, &vmssState)
}

func GetScaleSetNameWithLatestConfigurationFromState(ctx context.Context, subscriptionId, resourceGroupName string, vmssState *VMSSState) (scaleSetName string, err error) {
latestVersion := vmssState.GetLatestVersion()
scaleSetName = GetVmScaleSetName(vmssState.Prefix, vmssState.ClusterName, latestVersion)
return scaleSetName, nil
}

func GetLatestScaleSetConfiguration(ctx context.Context, subscriptionId, resourceGroupName string, vmssState *VMSSState) (vmssConfig *VMSSConfig, err error) {
logger := logging.LoggerFromCtx(ctx)

scaleSetName, err := GetScaleSetNameWithLatestConfigurationFromState(ctx, subscriptionId, resourceGroupName, vmssState)
if err != nil {
err = fmt.Errorf("cannot get the latest scale set name: %w", err)
logger.Error().Err(err).Send()
return
}
scaleSet, err := getScaleSet(ctx, subscriptionId, resourceGroupName, scaleSetName)
if err != nil {
err = fmt.Errorf("cannot get the latest scale set: %w", err)
logger.Error().Err(err).Send()
return
}
vmssConfig = GetVmssConfig(ctx, resourceGroupName, scaleSet)
return
}

func GetScaleSetsByVersion(ctx context.Context, subscriptionId, resourceGroupName string, vmssState *VMSSState) (map[int]*armcompute.VirtualMachineScaleSet, error) {
logger := logging.LoggerFromCtx(ctx)

Expand Down Expand Up @@ -1421,13 +1444,20 @@ func GetVmssConfig(ctx context.Context, resourceGroupName string, scaleSet *armc
ppg = &val
}

var sourceImageID string
if scaleSet.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID != nil {
sourceImageID = *scaleSet.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID
} else {
sourceImageID = *scaleSet.Properties.VirtualMachineProfile.StorageProfile.ImageReference.ID
}

vmssConfig := &VMSSConfig{
Name: *scaleSet.Name,
Location: *scaleSet.Location,
Zones: PtrArrToStrArray(scaleSet.Zones),
ResourceGroupName: resourceGroupName,
SKU: *scaleSet.SKU.Name,
SourceImageID: *scaleSet.Properties.VirtualMachineProfile.StorageProfile.ImageReference.CommunityGalleryImageID,
SourceImageID: sourceImageID,
Tags: PtrMapToStrMap(scaleSet.Tags),

UpgradeMode: string(*scaleSet.Properties.UpgradePolicy.Mode),
Expand Down
5 changes: 3 additions & 2 deletions function-app/code/common/vmss_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ func (q *VMSSState) RemoveVersion(item int) error {
}

type VMSSStateVerbose struct {
ActiveVmssNames []string `json:"active_vmss_names"`
TargetConfig VMSSConfig `json:"target_config"`
ActiveVmssNames []string `json:"active_vmss_names"`
TargetConfig VMSSConfig `json:"target_config"`
LatestConfig *VMSSConfig `json:"latest_config,omitempty"`
}

func ToEnumStrValue[T interface{ ~string }](val string, possibleEnumValues []T) (*T, error) {
Expand Down
4 changes: 4 additions & 0 deletions function-app/code/functions/scale_up/scale_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ func HandleVmssUpdate(ctx context.Context, currentConfig, newConfig *common.VMSS
msg := fmt.Sprintf("cannot change vmss SKU from %s to %s, need refresh", currentConfig.SKU, newConfig.SKU)
logger.Info().Msg(msg)
refreshNeeded = true
} else if currentConfig.SourceImageID != newConfig.SourceImageID {
msg := fmt.Sprintf("cannot change vmss source image from %s to %s, need refresh", currentConfig.SourceImageID, newConfig.SourceImageID)
logger.Info().Msg(msg)
refreshNeeded = true
} else {
_, err := common.CreateOrUpdateVmss(ctx, subscriptionId, resourceGroupName, currentConfig.Name, newConfigHash, *newConfig, desiredSize)
if err != nil {
Expand Down
21 changes: 18 additions & 3 deletions function-app/code/functions/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,15 @@ func GetClusterStatus(
return
}

func GetRefreshStatus(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName string) (*common.VMSSStateVerbose, error) {
scaleSetNames, err := common.GetScaleSetsNames(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName)
func GetRefreshStatus(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName string, extended bool) (*common.VMSSStateVerbose, error) {
vmssState, err := common.ReadVmssState(ctx, stateStorageName, stateContainerName)
if err != nil {
err = fmt.Errorf("failed to read vmss state: %v", err)
return nil, err
}

scaleSetNames := common.GetScaleSetsNamesFromVmssState(ctx, subscriptionId, resourceGroupName, &vmssState)

vmssConfig, err := common.ReadVmssConfig(ctx, stateStorageName, stateContainerName)
if err != nil {
return nil, err
Expand All @@ -121,6 +124,16 @@ func GetRefreshStatus(ctx context.Context, subscriptionId, resourceGroupName, st
ActiveVmssNames: scaleSetNames,
TargetConfig: vmssConfig,
}

if len(scaleSetNames) > 0 && extended {
latestConfig, err := common.GetLatestScaleSetConfiguration(ctx, subscriptionId, resourceGroupName, &vmssState)
if err != nil {
return nil, err
}
latestConfig.CustomData = "<hidden>"
latestConfig.SshPublicKey = "<hidden>"
result.LatestConfig = latestConfig
}
return result, nil
}

Expand Down Expand Up @@ -172,7 +185,9 @@ func Handler(w http.ResponseWriter, r *http.Request) {
} else if requestBody.Type == "progress" {
result, err = GetReports(ctx, stateStorageName, stateContainerName)
} else if requestBody.Type == "vmss" {
result, err = GetRefreshStatus(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName)
result, err = GetRefreshStatus(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName, false)
} else if requestBody.Type == "vmss-extended" {
result, err = GetRefreshStatus(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName, true)
} else {
result = "Invalid status type"
}
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ variable "function_app_storage_account_container_prefix" {
variable "function_app_version" {
type = string
description = "Function app code version (hash)"
default = "1724b274e2e6e636b84109b2d459000f"
default = "7b4b459de8ab86c1a9e0c43e34346274"
}

variable "function_app_dist" {
Expand Down

0 comments on commit a17a1f6

Please sign in to comment.