Skip to content

Commit

Permalink
optimize cloud install.sh;
Browse files Browse the repository at this point in the history
add account gift support float ratios;
default price is reduced to 30%.
  • Loading branch information
bxy4543 committed Oct 24, 2023
1 parent a4adbb7 commit e7596ed
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
7 changes: 4 additions & 3 deletions controllers/account/controllers/account_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"math"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -473,21 +474,21 @@ func giveGift(amount int64, configMap *corev1.ConfigMap) (int64, error) {
stepsStr := strings.Split(configMap.Data["steps"], ",")
ratiosStr := strings.Split(configMap.Data["ratios"], ",")

var ratio int64
var ratio float64

for i, stepStr := range stepsStr {
step, err := strconv.ParseInt(stepStr, 10, 64)
if err != nil {
return amount, fmt.Errorf("steps format error :%s", err)
}
if amount >= step*BaseUnit {
ratio, err = strconv.ParseInt(ratiosStr[i], 10, 64)
ratio, err = strconv.ParseFloat(ratiosStr[i], 32)
if err != nil {
return amount, fmt.Errorf("ratios format error :%s", err)
}
} else {
break
}
}
return amount*ratio/100 + amount, nil
return int64(math.Ceil(float64(amount)*ratio/100)) + amount, nil
}
2 changes: 1 addition & 1 deletion controllers/account/controllers/account_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Test_giveGift(t *testing.T) {
configMap := &corev1.ConfigMap{}
configMap.Data = make(map[string]string)
configMap.Data["steps"] = "299,599,1999,4999,19999"
configMap.Data["ratios"] = "10,15,20,25,30"
configMap.Data["ratios"] = "10.0,15.0,20.0,25.0,30.0"

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
27 changes: 15 additions & 12 deletions controllers/pkg/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,27 @@ const (

var DefaultPropertyTypeList = []PropertyType{
{
Name: "cpu",
Enum: 0,
PriceType: AVG,
UnitPrice: 67,
Name: "cpu",
Enum: 0,
PriceType: AVG,
// raw price: 67
UnitPrice: 20,
UnitString: "1m",
},
{
Name: "memory",
Enum: 1,
PriceType: AVG,
UnitPrice: 33,
Name: "memory",
Enum: 1,
PriceType: AVG,
// raw price: 33
UnitPrice: 10,
UnitString: "1Mi",
},
{
Name: "storage",
Enum: 2,
PriceType: AVG,
UnitPrice: 2,
Name: "storage",
Enum: 2,
PriceType: AVG,
// raw price: 21
UnitPrice: 1,
UnitString: "1Mi",
},
{
Expand Down
18 changes: 10 additions & 8 deletions scripts/cloud/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,16 @@ collect_input() {
done
fi
if [[ $single != "y" ]]; then
while :; do
read -p "$(get_prompt "input_node_ips")" node_ips
if validate_ips "$node_ips"; then
break
else
get_prompt "invalid_ips"
fi
done
if [[ -z "$node_ips" ]]; then
while :; do
read -p "$(get_prompt "input_node_ips")" node_ips
if validate_ips "$node_ips"; then
break
else
get_prompt "invalid_ips"
fi
done
fi
read -p "$(get_prompt "ssh_private_key")" ssh_private_key

if [[ -z "$ssh_private_key" ]]; then
Expand Down

0 comments on commit e7596ed

Please sign in to comment.