-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/auto scale behavior client (#235)
* Update Go version to 1.22 and toolchain to go1.23.2 * feat: Add test for AutoScaleBehaviorSet function * feat: Add flags for autoscale down behavior settings * fix: corrected package versions * feat: Add scale down behavior details to app string representation * feat: Implement scale down behavior JSON handling in client * test: checking auto scale down output in app details
- Loading branch information
Showing
7 changed files
with
233 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2016 tsuru-client authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package client | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/tsuru/go-tsuruclient/pkg/tsuru" | ||
) | ||
|
||
type behaviorScaleDownJson struct { | ||
ScaleDown scaleDownJson `json:"scaleDown"` | ||
} | ||
|
||
type scaleDownJson struct { | ||
UnitsPolicyValue *int32 `json:"unitsPolicyValue,omitempty"` | ||
PercentagePolicyValue *int32 `json:"percentagePolicyValue,omitempty"` | ||
StabilizationWindow *int32 `json:"stabilizationWindow,omitempty"` | ||
} | ||
|
||
type scaleDownOutput struct { | ||
UnitsPolicyValue string `json:"unitsPolicyValue,omitempty"` | ||
PercentagePolicyValue string `json:"percentagePolicyValue,omitempty"` | ||
StabilizationWindow string `json:"stabilizationWindow,omitempty"` | ||
} | ||
|
||
func getParamsScaleDownJson(behavior tsuru.AutoScaleSpecBehavior) scaleDownOutput { | ||
b, err := json.Marshal(behavior) | ||
if err != nil { | ||
return scaleDownOutput{} | ||
} | ||
var behaviorJson behaviorScaleDownJson | ||
err = json.Unmarshal(b, &behaviorJson) | ||
if err != nil { | ||
return scaleDownOutput{} | ||
} | ||
output := scaleDownOutput{} | ||
if behaviorJson.ScaleDown.UnitsPolicyValue != nil { | ||
output.UnitsPolicyValue = fmt.Sprintf("%d", *behaviorJson.ScaleDown.UnitsPolicyValue) | ||
} | ||
if behaviorJson.ScaleDown.PercentagePolicyValue != nil { | ||
output.PercentagePolicyValue = fmt.Sprintf("%d", *behaviorJson.ScaleDown.PercentagePolicyValue) | ||
} | ||
if behaviorJson.ScaleDown.StabilizationWindow != nil { | ||
output.StabilizationWindow = fmt.Sprintf("%d", *behaviorJson.ScaleDown.StabilizationWindow) | ||
} | ||
return output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters