Files
kubevela/references/cli/pods.go
T
github-actions[bot]andbarnettZQG 3a9e5ccd5d [Backport release-1.5] Feat: refactor CLI commands related to resources (#4514)
* Feat: refactor CLI commands related to resources

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit dacefcac80)

* Fix: remove the old test case.

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit ef9fbaa22f)

* Fix: e2e test

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 6f412f5b45)

* Fix: optimize test cases

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 501d7cfad7)

* Feat: rename 'vela pods' to 'vela status --pod'

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 2d6ad41afc)

* Feat: optimize the e2e test case

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit afa786a096)

* Fix: sort the objects

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 619e9b1b5f)

* Fix: optimize the e2e test case

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit d6688c40b5)

* Fix: list the pod by the labels

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit aec1791ac1)

* Fix: order the tree resource

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit f51abadec3)

* Fix: set multicluster config

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 767b0020e5)

Co-authored-by: barnettZQG <barnett.zqg@gmail.com>
2022-08-01 19:46:20 +08:00

70 lines
1.9 KiB
Go

/*
Copyright 2022 The KubeVela Authors.
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://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 cli
import (
"context"
"fmt"
"github.com/gosuri/uitable"
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
"github.com/oam-dev/kubevela/pkg/utils/common"
"github.com/oam-dev/kubevela/references/appfile"
)
func printAppPods(appName string, namespace string, f Filter, velaC common.Args) error {
app, err := appfile.LoadApplication(namespace, appName, velaC)
if err != nil {
return err
}
var podArgs = PodArgs{
Args: velaC,
Namespace: namespace,
Filter: f,
App: app,
}
table, err := podArgs.listPods(context.Background())
if err != nil {
return err
}
fmt.Println(table.String())
return nil
}
// PodArgs creates arguments for `pods` command
type PodArgs struct {
Args common.Args
Namespace string
Filter Filter
App *v1beta1.Application
}
func (p *PodArgs) listPods(ctx context.Context) (*uitable.Table, error) {
pods, err := GetApplicationPods(ctx, p.App.Name, p.Namespace, p.Args, p.Filter)
if err != nil {
return nil, err
}
table := uitable.New()
table.AddRow("CLUSTER", "COMPONENT", "POD NAME", "NAMESPACE", "PHASE", "CREATE TIME", "REVISION", "HOST")
for _, pod := range pods {
table.AddRow(pod.Cluster, pod.Component, pod.Metadata.Name, pod.Metadata.Namespace, pod.Status.Phase, pod.Metadata.CreationTime, pod.Metadata.Version.DeployVersion, pod.Status.NodeName)
}
return table, nil
}