Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Github work flow to deploy configs #892

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
73 changes: 73 additions & 0 deletions .github/workflows/build_openyurt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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:
build_openyurt:
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: Show scripts help info
run:
./scripts/openyurt-deployer/oy_deploy help

- name: Allow root login
run: |
echo "PermitRootLogin=yes" | sudo tee -a /etc/ssh/sshd_config

- name: Set up SSH and run deploy
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
./oy_deploy deploy
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=
Binary file added scripts/openyurt-deployer/.DS_Store
Binary file not shown.
120 changes: 120 additions & 0 deletions scripts/openyurt-deployer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Quick set-up `OpenYurt`

## 1. Introduction

This program extends [`EasyOpenyurt`](https://github.com/flyinghorse0510/easy_openyurt) to automate the set up process of an `OpenYurt` cluster.

It support setting up a Kubernetes cluster using kubeadm and then deploy `OpenYurt` and Knative on it. It is compatible with vHive stock-only mode.

## 2. Brief overview

**Prerequisite of nodes:**
1. The scripts has been tested on [cloud-lab](https://www.cloudlab.us/), suggested profile is: [`openyurt-demo`](https://www.cloudlab.us/p/ntu-cloud/openyurt-demo), with one master node, one cloud worker node and one edge worker node
2. Ensure that SSH authentication is possible from local device to all nodes.


**Components:**

| Files | Purpose |
| :----------: | :---: |
| main.go | script entry point |
| `conf.json` | json files that stores cluster's configuration |
| node | executing commands on remote nodes through ssh |
| configs | node runtime configurations |

**Description**

1. Prepare system environment for all nodes, installing kubeadm, kubectl, dependencies, etc.
2. On master node, init the cluster using `kubeadm init` and in each worker node, join the initialized cluster.
3. On top of the created cluster, init `openyurt` cluster both on master nodes and worker nodes, then expand to all worker nodes from master nodes.
4. (Optional) Deploy Knative (vHive stock-only mode compatible)

## 3. Usage
```bash
./openyurt_deployer deploy # deploy openyurt on the cluster
```
```bash
./openyurt_deployer clean # clean the openyurt cluster and restore it to initial state
```

### 3.1 Preparations
1. Prepare a cluster with at least two nodes.
2. Change the contents in `conf.json` to following format:
```plaintext
{
"master": "user@master",
"workers": {
"cloud": [
"user@cloud-0"
],
"edge": [
"user@edge-0"
]
}
}
```

### 3.2 Run Script

```bash
go build .
./openyurt_deployer deploy
```
If it gives out error like:
```
FATA[0001] Failed to connect to: username@host
```
Please execute:
```
eval `ssh-agent -s` && ssh-add ~/.ssh/<your private key>
```
For example:
```
eval `ssh-agent -s` && ssh-add ~/.ssh/id_rsa
```
And try again


## 4. Demo: Create `NodePool` And Deploy service on it
**Referenced from [`OpenYurt`](https://openyurt.io/docs/user-manuals/workload/node-pool-management)*

The demo would deploy a helloworld function to cloud node pool or edge node pool

Deploy the demo:
```
./openyurt_deployer demo-c
```
or:
```
./openyurt_deployer demo-e
```
where `demo-c` would deploy the service to the cloud node pool and `demo-e` would deploy the service to the edge node pool.

The demo code will also show information about node pool after deployment.
The name for `demo-c` would be `helloworld-cloud`, while the name for `demo-e` would be `helloworld-edge`
It will also show the services' `URL` so you can try to invoke it on the master node.

You can check the nodepool information simply by:
```
./openyurt_deployer demo-print
```
Or delete the services deployed on nodepool by:
```
./openyurt_deployer demo-clear
```

The demo code will also show information about node pool after deployment.

### 4.1 Invoke the Services (Optional)
You can try to invoke the services created by `demo-c` or `demo-e` on master node.
First, ssh to master node, following commands should all be executed on master node.
```
ssh <master-user>@<master-ip>
git clone https://github.com/vhive-serverless/vSwarm.git
cd vSwarm/tools/test-client && go build .
./test-client --addr $URL:80 --name "Hello there"
```

Here `$URL` should be the `URL` returned in the previous part when deploying cloud and edge services, you can also get it from: `kubectl get ksvc`, but discarding the `http://` at the beginning.

After invoking, you can use `kubectl get pods -o wide` to check whether the pods have been auto-scaled.
9 changes: 9 additions & 0 deletions scripts/openyurt-deployer/conf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"master": "[email protected]",
"workers": {
"cloud": [
],
"edge": [
]
}
}
80 changes: 80 additions & 0 deletions scripts/openyurt-deployer/configs/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package configs

import (
"encoding/json"
"io"
"os"
"path"
)

// Decode specific config files (JSON format)
func DecodeConfig(configFilePath string, configStruct interface{}) error {
// Open & read the config file
configFile, err := os.Open(configFilePath)
if err != nil {
return err
}
defer configFile.Close()

// Read file content
configContent, err := io.ReadAll(configFile)
if err != nil {
return err
}

// Decode json into struct
err = json.Unmarshal(configContent, configStruct)

return err

}

// Load knative config files
func (knative *KnativeConfigStruct) LoadConfig() error {
// Get the (absolute) path of the config file
configFilePath := path.Join(VHive.VHiveSetupConfigPath, "knative.json")

// Decode json into struct
err := DecodeConfig(configFilePath, knative)

return err

}

// Load kubernetes config files
func (kube *KubeConfigStruct) LoadConfig() error {
// Get the (absolute) path of the config file
configFilePath := path.Join(VHive.VHiveSetupConfigPath, "kube.json")

// Decode json into struct
err := DecodeConfig(configFilePath, kube)

return err
}

// Load system config files
func (system *SystemEnvironmentStruct) LoadConfig() error {
// Get the (absolute) path of the config file
configFilePath := path.Join(VHive.VHiveSetupConfigPath, "system.json")

// Decode json into struct
err := DecodeConfig(configFilePath, system)

return err
}

// Load vHive config files
func (vhive *VHiveConfigStruct) LoadConfig() error {
// Get the (absolute) path of the config file
configFilePath := path.Join(VHive.VHiveSetupConfigPath, "vhive.json")

// Decode json into struct
err := DecodeConfig(configFilePath, vhive)

return err

}

const (
Version = "0.2.4b" // Version Info
)
21 changes: 21 additions & 0 deletions scripts/openyurt-deployer/configs/demo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package configs

type DemoEnvironment struct {
CloudYamlFile string
EdgeYamlFile string
CloudBenchYamlFile string
EdgeBenchYamlFile string
YurtAppSetYamlFile string
CloudPoolName string
EdgePoolName string
}

var Demo = DemoEnvironment{
CloudYamlFile: "cloud.yaml",
EdgeYamlFile: "edge.yaml",
CloudBenchYamlFile: "cloud-bench.yaml",
EdgeBenchYamlFile: "edge-bench.yaml",
YurtAppSetYamlFile: "yurt.yaml",
CloudPoolName: "cloud",
EdgePoolName: "edge",
}
3 changes: 3 additions & 0 deletions scripts/openyurt-deployer/configs/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/vhive-serverless/vhive/scripts/openyurt_deployer/configs

go 1.20
35 changes: 35 additions & 0 deletions scripts/openyurt-deployer/configs/knative.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package configs

import "fmt"

type KnativeConfigStruct struct {
KnativeVersion string
IstioVersion string
IstioDownloadUrlTemplate string
IstioOperatorConfigUrl string
MetalLBVersion string
MetalLBConfigURLArray []string
LocalRegistryRepoVolumeSize string
LocalRegistryVolumeConfigUrl string
LocalRegistryDockerRegistryConfigUrl string
LocalRegistryHostUpdateConfigUrl string
MagicDNSConfigUrl string
VHiveMode bool
}

var Knative = KnativeConfigStruct{
IstioOperatorConfigUrl: "https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/istio/istio-minimal-operator.yaml",
IstioDownloadUrlTemplate: "https://github.com/istio/istio/releases/download/%s/istio-%s-linux-%s.tar.gz",
MetalLBConfigURLArray: []string{
"https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/metallb/metallb-ipaddresspool.yaml",
"https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/metallb/metallb-l2advertisement.yaml"},
LocalRegistryVolumeConfigUrl: "https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/registry/repository-volume.yaml",
LocalRegistryDockerRegistryConfigUrl: "https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/registry/docker-registry.yaml",
LocalRegistryHostUpdateConfigUrl: "https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/registry/repository-update-hosts.yaml", //TODO: uses path
MagicDNSConfigUrl: "https://raw.githubusercontent.com/vhive-serverless/vHive/main/configs/knative_yamls/serving-default-domain.yaml", //TODO: uses path
VHiveMode: true,
}

func (knative *KnativeConfigStruct) GetIstioDownloadUrl() string {
return fmt.Sprintf(knative.IstioDownloadUrlTemplate, knative.IstioVersion, knative.IstioVersion, System.CurrentArch)
}
Loading