cmd

package
v1.15.4 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0 Imports: 140 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STDOUT outputType = 0 + iota
	MARKDOWN
	HTML
	JSONOUTPUT
	JSONPATH
)

outputTypes enum values

View Source
const (
	PolicyEnabled  = "Enabled"
	PolicyDisabled = "Disabled"
	PolicyAudit    = "Disabled (Audit)"
	UnknownState   = "Unknown"
)

PolicyEnabled and PolicyDisabled represent the endpoint policy status

Variables

View Source
var BPFAuthCmd = &cobra.Command{
	Use:   "auth",
	Short: "Manage authenticated connections between identities",
}

BPFAuthCmd represents the bpf command

View Source
var BPFBandwidthCmd = &cobra.Command{
	Use:   "bandwidth",
	Short: "BPF datapath bandwidth settings",
}

BPFBandwidthCmd represents the bpf_bandwidth command

View Source
var BPFCmd = &cobra.Command{
	Use:   "bpf",
	Short: "Direct access to local BPF maps",
}

BPFCmd represents the bpf command

View Source
var BPFConfigCmd = &cobra.Command{
	Use:   "config",
	Short: "Manage runtime config",
}

BPFConfigCmd represents the bpf command

View Source
var BPFCtCmd = &cobra.Command{
	Use:   "ct",
	Short: "Connection tracking tables",
}

BPFCtCmd represents the bpf_ct command

View Source
var BPFEgressCmd = &cobra.Command{
	Use:   "egress",
	Short: "Manage the egress routing rules",
}

BPFEgressCmd represents the bpf command

View Source
var BPFEndpointCmd = &cobra.Command{
	Use:   "endpoint",
	Short: "Local endpoint map",
}
View Source
var BPFIPCacheCmd = &cobra.Command{
	Use:   "ipcache",
	Short: "Manage the IPCache mappings for IP/CIDR <-> Identity",
}

BPFIPCacheCmd represents the bpf command

View Source
var BPFIPMasqCmd = &cobra.Command{
	Use:   "ipmasq",
	Short: "ip-masq-agent CIDRs",
}

BPFIPMasqCmd represents the bpf command

View Source
var BPFLBCmd = &cobra.Command{
	Use:   "lb",
	Short: "Load-balancing configuration",
}

bpfCtCmd represents the bpf_ct command

View Source
var BPFMaglevCmd = &cobra.Command{
	Use:   "maglev",
	Short: "Maglev lookup table",
}

BPFMaglevCmd represents the bpf lb maglev command

View Source
var BPFMetricsCmd = &cobra.Command{
	Use:   "metrics",
	Short: "BPF datapath traffic metrics",
}

BPFMetricsCmd represents the bpf_metrics command

View Source
var BPFMountFSCmd = &cobra.Command{
	Use:   "fs",
	Short: "BPF filesystem mount",
}
View Source
var BPFNatCmd = &cobra.Command{
	Use:   "nat",
	Short: "NAT mapping tables",
}

BPFNatCmd represents the bpf_nat command

View Source
var BPFNodeIDCmd = &cobra.Command{
	Use:   "nodeid",
	Short: "Manage the node IDs",
}

BPFNodeIDCmd represents the bpf command

View Source
var BPFPolicyCmd = &cobra.Command{
	Use:   "policy",
	Short: "Manage policy related BPF maps",
}

BPFPolicyCmd represents the bpf_policy command

View Source
var BPFRecorderCmd = &cobra.Command{
	Use:   "recorder",
	Short: "PCAP recorder",
}

BPFRecorderCmd represents the bpf_recorder command

View Source
var BPFSRv6Cmd = &cobra.Command{
	Use:   "srv6",
	Short: "Manage the SRv6 routing rules",
}

BPFSRv6Cmd represents the bpf command

View Source
var BPFTemplateCmd = &cobra.Command{
	Use:     "sha",
	Aliases: []string{"template"},
	Short:   "Manage compiled BPF template objects",
}

BPFTemplateCmd represents the bpf-sha command

View Source
var BPFTunnelCmd = &cobra.Command{
	Use:   "tunnel",
	Short: "Tunnel endpoint map",
}
View Source
var BPFVtepCmd = &cobra.Command{
	Use:   "vtep",
	Short: "Manage the VTEP mappings for IP/CIDR <-> VTEP MAC/IP",
}

BPFVtepCmd represents the bpf command

View Source
var BgpCmd = &cobra.Command{
	Use:   "bgp",
	Short: "Access to BGP control plane",
}

BgpCmd represents the bgp command

