Cb-tumblebug: Bug: ListNs() returns weird values

Created on 24 Sep 2020  ยท  7Comments  ยท  Source: cloud-barista/cb-tumblebug

โฏ ./delete-all-ns.sh
####################################################################
## 0. Namespace: Delete
####################################################################
{
   "message" : "All namespaces has been deleted"
}

(There should be no namespaces.)

โฏ ./list-ns.sh | less
####################################################################
## 0. Namespace: List
####################################################################
{
   "ns" : [
      {
         "name" : "222f9394-f2b7-4c62-8024-586304b45eb3",
         "id" : "222f9394-f2b7-4c62-8024-586304b45eb3",
         "description" : ""
      },
      {
         "name" : "fe149015-ca50-4497-9cde-9ff0b3be2df2",
         "description" : "",
         "id" : "fe149015-ca50-4497-9cde-9ff0b3be2df2"
      },
      {
         "name" : "",
         "description" : "",
         "id" : "aws-us-east-1-t2.nano"
      },
      {
         "name" : "",
         "id" : "aws-us-east-1-t1.micro",
         "description" : ""
      },
      {
         "name" : "",
         "id" : "aws-us-east-1-t2.micro",
         "description" : ""
      },
      {
         "name" : "",
         "id" : "aws-us-east-1-a1.medium",
         "description" : ""
      },
      {
         "id" : "aws-us-east-1-c6g.medium",
         "description" : "",
         "name" : ""
      },
      {
         "description" : "",
         "id" : "aws-us-east-1-c6gd.medium",
         "name" : ""
      },
      {
         "id" : "aws-us-east-1-m1.small",
         "description" : "",
         "name" : ""
      },
      {
         "description" : "",
         "id" : "aws-us-east-1-t2.small",
         "name" : ""
      },
...

List Ns ํ–ˆ์„ ๋•Œ ๋‚˜์˜ค๋Š” ๊ฒƒ๋“ค

  • Spec
  • Image
  • ...
bug

Most helpful comment

@jihoon-seo @seokho-son

[utils.GetChildList() ์ถ”๊ฐ€ ๋ฐ ์‹œํ—˜ ์™„๋ฃŒ]

All 7 comments

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.98. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@jihoon-seo ์–ด๋–ค ์ƒํ™ฉ์—์„œ ๋ฒ„๊ทธ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”์ง€์š”?
๋‹ค๋ฅธ ์ €์žฅ์†Œ์˜ ์—…๋ฐ์ดํŠธ ์ƒํ™ฉ๊ณผ ์—ฐ๊ณ„๋˜์–ด ์žˆ๋‚˜์š”?

TB ์—์„œ CreateNs() ํ•จ์ˆ˜๋ฅผ ๋ถ€๋ฅด๋ฉด
Key-Value store์—

  • Key: "/ns/NS-01"
  • Val: (JSON)
{
  "id": "NS-01",
  "name": "NS-01",
  "description": "my desc"
}

์ด๋Ÿฐ ํ˜•์‹์œผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.


์ดํ›„ Image ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๋ฉด
Key-Value store์—

  • Key: "/ns/NS-01/resources/image/IMAGE-01"
  • Val: (JSON)
        {
            "connectionName": "'${CONN_CONFIG[$INDEX,$REGION]}'", 
            "name": "'${CONN_CONFIG[$INDEX,$REGION]}'-'${POSTFIX}'",
            "cspImageId": "'${IMAGE_NAME[$INDEX,$REGION]}'",
            "cspImageName": "",
            "creationDate": "",
            "description": "Canonical, Ubuntu, 18.04 LTS, amd64 bionic",
            "guestOS": "Ubuntu",
            "status": "",
            "keyValueList": [
                {
                    "Key": "",
                    "Value": ""
                },
                {
                    "Key": "",
                    "Value": ""
                }
            ]
        }

์ด๋Ÿฐ ํ˜•์‹์œผ๋กœ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.


TB ์˜ ListNs() ํ•จ์ˆ˜๋ฅผ ๋ถ€๋ฅด๋ฉด

key := "/ns"
keyValue, err := CBStore.GetList(key, true)

๋ฅผ ํ˜ธ์ถœํ•˜๋Š”๋ฐ

CBStore.GetList() ํ•จ์ˆ˜๋Š”
/ns ๋ผ๋Š” ํ‚ค์˜ ํ•˜์œ„์— ์žˆ๋Š” ๋ชจ๋“  Key-Val pair ๋ฅผ ๋ฆฌํ„ดํ•ฉ๋‹ˆ๋‹ค.

  • Key: "/ns/NS-01" ์ธ ๊ฐ์ฒด์˜ keyValue pair
  • Key: "/ns/NS-01/resources/image/IMAGE-01" ์ธ ๊ฐ์ฒด์˜ keyValue pair
  • ...

์ด๋Ÿฌํ•œ ์ด์œ ๋กœ ์œ„์™€ ๊ฐ™์€ ํ˜„์ƒ์ด ๋‚˜ํƒ€๋‚˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.


KV store ์—์„œ
ํŠน์ • ๊ณ„์œ„ (์˜ˆ: /ns) ์˜ ์ง์†ํ›„๋ฐฐ๋งŒ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋ฅผ
cb-store ์— ์ถ”๊ฐ€ ์š”์ฒญ ๋“œ๋ ธ์Šต๋‹ˆ๋‹ค.

์ด ํ•จ์ˆ˜๊ฐ€ ์™„์„ฑ๋˜๋ฉด, TB ์—์„œ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” CBStore.GetList() ํ•จ์ˆ˜ ๋ถ€๋ถ„์„
์ƒˆ ํ•จ์ˆ˜๋กœ ๋Œ€์ฒดํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

Ref: @powerkimhub

[Files and functions that using CBStore.GetList() function]

  • src/core/common/namespace.go

    • func ListNs() ([]NsInfo, error)

    • func ListNsId() []string

  • src/core/mcir/common.go

    • func ListResourceId(nsId string, resourceType string) []string

    • func ListResource(nsId string, resourceType string) (interface{}, error)

  • (obsolete) src/core/mcir/obsolete/publicip.go

    • func getPublicIpList(nsId string) []string

  • (obsolete) src/core/mcir/obsolete/subnet.go

    • func getSubnetList(nsId string) []string

  • (obsolete) src/core/mcir/obsolete/vnic.go

    • func getVNicList(nsId string) []string

  • src/core/mcis/control.go

    • func ListMcisId(nsId string) []string

    • func ListVmId(nsId string, mcisId string) ([]string, error)

    • func GetRecommendList(nsId string, cpuSize string, memSize string, diskSize string) ([]TbVmPriority, error)

func ListNsId() []string ์— ํ•ด๋‹น ๋กœ์ง์ด ์žˆ์Šต๋‹ˆ๋‹ค.
https://github.com/cloud-barista/cb-tumblebug/blob/e42e87081448772bcb459971079e1d677e18d10d/src/core/common/namespace.go#L131
๊ทธ๋Ÿฐ๋ฐ ํ•„ํ„ฐ๋ง์„ ์ˆ˜๋™์œผ๋กœ ํ•ด ์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.
(์œ„์˜ ๋งํฌ์—์„œ๋Š”

        if !strings.Contains(v.Key, "mcis") && !strings.Contains(v.Key, "cpu") && !strings.Contains(v.Key, "resources") {
            nsList = append(nsList, strings.TrimPrefix(v.Key, "/ns/"))
        }

์ด๋ ‡๊ฒŒ ํ•„ํ„ฐ๋ง ํ•˜๊ณ  ์žˆ์Œ)

[์•ˆ]

  1. cb-store ์—์„œ ์ƒˆ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์‹œ๊ธฐ๋ฅผ ๊ธฐ๋‹ค๋ฆฐ๋‹ค.
  2. func ListNsId() []string ์— ์žˆ๋Š” ๋กœ์ง์„ func ListNs() ([]NsInfo, error) ์—๋„ ๋„ฃ๋Š”๋‹ค. (๋‹ค๋ฅธ ํ•จ์ˆ˜๋“ค์—๋„ ๋งˆ์ฐฌ๊ฐ€์ง€)
  3. func ListNs() ([]NsInfo, error) ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด
    func ListNsId() []string ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ 
    ๊ทธ ๊ฒฐ๊ณผ๋กœ ๋‚˜์˜จ NsId ๋“ค์— ๋Œ€ํ•ด func GetNs(id string) (NsInfo, error) ํ•˜์—ฌ
    ์ตœ์ข…์ ์œผ๋กœ []NsInfo ๋ฅผ ๋ฆฌํ„ดํ•œ๋‹ค.
    (๋‹ค๋ฅธ ํ•จ์ˆ˜๋“ค์—๋„ ๋งˆ์ฐฌ๊ฐ€์ง€)

@jihoon-seo @seokho-son

[๊ฐœ์š”]

  • Key-Value Store๋Š” Key์™€ Value ๋‚ด๋ถ€ Semantic๋Š” ์•Œ์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค. '/'์˜ ํฌํ•จ ์—ฌ๋ถ€๋„...์˜๋ฏธ๋„...์•Œ์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค.
  • Key๋ฅผ '/'๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ path๋ฅผ ๋งŒ๋“ค์–ด ๊ด€๋ฆฌํ•˜๋Š” ๊ฑด ์‚ฌ์šฉ์ž์˜ ๋ชซ์ด๋ผ ํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

[๊ณ„ํš]

  • Key "/ns/NS-01"์—์„œ "/ns"๋Š” Key๋Š” ์•„๋‹ˆ๊ณ  Key์˜ ์ผ๋ถ€ ๋ฌธ์ž์—ด๋กœ์„œ,
  • Key-Value Store ๋‚ด๋ถ€์—์„œ ์˜๋ฏธ๋ฅผ ๋ถ€์—ฌํ•˜์—ฌ child list๋ฅผ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์€ ๋ชจํ˜ธํ•œ ์ƒํ™ฉ
  • Cloud-Barista์—์„œ๋Š” ์ž์ฃผ ์“ฐ์ผ ๋“ฏํ•˜๋‹ˆ,
  • cb-store utils์— ๋‹ค์Œ ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ ์˜ˆ์ •

    • func GetChildList(keyValueList []KeyValue, key string) ([]KeyValue)

[์‚ฌ์šฉ์˜ˆ์‹œ]

keyValueList, _ := store.GetList("/ns", true)                 //  => /ns*
targetList, _ := utils.GetChildList(keyValueList, "/ns")  // => /ns/[*]

@jihoon-seo @seokho-son

[utils.GetChildList() ์ถ”๊ฐ€ ๋ฐ ์‹œํ—˜ ์™„๋ฃŒ]

Was this page helpful?
0 / 5 - 0 ratings