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 2c05099
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 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` | `"eab0101e112c145ea4973ee127a8ceb7"` | 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
23 changes: 23 additions & 0 deletions 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
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
13 changes: 12 additions & 1 deletion function-app/code/functions/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@ func GetClusterStatus(
}

func GetRefreshStatus(ctx context.Context, subscriptionId, resourceGroupName, stateStorageName, stateContainerName string) (*common.VMSSStateVerbose, error) {
scaleSetNames, err := common.GetScaleSetsNames(ctx, subscriptionId, resourceGroupName, stateStorageName, stateContainerName)
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,14 @@ func GetRefreshStatus(ctx context.Context, subscriptionId, resourceGroupName, st
ActiveVmssNames: scaleSetNames,
TargetConfig: vmssConfig,
}

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

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 = "eab0101e112c145ea4973ee127a8ceb7"
}

variable "function_app_dist" {
Expand Down

0 comments on commit 2c05099

Please sign in to comment.