View Source
var BgpPeersCmd = &cobra.Command{
	Use:     "peers",
	Aliases: []string{"neighbors"},
	Short:   "List current state of all peers",
	Long:    "List state of all peers defined in CiliumBGPPeeringPolicy",
	Run: func(cmd *cobra.Command, args []string) {
		res, err := client.Bgp.GetBgpPeers(nil)
		if err != nil {
			disabledErr := bgp.NewGetBgpPeersDisabled()
			if errors.As(err, &disabledErr) {
				fmt.Println("BGP Control Plane is disabled")
				return
			}
			Fatalf("cannot get peers list: %s\n", err)
		}

		if command.OutputOption() {
			if err := command.PrintOutput(res.GetPayload()); err != nil {
				Fatalf("error getting output in JSON: %s\n", err)
			}
		} else {
			printSummary(res.GetPayload())
		}
	},
}
View Source
var BgpRoutePoliciesCmd = &cobra.Command{
	Use:     "route-policies [vrouter <asn>]",
	Aliases: []string{"rps"},
	Short:   "List configured route policies",
	Long:    "List route policies configured in the underlying routing daemon",
	Run: func(cmd *cobra.Command, args []string) {
		var err error
		params := bgp.NewGetBgpRoutePoliciesParams()

		if len(args) > 0 {
			var asn int64
			asn, _, err = parseVRouterASN(args)
			if err != nil {
				Fatalf("failed to parse vrouter ASN: %s\n", err)
			}
			params.RouterAsn = pointer.Int64(asn)
		}

		res, err := client.Bgp.GetBgpRoutePolicies(params)
		if err != nil {
			disabledErr := bgp.NewGetBgpRoutePoliciesDisabled()
			if errors.As(err, &disabledErr) {
				fmt.Println("BGP Control Plane is disabled")
				return
			}
			Fatalf("cannot get route policies list: %s\n", err)
		}

		if command.OutputOption() {
			if err := command.PrintOutput(res.GetPayload()); err != nil {
				Fatalf("error getting output in JSON: %s\n", err)
			}
		} else {
			printBGPRoutePoliciesTable(res.GetPayload())
		}
	},
}
View Source
var BgpRoutesCmd = &cobra.Command{
	Use:   "routes <available | advertised> <afi> <safi> [vrouter <asn>] [peer|neighbor <address>]",
	Short: "List routes in the BGP Control Plane's RIBs",
	Long:  "List routes in the BGP Control Plane's Routing Information Bases (RIBs)",
	Example: `  Get all IPv4 unicast routes available:
    cilium-dbg bgp routes available ipv4 unicast

  Get all IPv6 unicast routes available for a specific vrouter:
    cilium-dbg bgp routes available ipv6 unicast vrouter 65001

  Get IPv4 unicast routes advertised to a specific peer:
    cilium-dbg bgp routes advertised ipv4 unicast peer 10.0.0.1`,

	Run: func(cmd *cobra.Command, args []string) {
		var err error
		params := bgp.NewGetBgpRoutesParams()

		params.TableType, params.Afi, params.Safi, args, err = parseBGPRoutesMandatoryArgs(args, command.OutputOption())
		if err != nil {
			Fatalf("invalid argument: %s\n", err)
		}

		if len(args) > 0 && args[0] == vRouterKW {
			var asn int64
			asn, args, err = parseVRouterASN(args)
			if err != nil {
				Fatalf("failed to parse vrouter ASN: %s\n", err)
			}
			params.RouterAsn = pointer.Int64(asn)
		}

		if params.TableType == adjRIBOutTableType && len(args) > 0 {
			addr, err := parseBGPPeerAddr(args)
			if err != nil {
				Fatalf("failed to parse peer address: %s\n", err)
			}
			params.Neighbor = &addr
		}

		res, err := client.Bgp.GetBgpRoutes(params)
		if err != nil {
			disabledErr := bgp.NewGetBgpRoutesDisabled()
			if errors.As(err, &disabledErr) {
				fmt.Println("BGP Control Plane is disabled")
				return
			}
			Fatalf("failed retrieving routes: %s\n", err)
		}

		if command.OutputOption() {
			if err := command.PrintOutput(res.GetPayload()); err != nil {
				Fatalf("failed getting output in JSON: %s\n", err)
			}
		} else {

			printPeer := (params.TableType == adjRIBOutTableType) && (params.Neighbor == nil || *params.Neighbor == "")
			printBGPRoutesTable(res.GetPayload(), printPeer)
		}
	},
}
View Source
var CgroupsCmd = &cobra.Command{
	Use:   "cgroups",
	Short: "Cgroup metadata",
}

CgroupsCmd represents the cgroups command

View Source
var CncryptCmd = &cobra.Command{
	Use:   "encrypt",
	Short: "Manage transparent encryption",
}

CncryptCmd represents the encrypt command

View Source
var EndpointCmd = &cobra.Command{
	Use:   "endpoint",
	Short: "Manage endpoints",
}

EndpointCmd represents the endpoint command

View Source
var IPCmd = &cobra.Command{
	Use:   "ip",
	Short: "Manage IP addresses and associated information",
}

IPCmd represents the ip command

