Skip to content

Commit

Permalink
Merge pull request #1196 from yunkon-kim/simplify-nlb-option-setup
Browse files Browse the repository at this point in the history
Set NLB health checker info by reflection
  • Loading branch information
seokho-son authored Oct 13, 2022
2 parents 085d8ef + ac47dca commit d26a642
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions src/core/mcis/nlb.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"encoding/json"
"fmt"
"os"
"reflect"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -370,44 +371,19 @@ func CreateNLB(nsId string, mcisId string, u *TbNLBReq, option string) (TbNLBInf

cloudType := connConfig.ProviderName

valuesFromYaml := TbNLBHealthCheckerInfo{}
// Convert cloud type to field name (e.g., AWS to Aws, OPENSTACK to Openstack)
lowercase := strings.ToLower(cloudType)
fieldName := strings.ToUpper(string(lowercase[0])) + lowercase[1:]

switch cloudType {
case "AWS":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Aws.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Aws.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Aws.Nlb.Threshold)
case "AZURE":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Azure.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Azure.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Azure.Nlb.Threshold)
case "GCP":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Gcp.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Gcp.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Gcp.Nlb.Threshold)
case "ALIBABA":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Alibaba.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Alibaba.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Alibaba.Nlb.Threshold)
case "TENCENT":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Tencent.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Tencent.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Tencent.Nlb.Threshold)
case "IBM":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Ibm.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Ibm.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Ibm.Nlb.Threshold)
case "OPENSTACK":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Openstack.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Openstack.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Openstack.Nlb.Threshold)
case "CLOUDIT":
valuesFromYaml.Interval, _ = strconv.Atoi(common.RuntimeConf.Cloud.Cloudit.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(common.RuntimeConf.Cloud.Cloudit.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(common.RuntimeConf.Cloud.Cloudit.Nlb.Threshold)
default:
// Get cloud setting with field name
cloudSetting := reflect.ValueOf(&common.RuntimeConf.Cloud).Elem().FieldByName(fieldName).Interface().(common.CloudSetting)

// Set nlb health checker info
valuesFromYaml := TbNLBHealthCheckerInfo{}
valuesFromYaml.Interval, _ = strconv.Atoi(cloudSetting.Nlb.Interval)
valuesFromYaml.Timeout, _ = strconv.Atoi(cloudSetting.Nlb.Timeout)
valuesFromYaml.Threshold, _ = strconv.Atoi(cloudSetting.Nlb.Threshold)

}

if u.HealthChecker.Interval == "default" || u.HealthChecker.Interval == "" {
tempReq.ReqInfo.HealthChecker.Interval = strconv.Itoa(valuesFromYaml.Interval)
Expand Down

0 comments on commit d26a642

Please sign in to comment.