Skip to content

Commit

Permalink
Add unit test for functions in openyurt
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Chua<[email protected]>
  • Loading branch information
jchua99 committed Dec 20, 2023
1 parent 5e29798 commit bfc5145
Show file tree
Hide file tree
Showing 18 changed files with 674 additions and 83 deletions.
119 changes: 119 additions & 0 deletions .github/workflows/openyurt-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
name: Build and Test OpenYurt Deployer

on:
push:
branches: [ main, legacy-firecracker-v0.24.0-with-upf-support ]
paths-ignore:
- 'docs/**'
- '**.md'
pull_request:
branches: [ main, legacy-firecracker-v0.24.0-with-upf-support, openyurt ]
paths-ignore:
- 'docs/**'
- '**.md'
workflow_dispatch:

env:
GOOS: linux
GO111MODULE: on

jobs:
main-unit-test:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.19
uses: actions/setup-go@v4
with:
go-version: '1.19'

- name: Check out the code
uses: actions/checkout@v4

- name: Build scripts
run:
pushd scripts/openyurt-deployer && go build -o oy_deploy && popd

- name: Allow root login
run: |
echo "PermitRootLogin=yes" | sudo tee -a /etc/ssh/sshd_config
- name: Set up SSH and Run Test
run: |
echo $USER
sudo apt-get update
sudo apt-get install -y openssh-server
sudo service ssh start
eval "$(ssh-agent -s)"
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
cat > ~/.ssh/config <<EOF
Host host.example
User $USER
HostName 127.0.0.1
IdentityFile ~/.ssh/id_rsa
EOF
echo -n '' | cat - ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
sudo service ssh restart
service ssh status
ssh-add ~/.ssh/id_rsa

cat ~/.ssh/authorized_keys
chmod og-rw ~/.ssh

cd scripts/openyurt-deployer
go test

node-unit-test:
runs-on: ubuntu-latest

steps:
- name: Set up Go 1.19
uses: actions/setup-go@v4
with:
go-version: '1.19'

- name: Check out the code
uses: actions/checkout@v4

- name: Build scripts
run:
pushd scripts/openyurt-deployer && go build -o oy_deploy && popd

- name: Allow root login
run: |
echo "PermitRootLogin=yes" | sudo tee -a /etc/ssh/sshd_config
- name: Set up SSH and Run Test
run: |
echo $USER
sudo apt-get update
sudo apt-get install -y openssh-server
sudo service ssh start
eval "$(ssh-agent -s)"
ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -N ""
cat > ~/.ssh/config <<EOF
Host host.example
User $USER
HostName 127.0.0.1
IdentityFile ~/.ssh/id_rsa
EOF
echo -n '' | cat - ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys
sudo service ssh restart
service ssh status
ssh-add ~/.ssh/id_rsa

cat ~/.ssh/authorized_keys
chmod og-rw ~/.ssh

cd scripts/openyurt-deployer/node
go test
3 changes: 3 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
10 changes: 10 additions & 0 deletions scripts/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
module github.com/vhive-serverless/vHive/scripts

go 1.19

require github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485

