Skip to content

Commit

Permalink
Enhance egctl (#1020)
Browse files Browse the repository at this point in the history
* finish get command and refactor code

* finish describe object

* finish all describe

* finish create, delete, update

* finish other command

* add example framework

* add more examples, add other missing commands

* add command for object status

* udpate egctl command

* update

* add comments

* add more comments, add egctl cheat sheet

* update egctl cheat sheet

* fix random test bug

* update based on comment

* rewrite apply create get command

* finish describe, delete and refactor code

* update examples

* fix typo

* add security for egctl

* update doc

* refactor code structure

* update based on code review comments

* update based on github action

* update based on github action

* update based on github action

* update based on github action

* update based on github action

* update based on github action

* support egctl create/apply -f -
  • Loading branch information
suchen-sci committed Jul 7, 2023
1 parent 9e8c6ed commit cec32d6
Show file tree
Hide file tree
Showing 87 changed files with 4,155 additions and 503 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ The architecture of Easegress:
- **Compression:** compresses body for the response.
- **Hot-Update:** updates both config and binary of Easegress in place without losing connections.
- **Operation**
- **Easy to Integrate:** command line(`egctl`), MegaEase Portal, HTTP clients such as curl, postman, etc.
- **Easy to Integrate:** command line([egctl](./doc/egctl-cheat-sheet.md)), MegaEase Portal, HTTP clients such as curl, postman, etc.
- **Distributed Tracing**
- Built-in [OpenTelemetry](https://opentelemetry.io/), which provides a vendor-neutral API.
- **Observability**
Expand Down Expand Up @@ -195,15 +195,20 @@ configuration file or command-line arguments that are explained well in
`easegress-server --help`.

```bash
$ egctl member list | grep "ClusterRole"
ClusterRole: primary
$ egctl member list | grep "APIAddr"
APIAddr: localhost:2381
$ egctl member list | grep "Name"
ClusterName: eg-cluster-default-name
Name: eg-default-name
$ egctl member list | grep "id"
id: 689e371e88f78b6a
$ egctl get member
NAME ROLE AGE STATE API-ADDR HEARTBEAT
eg-default-name primary 9s Leader localhost:2381 3s ago

$ egctl describe member
Name: eg-default-name
LastHeartbeatTime: "2023-07-03T17:39:30+08:00"

Etcd:
=====
id: 689e371e88f78b6a
startTime: "2023-07-03T17:39:14+08:00"
state: Leader
...
```

After launching successfully, we could check the status of the one-node
Expand All @@ -224,7 +229,7 @@ https: false
rules:
- paths:
- pathPrefix: /pipeline
backend: pipeline-demo' | egctl object create
backend: pipeline-demo' | egctl create -f -
```

The rules above mean it will forward the traffic with the prefix `/pipeline` to
Expand All @@ -246,7 +251,7 @@ filters:
- url: http:https://127.0.0.1:9096
- url: http:https://127.0.0.1:9097
loadBalance:
policy: roundRobin' | egctl object create
policy: roundRobin' | egctl create -f -
```

The pipeline means it will forward traffic to 3 backend endpoints, using the
Expand Down Expand Up @@ -374,7 +379,7 @@ filters:
kind: ResponseBuilder
template: |
statusCode: 200
body: RSS feed has been sent to Slack successfully.' | egctl object create
body: RSS feed has been sent to Slack successfully.' | egctl create -f -
```

### Update the HTTPServer
Expand All @@ -394,7 +399,7 @@ rules:
- pathPrefix: /rss # +
backend: rss-pipeline # +
- pathPrefix: /pipeline
backend: pipeline-demo' | egctl object update
backend: pipeline-demo' | egctl apply -f -
```
### Test the RSS Pipeline
Expand Down
33 changes: 19 additions & 14 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
- **压缩**:减少应答数据的体积。
- **热更新**:线上更新 Easegress 的配置和二进制文件,服务不中断。
- **操作**
- **易于集成**:命令行(`egctl`)、MegaEase Portal,以及 HTTP 客户端,如 curl、postman 等。
- **易于集成**:命令行([egctl](./doc/egctl-cheat-sheet.md))、MegaEase Portal,以及 HTTP 客户端,如 curl、postman 等。
- **分布式跟踪**
- 内置 [OpenTelemetry](https://opentelemetry.io/),提供厂商中立的 API。
- **可观察性**
Expand Down Expand Up @@ -183,15 +183,20 @@ Makefile 默认会将两个二进制文件编译到 `bin/` 目录中。`bin/ease
如果启动时不指定任何参数,`easegress-server` 会默认使用端口 2379、2380 和 2381。我们可以在配置文件中更改默认端口,或者在命令行启动时指定相关参数(参数具体释义可通过执行 `easegress-server --help` 命令获取)。

```bash
$ egctl member list | grep "ClusterRole"
ClusterRole: primary
$ egctl member list | grep "APIAddr"
APIAddr: localhost:2381
$ egctl member list | grep "Name"
ClusterName: eg-cluster-default-name
Name: eg-default-name
$ egctl member list | grep "id"
id: 689e371e88f78b6a
$ egctl get member
NAME ROLE AGE STATE API-ADDR HEARTBEAT
eg-default-name primary 9s Leader localhost:2381 3s ago

$ egctl describe member
Name: eg-default-name
LastHeartbeatTime: "2023-07-03T17:39:30+08:00"

Etcd:
=====
id: 689e371e88f78b6a
startTime: "2023-07-03T17:39:14+08:00"
state: Leader
...
```

成功启动后,我们可以用上述命令检查单节点集群的状态,它展示示了系统的静态选项,以及心跳和 etcd 的动态状态。
Expand All @@ -210,7 +215,7 @@ https: false
rules:
- paths:
- pathPrefix: /pipeline
backend: pipeline-demo' | egctl object create
backend: pipeline-demo' | egctl create -f -
```

上面的路由规则将把路径前缀为 `/pipeline` 的请求分发到名为 `pipeline-demo` 的 Pipeline,目前还没有这条 Pipeline,如果 `curl` 这个地址,将返回 503。
Expand All @@ -230,7 +235,7 @@ filters:
- url: http:https://127.0.0.1:9096
- url: http:https://127.0.0.1:9097
loadBalance:
policy: roundRobin' | egctl object create
policy: roundRobin' | egctl create -f -
```

这条 Pipeline 的定义是将请求按轮询的方式分发到三个后端服务实例上。
Expand Down Expand Up @@ -351,7 +356,7 @@ filters:
kind: ResponseBuilder
template: |
statusCode: 200
body: RSS feed has been sent to Slack successfully.' | egctl object create
body: RSS feed has been sent to Slack successfully.' | egctl create -f -
```
### 更新 HTTPServer
Expand All @@ -370,7 +375,7 @@ rules:
- pathPrefix: /rss # +
backend: rss-pipeline # +
- pathPrefix: /pipeline
backend: pipeline-demo' | egctl object update
backend: pipeline-demo' | egctl apply -f -
```
### 测试 RSS Pipeline
Expand Down
42 changes: 42 additions & 0 deletions cmd/client/command/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2017, MegaEase
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http:https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// Package command provides the commands.
package command

import "github.com/megaease/easegress/cmd/client/general"

var makePath = general.MakePath

const (
apiURL = general.APIURL

membersURL = general.MembersURL
memberURL = general.MemberItemURL

objectKindsURL = general.ObjectKindsURL
objectsURL = general.ObjectsURL
objectURL = general.ObjectItemURL

statusObjectURL = general.StatusObjectItemURL
statusObjectsURL = general.StatusObjectsURL

customDataKindURL = general.CustomDataKindURL
customDataKindItemURL = general.CustomDataKindItemURL
customDataURL = general.CustomDataURL
customDataItemURL = general.CustomDataItemURL
)
5 changes: 3 additions & 2 deletions cmd/client/command/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/

// Package command provides the commands.
package command

import (
Expand All @@ -27,7 +28,7 @@ import (
func APICmd() *cobra.Command {
cmd := &cobra.Command{
Use: "api",
Short: "View Easegress APIs",
Short: "(Deprecated) View Easegress APIs",
}

cmd.AddCommand(listAPICmd())
Expand All @@ -39,7 +40,7 @@ func listAPICmd() *cobra.Command {
Use: "list",
Short: "List Easegress APIs",
Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodGet, makeURL(apiURL), nil, cmd)
handleRequest(http.MethodGet, makePath(apiURL), nil, cmd)
},
}

Expand Down
Loading

0 comments on commit cec32d6

Please sign in to comment.