Skip to content

Arktos API extension with Openstack like VM request

Yunwen Bai edited this page Mar 15, 2022 · 9 revisions

To setup the test machine:

Currently it is tested on Ubuntu 18.04.

sudo su -

wget https://raw.githubusercontent.com/CentaurusInfra/mizar/dev-next/kernelupdate.sh
chmod 744 kernelupdate.sh
./kernelupdate.sh

mkdir -p go/src/k8s.io
cd go/src/k8s.io
git clone https://github.com/CentaurusInfra/arktos.git
cd arktos

./hack/setup-dev-node.sh 
export PATH=$PATH:/usr/local/go/bin

systemctl restart containerd

Start the local cluster

root@ip-172-31-39-83:~/go/src/k8s.io/arktos# CNIPLUGIN=mizar ./hack/arktos-up.sh > up.log 2>&1 &
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# kubectl get nodes
NAME              STATUS   ROLES    AGE   VERSION
ip-172-31-3-159   Ready    <none>   12m   v0.9.0

Test the new APIs with a few sample input requests

root@ip-172-31-39-83:~/go/src/k8s.io/arktos# kubectl get pods -AT
TENANT   NAMESPACE     NAME                               HASHKEY               READY   STATUS    RESTARTS   AGE
system   default       mizar-daemon-p4wbw                 2608452280564570750   1/1     Running   0          15m
system   default       mizar-operator-5c97f7478d-hg8kd    7677007499942773595   1/1     Running   0          15m
system   kube-system   coredns-default-5b4f9674cf-2dbfv   3126664299402957532   1/1     Running   0          15m
system   kube-system   kube-dns-554c5866fc-7xsjh          7227700435512906259   3/3     Running   0          15m
system   kube-system   virtlet-8lzfv                      1269981622409187876   3/3     Running   0          14m
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -k -XPOST -H "Content-Type: application/json" -H "User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/$Format" -H "Accept: application/json" -H "openstack: true" 'http://localhost:8080/servers' -d @test/e2e/arktos/testvm.json -v | jq
Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /servers HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 775
> 
} [775 bytes data]
* upload completely sent off: 775 out of 775 bytes
< HTTP/1.1 307 Temporary Redirect
< Cache-Control: no-cache, private
< Location: /api/v1/tenants/system/namespaces/kube-system/pods
< Date: Wed, 09 Mar 2022 00:51:38 GMT
< Content-Length: 0
< 
100   775    0     0  100   775      0   756k --:--:-- --:--:-- --:--:--  756k
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:8080/api/v1/tenants/system/namespaces/kube-system/pods'
* Found bundle for host localhost: 0x55926813f8d0 [can pipeline]
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /api/v1/tenants/system/namespaces/kube-system/pods HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 775
> 
} [775 bytes data]
* upload completely sent off: 775 out of 775 bytes
< HTTP/1.1 201 Created
< Cache-Control: no-cache, private
< Content-Type: application/json
< Date: Wed, 09 Mar 2022 00:51:38 GMT
< Content-Length: 255
< 
{ [255 bytes data]
100  1030  100   255  100   775  31875  96875 --:--:-- --:--:-- --:--:--  125k
* Connection #0 to host localhost left intact
{
  "id": "testvm",
  "links": [
    {
      "Link": "/servers/testvm",
      "Rel": ""
    }
  ],
  "flavor": {
    "memoryMb": 512,
    "vcpus": 1
  },
  "image": {
    "name": "download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.img"
  },
  "status": "statusUnknown",
  "tenant": "system",
  "os_ext_sts_power_state": "nosate"
}
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -k -H "Content-Type: application/json" -H "User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/$Format" -H "Accept: application/json" -H "openstack: true" 'http://localhost:8080/servers' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   118  100   118    0     0   115k      0 --:--:-- --:--:-- --:--:--  115k
100    76  100    76    0     0  19000      0 --:--:-- --:--:-- --:--:-- 19000
{
  "Servers": [
    {
      "id": "testvm",
      "links": [
        {
          "Link": "/servers/testvm",
          "Rel": ""
        }
      ]
    }
  ]
}
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -k -H "Content-Type: application/json" -H "User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/$Format" -H "Accept: application/json" -H "openstack: true" 'http://localhost:8080/servers/testvm' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   125  100   125    0     0   122k      0 --:--:-- --:--:-- --:--:--  122k
100   391  100   391    0     0   127k      0 --:--:-- --:--:-- --:--:--  127k
{
  "id": "testvm",
  "links": [
    {
      "Link": "/servers/testvm",
      "Rel": ""
    }
  ],
  "flavor": {
    "memoryMb": 512,
    "vcpus": 1
  },
  "image": {
    "name": "download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.img"
  },
  "status": "active",
  "tenant": "system",
  "createdAt": "2022-03-09 00:51:38 +0000 UTC",
  "accessIpv4": "252.67.0.9",
  "os_ext_sts_power_state": "running",
  "vpc": "system-default-network",
  "subnet": "system-default-network-subnet"
}
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -k -XPOST -H "Content-Type: application/json" -H "User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/$Format" -H "Accept: application/json" -H "openstack: true" 'http://localhost:8080/servers' -d @test/e2e/arktos/testvm-batch.json -v | jq
Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /servers HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 275
> 
} [275 bytes data]
* upload completely sent off: 275 out of 275 bytes
< HTTP/1.1 307 Temporary Redirect
< Cache-Control: no-cache, private
< Location: /apis/apps/v1/tenants/system/namespaces/kube-system/replicasets
< Date: Wed, 09 Mar 2022 00:53:18 GMT
< Content-Length: 0
< 
100   275    0     0  100   275      0   268k --:--:-- --:--:-- --:--:--  268k
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:8080/apis/apps/v1/tenants/system/namespaces/kube-system/replicasets'
* Found bundle for host localhost: 0x55ef6d7f2980 [can pipeline]
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /apis/apps/v1/tenants/system/namespaces/kube-system/replicasets HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 275
> 
} [275 bytes data]
* upload completely sent off: 275 out of 275 bytes
< HTTP/1.1 201 Created
< Cache-Control: no-cache, private
< Content-Type: application/json
< Date: Wed, 09 Mar 2022 00:53:18 GMT
< Content-Length: 28
< 
{ [28 bytes data]
100   303  100    28  100   275   4666  45833 --:--:-- --:--:-- --:--:-- 50499
* Connection #0 to host localhost left intact
{
  "reservation_id": "testvm"
}
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -k -XGET -H "Content-Type: application/json" -H "User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/$Format" -H "Accept: application/json" -H "openstack: true" 'http://localhost:8080/servers' -d @test/e2e/arktos/testvm-list.json -v | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /servers HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 29
> 
} [29 bytes data]
* upload completely sent off: 29 out of 29 bytes
< HTTP/1.1 307 Temporary Redirect
< Cache-Control: no-cache, private
< Content-Type: text/html; charset=utf-8
< Location: /api/v1/tenants/system/namespaces/kube-system/pods?labelSelector=openstsckApi=true,ln=testvm
< Date: Wed, 09 Mar 2022 00:53:27 GMT
< Content-Length: 128
< 
* Ignoring the response-body
{ [128 bytes data]
100   157  100   128  100    29   125k  29000 --:--:-- --:--:-- --:--:--  153k
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:8080/api/v1/tenants/system/namespaces/kube-system/pods?labelSelector=openstsckApi=true,ln=testvm'
* Found bundle for host localhost: 0x5604e2de5ae0 [can pipeline]
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /api/v1/tenants/system/namespaces/kube-system/pods?labelSelector=openstsckApi=true,ln=testvm HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 29
> 
} [29 bytes data]
* upload completely sent off: 29 out of 29 bytes
< HTTP/1.1 200 OK
< Cache-Control: no-cache, private
< Content-Type: application/json
< Date: Wed, 09 Mar 2022 00:53:27 GMT
< Content-Length: 236
< 
{ [236 bytes data]
100   265  100   236  100    29  47200   5800 --:--:-- --:--:-- --:--:-- 53000
* Connection #0 to host localhost left intact
{
  "Servers": [
    {
      "id": "testvm-245gd",
      "links": [
        {
          "Link": "/servers/testvm-245gd",
          "Rel": ""
        }
      ]
    },
    {
      "id": "testvm-555tz",
      "links": [
        {
          "Link": "/servers/testvm-555tz",
          "Rel": ""
        }
      ]
    },
    {
      "id": "testvm-r5b26",
      "links": [
        {
          "Link": "/servers/testvm-r5b26",
          "Rel": ""
        }
      ]
    }
  ]
}
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -k -XPOST -H "Content-Type: application/json" -H "User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/$Format" -H "Accept: application/json" -H "openstack: true" 'http://localhost:8080/servers/testvm/action' -d @test/e2e/arktos/reboot.json -v | jq
Note: Unnecessary use of -X or --request, POST is already inferred.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /servers/testvm/action HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 46
> 
} [46 bytes data]
* upload completely sent off: 46 out of 46 bytes
< HTTP/1.1 307 Temporary Redirect
< Cache-Control: no-cache, private
< Location: /api/v1/tenants/system/namespaces/kube-system/pods/testvm/action
< Date: Wed, 09 Mar 2022 00:53:40 GMT
< Content-Length: 0
< 
100    46    0     0  100    46      0  46000 --:--:-- --:--:-- --:--:-- 46000
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost:8080/api/v1/tenants/system/namespaces/kube-system/pods/testvm/action'
* Found bundle for host localhost: 0x55b725921ae0 [can pipeline]
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /api/v1/tenants/system/namespaces/kube-system/pods/testvm/action HTTP/1.1
> Host: localhost:8080
> Content-Type: application/json
> User-Agent: kubectl/v0.9.0 (linux/amd64) kubernetes/
> Accept: application/json
> openstack: true
> Content-Length: 46
> 
} [46 bytes data]
* upload completely sent off: 46 out of 46 bytes
< HTTP/1.1 201 Created
< Cache-Control: no-cache, private
< Date: Wed, 09 Mar 2022 00:53:40 GMT
< Content-Length: 0
< 
100    46    0     0  100    46      0   5750 --:--:-- --:--:-- --:--:--  5750
* Connection #0 to host localhost left intact
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# 
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# kubectl get pods  -AT
TENANT   NAMESPACE     NAME                               HASHKEY               READY   STATUS    RESTARTS   AGE
system   default       mizar-daemon-p4wbw                 2608452280564570750   1/1     Running   0          18m
system   default       mizar-operator-5c97f7478d-hg8kd    7677007499942773595   1/1     Running   0          18m
system   kube-system   coredns-default-5b4f9674cf-2dbfv   3126664299402957532   1/1     Running   0          18m
system   kube-system   kube-dns-554c5866fc-7xsjh          7227700435512906259   3/3     Running   0          18m
system   kube-system   testvm                             1340386839546996352   1/1     Running   1          2m15s
system   kube-system   testvm-245gd                       4262490064148653013   1/1     Running   0          35s
system   kube-system   testvm-555tz                       6139486331874778472   1/1     Running   0          35s
system   kube-system   testvm-r5b26                       1971958923336370202   1/1     Running   0          35s
system   kube-system   virtlet-8lzfv                      1269981622409187876   3/3     Running   0          17m
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# curl -L -XDELETE -H "openstack: true" http://localhost:8080/servers/testvm | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100   488  100   488    0     0  97600      0 --:--:-- --:--:-- --:--:-- 97600
{
  "id": "testvm",
  "links": [
    {
      "Link": "/servers/testvm",
      "Rel": ""
    }
  ],
  "flavor": {
    "memoryMb": 512,
    "vcpus": 1
  },
  "image": {
    "name": "download.cirros-cloud.net/0.5.1/cirros-0.5.1-x86_64-disk.img"
  },
  "status": "active",
  "tenant": "system",
  "createdAt": "2022-03-09 00:51:38 +0000 UTC",
  "accessIpv4": "252.67.0.9",
  "os_ext_sts_power_state": "running",
  "vpc": "system-default-network",
  "subnet": "system-default-network-subnet"
}
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# 
root@ip-172-31-39-83:~/go/src/k8s.io/arktos# kubectl get pods  -AT
TENANT   NAMESPACE     NAME                               HASHKEY               READY   STATUS    RESTARTS   AGE
system   default       mizar-daemon-p4wbw                 2608452280564570750   1/1     Running   0          18m
system   default       mizar-operator-5c97f7478d-hg8kd    7677007499942773595   1/1     Running   0          18m
system   kube-system   coredns-default-5b4f9674cf-2dbfv   3126664299402957532   1/1     Running   0          18m
system   kube-system   kube-dns-554c5866fc-7xsjh          7227700435512906259   3/3     Running   0          18m
system   kube-system   testvm-245gd                       4262490064148653013   1/1     Running   0          63s
system   kube-system   testvm-555tz                       6139486331874778472   1/1     Running   0          63s
system   kube-system   testvm-r5b26                       1971958923336370202   1/1     Running   0          63s
system   kube-system   virtlet-8lzfv                      1269981622409187876   3/3     Running   0          17m
root@ip-172-31-39-83:~/go/src/k8s.io/arktos#