mirror of
https://github.com/labring/sealos.git
synced 2026-09-24 15:46:19 +08:00
optimize cloud install.sh; (#4153)
add account gift support float ratios; default price is reduced to 30%.
This commit is contained in:
@@ -19,6 +19,7 @@ package controllers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -473,7 +474,7 @@ 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)
|
||||
@@ -481,7 +482,7 @@ func giveGift(amount int64, configMap *corev1.ConfigMap) (int64, error) {
|
||||
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)
|
||||
}
|
||||
@@ -489,5 +490,5 @@ func giveGift(amount int64, configMap *corev1.ConfigMap) (int64, error) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return amount*ratio/100 + amount, nil
|
||||
return int64(math.Ceil(float64(amount)*ratio/100)) + amount, nil
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user