View Source
var IdentityCmd = &cobra.Command{
	Use:   "identity",
	Short: "Manage security identities",
}

IdentityCmd represents the identity command

View Source
var LRPCmd = &cobra.Command{
	Use:   "lrp",
	Short: "Manage local redirect policies",
}

LRPCmd represents the lrp command

View Source
var MAPCmd = &cobra.Command{
	Use:   "map",
	Short: "Access userspace cached content of BPF maps",
}

MAPCmd represents the map command

View Source
var MetricsCmd = &cobra.Command{
	Use:   "metrics",
	Short: "Access metric status",
}

MetricsCmd represents the metrics command.

View Source
var MetricsListCmd = &cobra.Command{
	Use:   "list",
	Short: "List all metrics",
	Run: func(cmd *cobra.Command, args []string) {
		res, err := client.Metrics.GetMetrics(nil)
		if err != nil {
			Fatalf("Cannot get metrics list: %s", err)
		}

		re, err := regexp.Compile(matchPattern)
		if err != nil {
			Fatalf("Cannot compile regex: %s", err)
		}

		metrics := make([]*models.Metric, 0, len(res.Payload))
		for _, metric := range res.Payload {
			if re.MatchString(metric.Name) {
				metrics = append(metrics, metric)
			}
		}

		if command.OutputOption() {
			if err := command.PrintOutput(metrics); err != nil {
				os.Exit(1)
			}
			return
		}

		w := tabwriter.NewWriter(os.Stdout, 5, 0, 3, ' ', 0)

		fmt.Fprintln(w, "Metric\tLabels\tValue")
		for _, metric := range metrics {
			label := ""
			if len(metric.Labels) > 0 {
				labelArray := []string{}
				keys := make([]string, 0, len(metric.Labels))
				for k := range metric.Labels {
					keys = append(keys, k)
				}
				sort.Strings(keys)
				for _, k := range keys {
					labelArray = append(labelArray, fmt.Sprintf(`%s="%s"`, k, metric.Labels[k]))
				}
				label = strings.Join(labelArray, " ")
			}
			fmt.Fprintf(w, "%s\t%s\t%f\n", metric.Name, label, metric.Value)
		}
		w.Flush()
	},
}

MetricsListCmd dumps all metrics into stdout

View Source
var NodeCmd = &cobra.Command{
	Use:   "node",
	Short: "Manage cluster nodes",
}

NodeCmd represents the node command

View Source
var NodeIDCmd = &cobra.Command{
	Use:   "nodeid",
	Short: "List node IDs and associated information",
}

nodeidCmd represents the nodeid command

View Source
var PolicyCmd = &cobra.Command{
	Use:   "policy",
	Short: "Manage security policies",
}

PolicyCmd represents the policy command

View Source
var PreFilterCmd = &cobra.Command{
	Use:   "prefilter",
	Short: "Manage XDP CIDR filters",
}

PreFilterCmd represents the prefilter command

View Source
var PreflightCmd = &cobra.Command{
	Use:   "preflight",
	Short: "Cilium upgrade helper",
	Long:  `CLI to help upgrade cilium`,
}

PreflightCmd is the command used to manage preflight tasks for upgrades

View Source
var RecorderCmd = &cobra.Command{
	Use:   "recorder",
	Short: "Introspect or mangle pcap recorder",
}

RecorderCmd represents the recorder command

View Source
var RootCmd = &cobra.Command{
	Use:   "cilium-dbg",
	Short: "CLI",
	Long:  `CLI for interacting with the local Cilium Agent`,
}

RootCmd represents the base command when called without any subcommands

View Source
var ServiceCmd = &cobra.Command{
	Use:   "service",
	Short: "Manage services & loadbalancers",
}

ServiceCmd represents the service command

View Source
var StatedbCmd = &cobra.Command{
	Use:   "statedb",
	Short: "Inspect StateDB",
}

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func Fatalf

func Fatalf(msg string, args ...interface{})

Fatalf prints the Printf formatted message to stderr and exits the program Note: os.Exit(1) is not recoverable

func NewTabWriter

func NewTabWriter() *tabwriter.Writer

NewTabWriter initialises tabwriter.Writer with following defaults width 5 and padding 3

func TablePrinter

func TablePrinter(firstTitle, secondTitle string, data map[string][]string)

TablePrinter prints the map[string][]string, which is an usual representation of dumped BPF map, using tabwriter.

func Usagef

func Usagef(cmd *cobra.Command, msg string, args ...interface{})

Usagef prints the Printf formatted message to stderr, prints usage help and exits the program Note: os.Exit(1) is not recoverable

Types

type PolicyUpdateArgs

type PolicyUpdateArgs struct {
	// contains filtered or unexported fields
}

PolicyUpdateArgs is the parsed representation of a bpf policy {add,delete} command.

Source Files

Jump to

Keyboard shortcuts

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