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

Enhance egctl #1020

merged 31 commits into from
Jul 7, 2023

Conversation

suchen-sci
Copy link
Contributor

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2023

Codecov Report

Patch coverage: 49.09% and project coverage change: -0.10 ⚠️

Comparison is base (2c257b1) 81.69% compared to head (7dfd1cc) 81.60%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1020      +/-   ##
==========================================
- Coverage   81.69%   81.60%   -0.10%     
==========================================
  Files         135      135              
  Lines       15044    15104      +60     
==========================================
+ Hits        12290    12325      +35     
- Misses       2197     2222      +25     
  Partials      557      557              
Impacted Files Coverage Δ
pkg/cluster/customdata/customdata.go 74.30% <0.00%> (-8.52%) ⬇️
pkg/cluster/layout.go 95.23% <0.00%> (-4.77%) ⬇️
pkg/object/autocertmanager/autocertmanager.go 93.60% <100.00%> (+0.13%) ⬆️
pkg/object/grpcserver/grpcserver.go 100.00% <100.00%> (ø)
pkg/object/httpserver/httpserver.go 100.00% <100.00%> (ø)
pkg/object/mqttproxy/mqttproxy.go 50.00% <100.00%> (+3.16%) ⬆️
pkg/object/pipeline/pipeline.go 81.48% <100.00%> (+0.38%) ⬆️

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

cmd/client/commandv2/create.go Outdated Show resolved Hide resolved
cmd/client/commandv2/general.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@suchen-sci suchen-sci marked this pull request as draft June 28, 2023 04:31
@suchen-sci suchen-sci marked this pull request as ready for review July 5, 2023 10:27
Copy link
Collaborator

@localvar localvar left a comment

Choose a reason for hiding this comment

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

  1. please also fix github action warnings.

  2. general, common, utils are all too general names, it is hard to guess their usages.

# egctl Cheat Sheet

## Creating resources
Easegress manifests are defined in YAML. The file extension .yaml and .yml be used. Use `egctl create`, or `egctl apply` to create resources. Use `egctl api-resources` to view all available resources and their supported actions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

please use chatgpt to improve this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all updated, please check!

Comment on lines 116 to 125
kinds, err := s.cds.ListKinds()
if err != nil {
ClusterPanic(err)
}

for _, k := range kinds {
err = s.cds.DeleteKind(k.Name)
if err != nil {
ClusterPanic(err)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this could be done via one etcd request, no need list and loops.

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

// Output table:
// NAME ROLE AGE STATE API-ADDR HEARTBEAT
table := [][]string{}
table = append(table, []string{"NAME", "ROLE", "AGE", "STATE", "API-ADDR", "HEARTBEAT"})
Copy link
Contributor

Choose a reason for hiding this comment

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

"API ADDR" would be better (via k8s), and all other fields with multiple words.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your advice. I check several k8s commands, I find some of them use seperate words(pod), some of them use "-" to connect words(node, deployment, svc). I am prefer "API-ADDR" over "API ADDR" because "API-ADDR" feel more like one word, and "API ADDR" feel more like two words. And when print table in terminal, sometimes two columns really close to each other, "API-ADDR" may feels better. So, it that ok to keep "API-ADDR"?

cd:➜  ~  |>k get svc -o wide | grep NAME                                                                                                                                                         [~]
NAME                              TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                                     AGE    SELECTOR
cd:➜  ~  |>k get po -o wide | grep NAME                                                                                                                                                          [~]
NAME                                                 READY   STATUS      RESTARTS       AGE     IP              NODE   NOMINATED NODE   READINESS GATES
cd:➜  ~  |>k get deploy -o wide | grep NAME                                                                                                                                                      [~]
NAME                                READY   UP-TO-DATE   AVAILABLE   AGE    CONTAINERS                          IMAGES                                                                                     SELECTOR
cd:➜  ~  |>k get node -o wide | grep NAME                                                                                                                                                        [~]
NAME   STATUS   ROLES                  AGE    VERSION   INTERNAL-IP    EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure

README.md Outdated
@@ -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

resp, body := doRequestV1(httpMethod, url, jsonBody, client, cmd)

msg := string(body)
if strings.HasPrefix(url, general.HTTPProtocol) && resp.StatusCode == http.StatusBadRequest && strings.Contains(strings.ToUpper(msg), "HTTPS") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Server returns 400 if the protocol is wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I actually reuse previous logic about updating protocol part. And I just do a test about it to make sure. The answer is yes. Golang http lib will return 400 if the protocol is wrong.

➜  easegress git:(enhance-egctl) ✗ curl http:https://localhost:2381/apis/v2 -v
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 2381 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 2381 (#0)
> GET /apis/v2 HTTP/1.1
> Host: localhost:2381
> User-Agent: curl/7.64.1
> Accept: */*
> 
* HTTP 1.0, assume close after body
< HTTP/1.0 400 Bad Request
< 
Client sent an HTTP request to an HTTPS server.
* Closing connection 0

return "", err
}

return path.Join(homeDir, ".egctlconfig"), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

.egctlrc would be more idiomatic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

all updated, please check!

@@ -15,6 +15,7 @@
* limitations under the License.
*/

// Package commandv2 provides the new version of commands.
Copy link
Collaborator

@localvar localvar Jul 7, 2023

Choose a reason for hiding this comment

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

add comment to one file of a package could resolve the github action warning, no need to add the comment to all files.

however, as the comments have been added, it is ok to leave them there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it!

@xxx7xxxx xxx7xxxx added this pull request to the merge queue Jul 7, 2023
Merged via the queue into easegress-io:main with commit cec32d6 Jul 7, 2023
7 checks passed
@suchen-sci suchen-sci deleted the enhance-egctl branch July 7, 2023 03:35
sodaRyCN pushed a commit to wecloudstack/Bigress that referenced this pull request Jul 9, 2023
* 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 -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants