Skip to content

Commit

Permalink
Merge pull request #1854 from sykim-etri/k8scluster-apply-changes-fro…
Browse files Browse the repository at this point in the history
…m-cb-sp-api

[k8scluster] apply changes from CB-SP API update
  • Loading branch information
seokho-son authored Oct 7, 2024
2 parents c229d9b + 63ef481 commit 591ce13
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/core/model/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ const (

var StartTime string

// Spider 2020-03-30 https://github.com/cloud-barista/cb-spider/blob/master/cloud-control-manager/cloud-driver/interfaces/resources/IId.go
// Spider 2024-10-05 https://github.com/cloud-barista/cb-spider/blob/master/cloud-control-manager/cloud-driver/interfaces/resources/IId.go
type IID struct {
NameId string // NameID by user
SystemId string // SystemID by CloudOS
NameId string `json:"NameId" validate:"required" example:"user-defined-name"`
SystemId string `json:"SystemId" validate:"required" example:"csp-defined-id"`
}

type SpiderConnectionName struct {
Expand Down
34 changes: 16 additions & 18 deletions src/core/model/k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type SpiderClusterUnregisterReqInfoWrapper struct {

// SpiderClusterReq is a wrapper struct to create JSON body of 'Create Cluster request'
type SpiderClusterReq struct {
NameSpace string // should be empty string from Tumblebug
ConnectionName string
ReqInfo SpiderClusterReqInfo
}
Expand Down Expand Up @@ -188,8 +187,7 @@ type TbChangeK8sNodeGroupAutoscaleSizeReq struct {

// SpiderChangeAutoscaleSizeRes is a wrapper struct to get JSON body of 'Change Autoscale Size' response
type SpiderChangeAutoscaleSizeRes struct {
ConnectionName string
NodeGroupInfo SpiderNodeGroupInfo
SpiderNodeGroupInfo
}

// TbChangeK8sNodeGroupAutoscaleSizeRes is a struct to handle 'Change K8sNodeGroup's Autoscale Size' response from CB-Tumblebug.
Expand Down Expand Up @@ -268,8 +266,7 @@ const (

// SpiderClusterRes is a wrapper struct to handle a Cluster information from the CB-Spider's REST API response
type SpiderClusterRes struct {
ConnectionName string
ClusterInfo SpiderClusterInfo
SpiderClusterInfo
}

// SpiderClusterInfo is a struct to handle Cluster information from the CB-Spider's REST API response
Expand Down Expand Up @@ -367,27 +364,28 @@ type TbK8sClusterNetworkInfo struct {

// SpiderNodeGroupInfo is a struct to handle Cluster Node Group information from the CB-Spider's REST API response
type SpiderNodeGroupInfo struct {
IId IID // {NameId, SystemId}
IId IID `json:"IId" validate:"required"` // {NameId, SystemId}

// VM config.
ImageIID IID
VMSpecName string
RootDiskType string // "SSD(gp2)", "Premium SSD", ...
RootDiskSize string // "", "default", "50", "1000" (GB)
KeyPairIID IID
ImageIID IID `json:"ImageIID" validate:"required"`
VMSpecName string `json:"VMSpecName" validate:"required" example:"t3.medium"`
RootDiskType string `json:"RootDiskType,omitempty" validate:"omitempty"` // "SSD(gp2)", "Premium SSD", ...
RootDiskSize string `json:"RootDiskSize,omitempty" validate:"omitempty" example:"50"` // "", "default", "50", "1000" (GB)
KeyPairIID IID `json:"KeyPairIID" validate:"required"`

// Scaling config.
OnAutoScaling bool // default: true
DesiredNodeSize int
MinNodeSize int
MaxNodeSize int
OnAutoScaling bool `json:"OnAutoScaling" validate:"required" example:"true"`
DesiredNodeSize int `json:"DesiredNodeSize" validate:"required" example:"2"`
MinNodeSize int `json:"MinNodeSize" validate:"required" example:"1"`
MaxNodeSize int `json:"MaxNodeSize" validate:"required" example:"3"`

// ---

Status SpiderNodeGroupStatus
Nodes []IID
Status SpiderNodeGroupStatus `json:"Status" validate:"required" example:"Active"`

KeyValueList []KeyValue
Nodes []IID `json:"Nodes,omitempty" validate:"omitempty"`

KeyValueList []KeyValue `json:"KeyValueList,omitempty" validate:"omitempty"`
}

// TbK8sNodeGroupInfo is a struct to handle K8sCluster's Node Group information from the CB-Tumblebug's REST API response
Expand Down
29 changes: 11 additions & 18 deletions src/core/resource/k8scluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ func CreateK8sCluster(nsId string, req *model.TbK8sClusterReq, option string) (m
uid := common.GenUid()

requestBody := model.SpiderClusterReq{
NameSpace: "", // should be empty string from Tumblebug
ConnectionName: req.ConnectionName,
ReqInfo: model.SpiderClusterReqInfo{
Name: uid,
Expand Down Expand Up @@ -267,13 +266,13 @@ func CreateK8sCluster(nsId string, req *model.TbK8sClusterReq, option string) (m
ResourceType: model.StrK8s,
Id: reqId,
Uid: uid,
CspResourceName: spClusterRes.ClusterInfo.IId.NameId,
CspResourceId: spClusterRes.ClusterInfo.IId.SystemId,
CspResourceName: spClusterRes.SpiderClusterInfo.IId.NameId,
CspResourceId: spClusterRes.SpiderClusterInfo.IId.SystemId,
Name: reqId,
ConnectionName: req.ConnectionName,
ConnectionConfig: connectionConfig,
Description: req.Description,
CspViewK8sClusterDetail: spClusterRes.ClusterInfo,
CspViewK8sClusterDetail: spClusterRes.SpiderClusterInfo,
}

if option == "register" && req.CspResourceId == "" {
Expand Down Expand Up @@ -429,7 +428,6 @@ func AddK8sNodeGroup(nsId string, k8sClusterId string, u *model.TbK8sNodeGroupRe
}

requestBody := model.SpiderNodeGroupReq{
NameSpace: "", // should be empty string from Tumblebug
ConnectionName: oldTbK8sCInfo.ConnectionName,
ReqInfo: model.SpiderNodeGroupReqInfo{
Name: spName,
Expand Down Expand Up @@ -484,7 +482,7 @@ func AddK8sNodeGroup(nsId string, k8sClusterId string, u *model.TbK8sNodeGroupRe
Name: oldTbK8sCInfo.Name,
ConnectionName: oldTbK8sCInfo.ConnectionName,
Description: oldTbK8sCInfo.Description,
CspViewK8sClusterDetail: spClusterRes.ClusterInfo,
CspViewK8sClusterDetail: spClusterRes.SpiderClusterInfo,
}

/*
Expand Down Expand Up @@ -775,7 +773,7 @@ func ChangeK8sNodeGroupAutoscaleSize(nsId string, k8sClusterId string, k8sNodeGr

var tbK8sCAutoscaleSizeRes model.TbChangeK8sNodeGroupAutoscaleSizeRes
tbK8sCAutoscaleSizeRes.TbK8sNodeGroupInfo = model.TbK8sNodeGroupInfo{
CspViewK8sNodeGroupDetail: spChangeAutoscaleSizeRes.NodeGroupInfo,
CspViewK8sNodeGroupDetail: spChangeAutoscaleSizeRes.SpiderNodeGroupInfo,
}

return tbK8sCAutoscaleSizeRes, nil
Expand Down Expand Up @@ -847,11 +845,9 @@ func GetK8sCluster(nsId string, k8sClusterId string) (model.TbK8sClusterInfo, er

// Create Request body for GetK8sCluster of CB-Spider
type JsonTemplate struct {
NameSpace string
ConnectionName string
}
requestBody := JsonTemplate{
NameSpace: "", // should be empty string from Tumblebug
ConnectionName: storedTbK8sCInfo.ConnectionName,
}

Expand Down Expand Up @@ -881,7 +877,7 @@ func GetK8sCluster(nsId string, k8sClusterId string) (model.TbK8sClusterInfo, er
Name: storedTbK8sCInfo.Name,
ConnectionName: storedTbK8sCInfo.ConnectionName,
Description: storedTbK8sCInfo.Description,
CspViewK8sClusterDetail: spClusterRes.ClusterInfo,
CspViewK8sClusterDetail: spClusterRes.SpiderClusterInfo,
}

/*
Expand Down Expand Up @@ -1116,7 +1112,6 @@ func DeleteK8sCluster(nsId string, k8sClusterId string, forceFlag string) (bool,

// Create Req body
type JsonTemplate struct {
NameSpace string
ConnectionName string
}
requestBody := JsonTemplate{}
Expand All @@ -1128,7 +1123,6 @@ func DeleteK8sCluster(nsId string, k8sClusterId string, forceFlag string) (bool,
return false, err
}

requestBody.NameSpace = "" // should be empty string from Tumblebug
requestBody.ConnectionName = tbK8sCInfo.ConnectionName

client := resty.New()
Expand Down Expand Up @@ -1290,7 +1284,6 @@ func UpgradeK8sCluster(nsId string, k8sClusterId string, u *model.TbUpgradeK8sCl
spVersion := u.Version

requestBody := model.SpiderUpgradeClusterReq{
NameSpace: "", // should be empty string from Tumblebug
ConnectionName: oldTbK8sCInfo.ConnectionName,
ReqInfo: model.SpiderUpgradeClusterReqInfo{
Version: spVersion,
Expand Down Expand Up @@ -1331,7 +1324,7 @@ func UpgradeK8sCluster(nsId string, k8sClusterId string, u *model.TbUpgradeK8sCl
Name: oldTbK8sCInfo.Name,
ConnectionName: oldTbK8sCInfo.ConnectionName,
Description: oldTbK8sCInfo.Description,
CspViewK8sClusterDetail: spClusterRes.ClusterInfo,
CspViewK8sClusterDetail: spClusterRes.SpiderClusterInfo,
}

/*
Expand Down Expand Up @@ -1392,8 +1385,8 @@ func convertSpiderNetworkInfoToTbK8sClusterNetworkInfo(spNetworkInfo model.Spide
func convertSpiderNodeGroupInfoToTbK8sNodeGroupInfo(spNodeGroupInfo *model.SpiderNodeGroupInfo) model.TbK8sNodeGroupInfo {
tbNodeId := spNodeGroupInfo.IId.SystemId
tbCspImageName := spNodeGroupInfo.ImageIID.SystemId
tbCspSpecName := spNodeGroupInfo.VMSpecName
tbImageId := spNodeGroupInfo.ImageIID.SystemId
tbSpecId := spNodeGroupInfo.VMSpecName
tbRootDiskType := spNodeGroupInfo.RootDiskType
tbRootDiskSize := spNodeGroupInfo.RootDiskSize
tbSshKeyId := spNodeGroupInfo.KeyPairIID.SystemId
Expand All @@ -1411,8 +1404,8 @@ func convertSpiderNodeGroupInfoToTbK8sNodeGroupInfo(spNodeGroupInfo *model.Spide
tbKeyValueList := convertSpiderKeyValueListToTbKeyValueList(spNodeGroupInfo.KeyValueList)
tbK8sNodeGroupInfo := model.TbK8sNodeGroupInfo{
Id: tbNodeId,
CspImageName: tbCspImageName,
CspSpecName: tbCspSpecName,
ImageId: tbImageId,
SpecId: tbSpecId,
RootDiskType: tbRootDiskType,
RootDiskSize: tbRootDiskSize,
SshKeyId: tbSshKeyId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ echo "MaxNodeSize=${MaxNodeSize}"
echo "K8SCLUSTERID=${K8SCLUSTERID}"
echo "===================================================================="

resp=$(
curl -H "${AUTH}" -sX PUT http://$TumblebugServer/tumblebug/ns/$NSID/k8scluster/${K8SCLUSTERID}/k8snodegroup/${K8SNODEGROUPNAME}/autoscalesize -H 'Content-Type: application/json' -d @- <<EOF
req=$(cat << EOF
{
"desiredNodeSize": "${DesiredNodeSize}",
"minNodeSize": "${MinNodeSize}",
"maxNodeSize": "${MaxNodeSize}"
}
EOF
); echo ${req} | jq ''


resp=$(
curl -H "${AUTH}" -sX PUT http://$TumblebugServer/tumblebug/ns/$NSID/k8scluster/${K8SCLUSTERID}/k8snodegroup/${K8SNODEGROUPNAME}/autoscalesize -H 'Content-Type: application/json' -d @- <<EOF
${req}
EOF
); echo ${resp} | jq ''
echo ""
Expand Down

0 comments on commit 591ce13

Please sign in to comment.