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

Enhance egctl #1020

Merged
merged 31 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
a755223
finish get command and refactor code
suchen-sci Jun 16, 2023
a118ed2
finish describe object
suchen-sci Jun 16, 2023
4c96e30
finish all describe
suchen-sci Jun 19, 2023
84ab4c6
finish create, delete, update
suchen-sci Jun 20, 2023
5f9815a
finish other command
suchen-sci Jun 21, 2023
6a807fe
add example framework
suchen-sci Jun 21, 2023
587e948
add more examples, add other missing commands
suchen-sci Jun 25, 2023
75219f6
add command for object status
suchen-sci Jun 26, 2023
9a74cf9
udpate egctl command
suchen-sci Jun 26, 2023
7d1f484
update
suchen-sci Jun 26, 2023
9f75742
add comments
suchen-sci Jun 26, 2023
7bc5634
add more comments, add egctl cheat sheet
suchen-sci Jun 26, 2023
9d8063a
update egctl cheat sheet
suchen-sci Jun 26, 2023
a496d83
fix random test bug
suchen-sci Jun 26, 2023
86baec0
update based on comment
suchen-sci Jun 26, 2023
599cd37
rewrite apply create get command
suchen-sci Jun 29, 2023
bf84ef6
finish describe, delete and refactor code
suchen-sci Jun 30, 2023
66d0089
update examples
suchen-sci Jul 3, 2023
e3169b9
Merge branch 'main' into enhance-egctl
suchen-sci Jul 3, 2023
f4a1e84
fix typo
suchen-sci Jul 3, 2023
d62f266
add security for egctl
suchen-sci Jul 5, 2023
d65c077
update doc
suchen-sci Jul 5, 2023
cb58b43
refactor code structure
suchen-sci Jul 6, 2023
f69ec13
update based on code review comments
suchen-sci Jul 6, 2023
14ebb75
update based on github action
suchen-sci Jul 6, 2023
7dfd1cc
update based on github action
suchen-sci Jul 6, 2023
83df91b
update based on github action
suchen-sci Jul 6, 2023
92f54a8
update based on github action
suchen-sci Jul 6, 2023
b8593fc
update based on github action
suchen-sci Jul 6, 2023
c4e92c4
update based on github action
suchen-sci Jul 6, 2023
6e81f67
support egctl create/apply -f -
suchen-sci Jul 7, 2023
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking if we should use more idiomatic egctl create|apply -f -

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, i will update it now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw your demo not showing this usage, is it supported now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, user can create and apply resoruce from yaml file or stdin.

➜  easegress git:(enhance-egctl) ✗ cat httpserver.yaml | egctl create 
create HTTPServer httpserver successfully

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought you will support egctl create -f -

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for misunderstanding... Let me update it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, now egctl create -f - and egctl apply -f - is supported. egctl create/apply will print the help text. I also update related ducoments. Please check again.

➜  cat httpserver.yaml | egctl create -f -
create HTTPServer httpserver successfully
➜  cat httpserver.yaml | egctl apply -f - 
update HTTPServer httpserver successfully
➜  egctl create         
Error: yaml file is required
Usage:
...

Examples:
...
...
Error: yaml file is required

```

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
```

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
```

### 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
```

### 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
```

上面的路由规则将把路径前缀为 `/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
```

这条 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
```

### 更新 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
```

### 测试 RSS Pipeline
Expand Down
41 changes: 41 additions & 0 deletions cmd/client/command/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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

Check warning on line 18 in cmd/client/command/alias.go

View workflow job for this annotation

GitHub Actions / analysis

should have a package comment

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
)
4 changes: 2 additions & 2 deletions cmd/client/command/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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 +39,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
Loading