cmd

package
v0.9.271 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2025 License: AGPL-3.0 Imports: 24 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",
	Short: "Query k8s containers",
	Args:  cobra.ArbitraryArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		client, ok := cmd.Context().Value(keys.CLIENT_CONTEXT_KEY).(*client.Client)
		if !ok {
			return fmt.Errorf("invalid client in context")
		}

		root, _ := cmd.Flags().GetString(runc_flags.RootFlag.Full)
		namespace, _ := cmd.Flags().GetString(containerd_flags.NamespaceFlag.Full)
		names, _ := cmd.Flags().GetStringSlice(k8s_flags.NameFlag.Full)
		containerType, _ := cmd.Flags().GetString(k8s_flags.ContainerTypeFlag.Full)

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

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

		result := resp.K8S

		if len(result.Pods) == 0 {
			fmt.Println("No pods found")
			return nil
		}

		tableWriter := table.NewWriter()
		tableWriter.SetStyle(style.TableStyle)
		tableWriter.SetOutputMirror(os.Stdout)

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

		tableWriter.SortBy([]table.SortBy{
			{Name: "ID", Mode: table.Asc},
		})

		for _, pod := range result.Pods {
			for i, container := range pod.Containerd {
				if i == 0 {
					tableWriter.AppendRow(table.Row{
						pod.ID,
						pod.Name,
						pod.Namespace,
						container.ID,
					})
				} else {
					tableWriter.AppendRow(table.Row{
						"",
						"",
						"",
						container.ID,
					})
				}
			}
		}

		if len(result.Pods) > 0 {
			tableWriter.Render()
			fmt.Println()
		}

		for _, msg := range resp.Messages {
			fmt.Println(msg)
		}

		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