require (
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/pkg/sftp v1.13.4 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
)
26 changes: 26 additions & 0 deletions scripts/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/pkg/sftp v1.13.4 h1:Lb0RYJCmgUcBgZosfoi9Y9sbl6+LJgOIgk/2Y4YjMFg=
github.com/pkg/sftp v1.13.4/go.mod h1:LzqnAvaD5TWeNBsZpfKxSYn1MbjWwOsCIAFFJbpIsK8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485 h1:ZMBZ2DKX1sScUSo9ZUwGI7jCMukslPNQNfZaw9vVyfY=
github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485/go.mod h1:9qeq2P58+4+LyuncL3waJDG+giOfXgowfrRZZF9XdWk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 h1:kUhD7nTDoI3fVd9G4ORWrbV5NY0liEs/Jg2pv5f+bBA=
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 11 additions & 1 deletion scripts/openyurt-deployer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ It support setting up a Kubernetes cluster using kubeadm and then deploy `OpenYu

### 3.2 Run Script

#### 3.2.1 To set up Kubernetes and Kube cluster
```bash
go build .
./openyurt_deployer deploy
./openyurt_deployer kube
```
If it gives out error like:
```
Expand All @@ -74,6 +75,15 @@ eval `ssh-agent -s` && ssh-add ~/.ssh/id_rsa
```
And try again

#### 3.2.2 To set up Knative
```bash
./openyurt_deployer knative
```

#### 3.2.2 To set up Openyurt
```bash
./openyurt_deployer openyurt
```

## 4. Demo: Create `NodePool` And Deploy service on it
**Referenced from [`OpenYurt`](https://openyurt.io/docs/user-manuals/workload/node-pool-management)*
Expand Down
6 changes: 5 additions & 1 deletion scripts/openyurt-deployer/configs/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module github.com/vhive-serverless/vhive/scripts/openyurt_deployer/configs

go 1.20
go 1.20

require github.com/vhive-serverless/vHive/scripts/utils v0.0.0-20231018022901-6a0c478d2c9f

require github.com/vhive-serverless/vHive/scripts/configs v0.0.0-20231018022901-6a0c478d2c9f // indirect
9 changes: 6 additions & 3 deletions scripts/openyurt-deployer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ module github.com/vhive-serverless/vhive/scripts/openyurt_deployer

go 1.20

require (
github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485
github.com/sirupsen/logrus v1.9.3
github.com/vhive-serverless/vHive/scripts/utils v0.0.0-20231018022901-6a0c478d2c9f
)

require (
github.com/davidmz/go-pageant v1.0.2 // indirect
github.com/kr/fs v0.1.0 // indirect
github.com/pkg/sftp v1.13.4 // indirect
github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/vhive-serverless/vHive/scripts/configs v0.0.0-20231018022901-6a0c478d2c9f // indirect
github.com/vhive-serverless/vHive/scripts/utils v0.0.0-20231018022901-6a0c478d2c9f // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
)
7 changes: 5 additions & 2 deletions scripts/openyurt-deployer/go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/pkg/sftp v1.13.4 h1:Lb0RYJCmgUcBgZosfoi9Y9sbl6+LJgOIgk/2Y4YjMFg=
github.com/pkg/sftp v1.13.4/go.mod h1:LzqnAvaD5TWeNBsZpfKxSYn1MbjWwOsCIAFFJbpIsK8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485 h1:ZMBZ2DKX1sScUSo9ZUwGI7jCMukslPNQNfZaw9vVyfY=
github.com/sfreiberg/simplessh v0.0.0-20220719182921-185eafd40485/go.mod h1:9qeq2P58+4+LyuncL3waJDG+giOfXgowfrRZZF9XdWk=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/vhive-serverless/vHive/scripts/configs v0.0.0-20231018022901-6a0c478d2c9f h1:2Cyd5RJaZ0Pdyk7Az338/PKeofj7RLZjD5rSAO+wqvk=
github.com/vhive-serverless/vHive/scripts/configs v0.0.0-20231018022901-6a0c478d2c9f/go.mod h1:nJSon4Eng7PdZ4HJX9dnZ7H4qxVm/r5zseFPfom7Jto=
Expand All @@ -24,12 +27,12 @@ golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
14 changes: 7 additions & 7 deletions scripts/openyurt-deployer/go.work
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
go 1.19
go 1.20

use(
.
./configs
./node
./template
)
use (
.
./configs
./node
./template
)
19 changes: 14 additions & 5 deletions scripts/openyurt-deployer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ func main() {
}
operation := os.Args[1]
switch operation {
case "deploy":
case "kube":
deployNodes(*deployerConf)
case "knative":
deployKnative(*deployerConf)
// case "clean":
// cleanNodes(*deployerConf)
// case "demo-e":
Expand All @@ -71,8 +73,10 @@ func main() {
// delDemo(*deployerConf)
// case "demo-print":
// printDemo(*deployerConf)
case "deploy-yurt":
case "openyurt":
deployOpenYurt(*deployerConf)
case "help":
utils.InfoPrintf("Usage: %s <operation: deploy | clean | demo-c | demo-e | demo-clear | demo-print> [Parameters...]\n", os.Args[0])
default:
utils.InfoPrintf("Usage: %s <operation: deploy | clean | demo-c | demo-e | demo-clear | demo-print> [Parameters...]\n", os.Args[0])
os.Exit(-1)
Expand Down Expand Up @@ -174,15 +178,20 @@ func deployNodes(deployerConfFile string) {
utils.InfoPrintf(name)
}
utils.InfoPrintf("]\n")
}

func deployKnative(deployerConfFile string) {

nodesInfo, err := readAndUnMarshall(deployerConfFile)
utils.CheckErrorWithMsg(err, "Failed to read and unmarshal deployer configuration JSON")
nodeList := parseNodeInfo(nodesInfo)
masterNode := nodeList[0]

// init knative
utils.SuccessPrintf("Start to init knative\n")
masterNode.InstallKnativeServing()
masterNode.InstallKnativeEventing()
utils.SuccessPrintf("Knative has been installed!\n")

// init demo environment
masterNode.BuildDemo(workerNodes)
}

func deployOpenYurt(deployerConfFile string) {
Expand Down
Loading

0 comments on commit bfc5145

Please sign in to comment.