cmd

package
v0.9.283 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const DAEMON_LOG_PATH = "/host/var/log/cedana-daemon.log"

Variables

View Source
var HelperCmd = &cobra.Command{
	Use:   "k8s",
	Short: "Helper for setting up and running in Kubernetes",
	Args:  cobra.ExactArgs(1),
}
View Source
var QueryCmd = &cobra.Command{
	Use:   "k8s <name1> [<name2> ...]",
	Short: "Query Kubernetes pods and containers",
	Args:  cobra.ArbitraryArgs,
	RunE: func(cmd *cobra.Command, names []string) error {
		ctx := cmd.Context()
		client, ok := ctx.Value(keys.CLIENT_CONTEXT_KEY).(*client.Client)
		if !ok {
			return fmt.Errorf("invalid client in context")
		}
		req, ok := ctx.Value(keys.QUERY_REQ_CONTEXT_KEY).(*daemon.QueryReq)
		if !ok {
			return fmt.Errorf("invalid query request in context")
		}

		namespace, _ := cmd.Flags().GetString(containerd_flags.NamespaceFlag.Full)
		containerType, _ := cmd.Flags().GetString(k8s_flags.ContainerTypeFlag.Full)

		req.Type = "k8s"
		req.K8S = &k8s.QueryReq{
			Namespace:     namespace,
			Names:         names,
			ContainerType: containerType,
		}

		resp, err := client.Query(ctx, req)
		if err != nil {
			return err
		}

		result := resp.K8S
		var output string

		defer func() {
			ctx = context.WithValue(ctx, keys.QUERY_RESP_CONTEXT_KEY, resp)
			ctx = context.WithValue(ctx, keys.QUERY_OUTPUT_CONTEXT_KEY, output)
			cmd.SetContext(ctx)
		}()

		if len(result.Pods) == 0 {
			return nil
		}

		tableWriter := table.NewWriter()
		tableWriter.SetStyle(style.TableStyle)

		tableWriter.AppendHeader(table.Row{
			"Sandbox ID",
			"Name",
			"Namespace",
			"Runtime",
			"Containers",
		})

		tableWriter.SetColumnConfigs([]table.ColumnConfig{
			{Name: "Sandbox ID", AutoMerge: true},
			{Name: "Name", AutoMerge: true},
			{Name: "Namespace", AutoMerge: true},
		})
		tableWriter.SortBy([]table.SortBy{
			{Name: "Name", Mode: table.Asc},
		})

		for _, pod := range result.Pods {
			for _, container := range pod.Containerd {
				tableWriter.AppendRow(table.Row{
					pod.ID,
					pod.Name,
					pod.Namespace,
					utils.Runtime(pod),
					container.ID,
				})
			}
		}

		output = tableWriter.Render()

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL