Skip to content

Commit

Permalink
Merge pull request #57 from CloudOS-Group3/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
illyaks authored Jun 6, 2024
2 parents cccfce3 + b7087aa commit abca5ab
Show file tree
Hide file tree
Showing 171 changed files with 12,779 additions and 52 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: test all cases

on:
push:
branches: ["master", "dev", "feature/*"]

pull_request:
branches: ["master", "dev", "feature/*"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.22.2

- name: Download etcd
run: |
wget https://github.com/etcd-io/etcd/releases/download/v3.5.13/etcd-v3.5.13-linux-amd64.tar.gz
tar -zxvf etcd-v3.5.13-linux-amd64.tar.gz
cd etcd-v3.5.13-linux-amd64
./etcd &> /dev/null &
- name: Download nerdctl
run: |
mkdir -p nerdctl
cd nerdctl
wget https://github.com/containerd/nerdctl/releases/download/v1.0.0/nerdctl-1.0.0-linux-amd64.tar.gz
tar -xf nerdctl-1.0.0-linux-amd64.tar.gz
cp nerdctl /usr/local/bin/
- name: Download Kafka
run: |
sudo apt-get update
sudo apt-get install openjdk-8-jdk
wget https://archive.apache.org/dist/kafka/3.6.0/kafka_2.13-3.6.0.tgz
tar -zxvf kafka_2.13-3.6.0.tgz
cd kafka_2.13-3.6.0
KAFKA_CLUSTER_ID="$(bin/kafka-storage.sh random-uuid)"
bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c config/kraft/server.properties
bin/kafka-server-start.sh config/kraft/server.properties &> /dev/null &
- name: Download etcdctl
run: |
wget https://github.com/etcd-io/etcd/releases/download/v3.4.14/etcd-v3.4.14-linux-amd64.tar.gz
tar -zxf etcd-v3.4.14-linux-amd64.tar.gz
mv etcd-v3.4.14-linux-amd64/etcdctl /usr/local/bin
sudo chmod +x /usr/local/bin/
etcdctl version
- name: Flannel Config
run: |
export ETCDCTL_API=2
etcdctl --endpoints http://127.0.0.1:2379 set /coreos.com/network/config '{"Network": "10.0.0.0/16", "SubnetLen": 24, "SubnetMin": "10.0.1.0","SubnetMax": "10.0.20.0", "Backend": {"Type": "vxlan"}}'
nerdctl run -d --privileged -v /run/flannel:/run/flannel --net host --name flannel registry.cn-hangzhou.aliyuncs.com/acs/flannel:v0.15.1.22-20a397e6-aliyun \
-etcd-prefix /coreos.com/network -iface eth0 -etcd-endpoints http://192.168.0.180:2379 -ip-masq
nerdctl network ls
- name: Download Nginx
run: |
sudo apt install -y curl gnupg2 ca-certificates lsb-release
sudo apt install -y nginx
sudo systemctl start nginx
- name: Run tests
run: sudo go test ./...
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
.idea

# windows executable files
**/*.exe
**/*.exe

build
2 changes: 2 additions & 0 deletions cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ cd cmd
go run kubectl.go
```

kubectl apply -f \<filename\>
已经可以使用,请正确指定yaml文件的路径
14 changes: 14 additions & 0 deletions cmd/apiserver/apiserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"minik8s/pkg/apiserver/server"
"minik8s/pkg/config"
)

func main() {

host, port := config.GetHostAndPort()
server := server.NewAPIserver(host, port)

server.Run()
}
8 changes: 8 additions & 0 deletions cmd/controller/controller.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "minik8s/pkg/controller/controllermanager"

func main() {
Controllers := controllermanager.NewControllerManager()
Controllers.Run(make(chan bool))
}
1 change: 1 addition & 0 deletions cmd/kubectl.go → cmd/kubectl/kubectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func main() {
rootCmd.AddCommand(cmd.ApplyCmd())
rootCmd.AddCommand(cmd.DeleteCmd())
rootCmd.AddCommand(cmd.DescribeCmd())
rootCmd.AddCommand(cmd.HttpCmd())

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
Expand Down
9 changes: 9 additions & 0 deletions cmd/kubectl/kubectl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"testing"
)

func TestMain(m *testing.M) {

}
18 changes: 18 additions & 0 deletions cmd/kubelet/kubelet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"minik8s/pkg/kubelet/subscriber"
"os"
)

func main() {
if len(os.Args) < 3 {
server := subscriber.NewKubeletSubscriber("")
server.Run()
} else {
if os.Args[1] == "--name" {
server := subscriber.NewKubeletSubscriber(os.Args[2])
server.Run()
}
}
}
19 changes: 19 additions & 0 deletions cmd/kubeproxy/kubeproxy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"minik8s/pkg/kubeproxy"
"os"
)

func main() {
if len(os.Args) < 3 {
proxy := kubeproxy.NewKubeProxy("")
proxy.Run()
} else {
if os.Args[1] == "--name" {
proxy := kubeproxy.NewKubeProxy(os.Args[2])
proxy.Run()
}
}

}
8 changes: 8 additions & 0 deletions cmd/scheduler/scheduler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package main

import "minik8s/pkg/scheduler"

func main() {
server := scheduler.NewScheduler()
server.Run()
}
82 changes: 82 additions & 0 deletions docs/serverless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Severless实现

### 1. Function抽象

**使用方式**

- 用户可以通过单个python文件定义function,python文件名无要求,但是主函数名必须为`main`
- 用户需要指定参数和返回值的数量、类型,也可指定名字(用于workflow之间传递指定参数);
- 用户可以指定函数invoke方式:http或event trigger;
- 用户需在对应文件夹下提供requirement.txt

yaml文件示例如下:

```yaml
apiVersion: v1
kind: Function
metadata:
name: BuyTrainTicket
language: python
filePath: /root/minik8s/testdata/workflow1/BuyTrainTicket/
triggerType:
http: true
params:
- name: x
type: int
result:
- name: x
type: int
- name: greeting
type: string
```
实现方式:
#### 1.1 创建function
通过 `apply -f <filepath>` 指令,通过yaml文件创建function:

1. 存入etcd;

2. build函数镜像

1. 将所有需要的文件复制到工作路径,安装运行环境
2. 在容器中写入一个server.py,在容器运行时监听8080端口,并且执行用户函数,将结果发送至集群的apiserver

3. 将镜像push到minik8s所维护的镜像仓库

> 该镜像仓库是运行在master IP 下的 5050 端口上的一个 Docker registry









1. ⽀持Function抽象。⽤⼾可以通过单个⽂件(zip包或代码⽂件)定义函数内容,通过指令上传给
minik8s,并且通过http trigger和event trigger调⽤函数。
◦ 函数需要⾄少⽀持Python语⾔
◦ 函数的格式,return的格式,update、invoke指令的格式可以⾃定义
◦ 函数调⽤的⽅式:⽀持⽤⼾通过http请求、和绑定事件触发两种⽅式调⽤函数。函数可以通过
指令指定要绑定的事件源,事件的类型可以是时间计划、⽂件修改或其他⾃定义内容
2. ⽀持Serverless Workflow抽象:⽤⼾可以定义Serverless DAG,包括以下⼏个组成成分:
◦ 函数调⽤链:在调⽤函数时传参给第⼀个函数,之后依次调⽤各个函数,前⼀个函数的输出作
为后⼀个函数的输⼊,最终输出结果。
◦ 分⽀:根据上⼀个函数的输出,控制⾯决定接下来运⾏哪⼀个分⽀的函数。
◦ Serverless Workflow可以通过配置⽂件来定义,参考AWS StepFunction或Knative的做法。除
此之外,同学们也可以⾃⾏定义编程模型来构建Serverless Workflow,只要workflow能达到
上述要求即可。
3. Serverless的⾃动扩容(Scale-to-0)
◦ Serverless的实例应当在函数请求⾸次到来时被创建(冷启动),并且在⻓时间没有函数请求再
次到来时被删除(scale-to-0)。同时,Serverless能够监控请求数变化,当请求数量增多时能
够⾃动扩容⾄>1实例。
◦ Serverless应当能够正确处理⼤量的并发请求(数⼗并发),演⽰时使⽤wrk2或者Jmeter进⾏压
⼒测试。
4. 找⼀个较为复杂的开源的Serverless应⽤或者⾃⾏实现⼀个较为复杂的Serverless应⽤,该应⽤必
须有现实的应⽤场景(⽐如下图所⽰的 Image Processing),不能只是简单的加减乘除或者hello
world。将该应⽤部署在minik8s上,基于这个应⽤来展⽰Serverless相关功能,并在验收报告中结
合该应⽤的需求和特点详细分析该应⽤使⽤Serverless架构的必要性和优势。 Serverless样例可参考Serverlessbench中的Alexa:ServerlessBench/Testcase4-Applicationbreakdown/alexa at master · SJTU-IPADS/ServerlessBench
125 changes: 124 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,132 @@ module minik8s

go 1.22.2

require github.com/spf13/cobra v1.8.0
require (
github.com/IBM/sarama v1.43.2
github.com/containerd/containerd v1.7.15
github.com/fatih/color v1.16.0
github.com/hashicorp/consul/api v1.29.1
github.com/moby/ipvs v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cobra v1.8.0
go.etcd.io/etcd/client/v3 v3.5.13
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/armon/go-metrics v0.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/eapache/go-resiliency v1.6.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/vishvananda/netlink v1.2.1-beta.2 // indirect
github.com/vishvananda/netns v0.0.2 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
)

require (
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 // indirect
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20230306123547-8075edf89bb0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/containerd/cgroups v1.1.0
github.com/containerd/continuity v0.4.2 // indirect
github.com/containerd/fifo v1.1.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/ttrpc v1.2.3 // indirect
github.com/containerd/typeurl/v2 v2.1.1 // indirect
github.com/coreos/go-semver v0.3.1 // indirect
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/gin-gonic/gin v1.9.1
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/uuid v1.3.1
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/signal v0.7.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/opencontainers/runtime-spec v1.1.0
github.com/opencontainers/selinux v1.11.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.etcd.io/etcd/api/v3 v3.5.13 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
Loading

0 comments on commit abca5ab

Please sign in to comment.