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

support egctl get describe different namespace #1197

Merged
merged 8 commits into from
Jan 26, 2024
Prev Previous commit
Next Next commit
add integration tests
  • Loading branch information
suchen-sci committed Jan 25, 2024
commit 81d67860148b5ea30f217a738044f8474d9fed64
64 changes: 64 additions & 0 deletions build/test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ func TestCreateHTTPProxy(t *testing.T) {
assert.Empty(stderr)
defer func() {
deleteResource("httpserver", "http-proxy-test")
deleteResource("pipeline", "--all")
}()

output, err := getResource("httpserver")
Expand Down Expand Up @@ -1473,4 +1474,67 @@ filters:
assert.Contains(output, "mock-httpserver")
assert.Contains(output, "port: 10222")
}

// easegress update status every 5 seconds
time.Sleep(5 * time.Second)

// egctl describe httpserver --all-namespaces
{
cmd := egctlCmd("describe", "httpserver", "--all-namespaces")
output, stderr, err := runCmd(cmd)
assert.Nil(err)
assert.Empty(stderr)
assert.Contains(output, "Name: httpserver-test")
assert.Contains(output, "Name: mock-httpserver")
assert.NotContains(output, "Name: pipeline-test")
assert.NotContains(output, "Name: mock-pipeline")
assert.Contains(output, "In Namespace default")
assert.Contains(output, "In Namespace mockNamespace")
// check if status is updated
assert.Equal(2, strings.Count(output, "node: primary-single"))
assert.Equal(2, strings.Count(output, "m1ErrPercent: 0"))
}

// egctl describe httpserver --namespace mockNamespace
{
cmd := egctlCmd("describe", "httpserver", "--namespace", "mockNamespace")
output, stderr, err := runCmd(cmd)
assert.Nil(err)
assert.Empty(stderr)
assert.Contains(output, "Name: mock-httpserver")
assert.NotContains(output, "Name: httpserver-test")
assert.NotContains(output, "Name: pipeline-test")
assert.NotContains(output, "Name: mock-pipeline")
// check if status is updated
assert.Equal(1, strings.Count(output, "node: primary-single"))
assert.Equal(1, strings.Count(output, "m1ErrPercent: 0"))
}

// egctl describe pipeline --namespace default
{
cmd := egctlCmd("describe", "pipeline", "--namespace", "default")
output, stderr, err := runCmd(cmd)
assert.Nil(err)
assert.Empty(stderr)
assert.NotContains(output, "Name: httpserver-test")
assert.Contains(output, "Name: pipeline-test")
assert.NotContains(output, "Name: mock-httpserver")
assert.NotContains(output, "Name: mock-pipeline")
// check if status is updated
assert.Equal(1, strings.Count(output, "node: primary-single"))
assert.Equal(1, strings.Count(output, "p999: 0"))
}

// egctl describe hs mock-httpserver --namespace mockNamespace -o yaml
{
cmd := egctlCmd("describe", "hs", "mock-httpserver", "--namespace", "mockNamespace", "-o", "yaml")
output, stderr, err := runCmd(cmd)
assert.Nil(err)
assert.Empty(stderr)
assert.NotContains(output, "httpserver-test")
assert.NotContains(output, "pipeline-test")
assert.Contains(output, "name: mock-httpserver")
assert.Contains(output, "port: 10222")
assert.Contains(output, "node: primary-single")
}
}
18 changes: 10 additions & 8 deletions cmd/client/resources/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,7 @@ func DescribeObject(cmd *cobra.Command, args *general.ArgInfo, kind string, flag
// status: ...
// - node: eg2
// status: ...
printNamespace := func(namespace string) {
msg := fmt.Sprintf("In Namespace %s:", namespace)
fmt.Println(strings.Repeat("=", len(msg)))
fmt.Println(msg)
fmt.Println(strings.Repeat("=", len(msg)))
}

printSpace := false
specs := namespaceSpecs[DefaultNamespace]
if len(specs) > 0 {
Expand All @@ -446,6 +441,13 @@ func DescribeObject(cmd *cobra.Command, args *general.ArgInfo, kind string, flag
return nil
}

func printNamespace(ns string) {
msg := fmt.Sprintf("In Namespace %s:", ns)
fmt.Println(strings.Repeat("=", len(msg)))
fmt.Println(msg)
fmt.Println(strings.Repeat("=", len(msg)))
}

// CreateObject creates an object.
func CreateObject(cmd *cobra.Command, s *general.Spec) error {
_, err := handleReq(http.MethodPost, makePath(general.ObjectsURL), []byte(s.Doc()))
Expand Down Expand Up @@ -610,8 +612,8 @@ func unmarshalObjectStatusInfo(body []byte, name string) ([]*objectStatusInfo, e

// NodeStatus is the status of a node.
type NodeStatus struct {
Node string
Status map[string]interface{}
Node string `json:"node"`
Status map[string]interface{} `json:"status"`
}

const objectStatusKeyInSpec = "allStatus"
Expand Down