From 037ffac9f958829c0bf4a759e3c1f07187ced8c4 Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo1991@outlook.com>
Date: Thu, 23 May 2024 13:28:03 +0800
Subject: [PATCH] feat(ps): pod list add ready and restarts

---
 cmd/ps.go      |  4 +++-
 cmd/ps_test.go | 42 +++++++++++++++++++++++++-----------------
 go.mod         |  2 +-
 go.sum         |  4 ++--
 4 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/cmd/ps.go b/cmd/ps.go
index 5343c573..3a5284f4 100644
--- a/cmd/ps.go
+++ b/cmd/ps.go
@@ -212,7 +212,7 @@ func printProcesses(d *DryccCmd, appID string, input []api.Pods) {
 	if len(processes) == 0 {
 		d.Println(fmt.Sprintf("No processes found in %s app.", appID))
 	} else {
-		table := d.getDefaultFormatTable([]string{"NAME", "RELEASE", "STATE", "PTYPE", "STARTED"})
+		table := d.getDefaultFormatTable([]string{"NAME", "RELEASE", "STATE", "PTYPE", "READY", "RESTARTS", "STARTED"})
 		for _, process := range processes {
 			for _, pod := range process.PodsList {
 				table.Append([]string{
@@ -220,6 +220,8 @@ func printProcesses(d *DryccCmd, appID string, input []api.Pods) {
 					pod.Release,
 					pod.State,
 					pod.Type,
+					pod.Ready,
+					fmt.Sprintf("%v", pod.Restarts),
 					pod.Started.Format("2006-01-02T15:04:05MST"),
 				})
 			}
diff --git a/cmd/ps_test.go b/cmd/ps_test.go
index 83f25790..e2da889d 100644
--- a/cmd/ps_test.go
+++ b/cmd/ps_test.go
@@ -23,18 +23,22 @@ func TestPrintProcesses(t *testing.T) {
 	}
 	pods := []api.Pods{
 		{
-			Release: "v3",
-			Name:    "benign-quilting-web-4084101150-c871y",
-			Type:    "web",
-			State:   "up",
-			Started: dtime.Time{Time: &d},
+			Release:  "v3",
+			Name:     "benign-quilting-web-4084101150-c871y",
+			Type:     "web",
+			State:    "up",
+			Ready:    "1/1",
+			Restarts: 0,
+			Started:  dtime.Time{Time: &d},
 		},
 		{
-			Release: "v3",
-			Name:    "benign-quilting-worker-4084101150-c871y",
-			Type:    "worker",
-			State:   "up",
-			Started: dtime.Time{Time: &d},
+			Release:  "v3",
+			Name:     "benign-quilting-worker-4084101150-c871y",
+			Type:     "worker",
+			State:    "up",
+			Ready:    "1/1",
+			Restarts: 0,
+			Started:  dtime.Time{Time: &d},
 		},
 	}
 	cf, server, err := testutil.NewTestServerAndClient()
@@ -45,9 +49,9 @@ func TestPrintProcesses(t *testing.T) {
 
 	printProcesses(&DryccCmd{WOut: &b, ConfigFile: cf}, "appname", pods)
 
-	assert.Equal(t, b.String(), `NAME                                       RELEASE    STATE    PTYPE     STARTED                
-benign-quilting-web-4084101150-c871y       v3         up       web       2023-11-15T11:55:16CST    
-benign-quilting-worker-4084101150-c871y    v3         up       worker    2023-11-15T11:55:16CST    
+	assert.Equal(t, b.String(), `NAME                                       RELEASE    STATE    PTYPE     READY    RESTARTS    STARTED                
+benign-quilting-web-4084101150-c871y       v3         up       web       1/1      0           2023-11-15T11:55:16CST    
+benign-quilting-worker-4084101150-c871y    v3         up       worker    1/1      0           2023-11-15T11:55:16CST    
 `, "output")
 }
 
@@ -73,6 +77,8 @@ func TestPsList(t *testing.T) {
 					"type": "web",
 					"name": "foo-web-4084101150-c871y",
 					"state": "up",
+					"ready": "1/1",
+					"restarts": 0,
 					"started": "2016-02-13T00:47:52"
 				}
 			]
@@ -82,8 +88,8 @@ func TestPsList(t *testing.T) {
 	err = cmdr.PsList("foo", -1)
 	assert.NoError(t, err)
 
-	assert.Equal(t, b.String(), `NAME                        RELEASE    STATE    PTYPE    STARTED                
-foo-web-4084101150-c871y    v2         up       web      2016-02-13T00:47:52UTC    
+	assert.Equal(t, b.String(), `NAME                        RELEASE    STATE    PTYPE    READY    RESTARTS    STARTED                
+foo-web-4084101150-c871y    v2         up       web      1/1      0           2016-02-13T00:47:52UTC    
 `, "output")
 }
 
@@ -180,6 +186,8 @@ func TestPsScale(t *testing.T) {
 					"type": "web",
 					"name": "foo-web-4084101150-c871y",
 					"state": "up",
+					"ready": "1/1",
+					"restarts": 0,
 					"started": "2016-02-13T00:47:52"
 				}
 			]
@@ -198,8 +206,8 @@ func TestPsScale(t *testing.T) {
 	assert.Equal(t, testutil.StripProgress(b.String()), `Scaling processes... but first, coffee!
 done in 0s
 
-NAME                        RELEASE    STATE    PTYPE    STARTED                
-foo-web-4084101150-c871y    v2         up       web      2016-02-13T00:47:52UTC    
+NAME                        RELEASE    STATE    PTYPE    READY    RESTARTS    STARTED                
+foo-web-4084101150-c871y    v2         up       web      1/1      0           2016-02-13T00:47:52UTC    
 `, "output")
 }
 
diff --git a/go.mod b/go.mod
index b13dd8f8..538c887e 100644
--- a/go.mod
+++ b/go.mod
@@ -5,7 +5,7 @@ go 1.22
 require (
 	github.com/containerd/console v1.0.4
 	github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815
-	github.com/drycc/controller-sdk-go v0.0.0-20240522092128-9ed47aac090e
+	github.com/drycc/controller-sdk-go v0.0.0-20240523052610-656dcb6b9db3
 	github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f
 	github.com/olekukonko/tablewriter v0.0.5
 	github.com/stretchr/testify v1.9.0
diff --git a/go.sum b/go.sum
index c44f54d1..bb36be61 100644
--- a/go.sum
+++ b/go.sum
@@ -4,8 +4,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
 github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 h1:bWDMxwH3px2JBh6AyO7hdCn/PkvCZXii8TGj7sbtEbQ=
 github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3ebgob9U8Nd0kOddGdZWjyMGR8Wziv+TBNwSE=
-github.com/drycc/controller-sdk-go v0.0.0-20240522092128-9ed47aac090e h1:4gZBm6S2nsHH2JvX7Ky92XEM0JGPmVv6p6W7Phehz34=
-github.com/drycc/controller-sdk-go v0.0.0-20240522092128-9ed47aac090e/go.mod h1:n6eQe1irJqjwLo/7t9+Dhdv6faSESQN+ATnZRBP3/Uc=
+github.com/drycc/controller-sdk-go v0.0.0-20240523052610-656dcb6b9db3 h1:eITOqdzcBH/QQVDD/zwHyq5JY1+xXr3MsPg066uR4fk=
+github.com/drycc/controller-sdk-go v0.0.0-20240523052610-656dcb6b9db3/go.mod h1:n6eQe1irJqjwLo/7t9+Dhdv6faSESQN+ATnZRBP3/Uc=
 github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f h1:kgjvUQJeAszDoU1Vo4vTTE92KI8Av3JPb6Qn890niXg=
 github.com/drycc/pkg v0.0.0-20240225112316-78fc9239f51f/go.mod h1:n+QxGif6ha9CEoxVnlipxb9IdmerybcUSzTEDFkvjiA=
 github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
