Skip to content

Commit

Permalink
feat(kubectl): include eds when inspecting config-dump (#11583)
Browse files Browse the repository at this point in the history
* feat(kubectl): introduce a new flag to specify whether eds should be included

---------

Signed-off-by: Jay Chen <[email protected]>
  • Loading branch information
jijiechen authored Oct 18, 2024
1 parent 5d4b1e6 commit 515a8cb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions app/kumactl/cmd/completion/testdata/bash.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4267,6 +4267,7 @@ _kumactl_inspect_dataplane()

flags+=("--include=")
two_word_flags+=("--include")
flags+=("--include-eds")
flags+=("--mesh=")
two_word_flags+=("--mesh")
two_word_flags+=("-m")
Expand Down Expand Up @@ -5399,6 +5400,7 @@ _kumactl_inspect_zoneegress()
flags_with_completion=()
flags_completion=()

flags+=("--include-eds")
flags+=("--type=")
two_word_flags+=("--type")
flags+=("--api-timeout=")
Expand Down Expand Up @@ -5461,6 +5463,7 @@ _kumactl_inspect_zoneingress()
flags_with_completion=()
flags_completion=()

flags+=("--include-eds")
flags+=("--type=")
two_word_flags+=("--type")
flags+=("--api-timeout=")
Expand Down
7 changes: 6 additions & 1 deletion app/kumactl/cmd/inspect/inspect_dataplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func newInspectDataplaneCmd(pctx *cmd.RootContext) *cobra.Command {
panic("unable to parse template")
}
var configDump bool
var includeEDS bool
var inspectionType string
var shadow bool
var include []string
Expand All @@ -81,6 +82,9 @@ func newInspectDataplaneCmd(pctx *cmd.RootContext) *cobra.Command {
if len(include) > 0 && inspectionType != InspectionConfig {
return errors.New("flag '--include' can be used only when '--type=config'")
}
if includeEDS && inspectionType != InspectionTypeConfigDump {
return errors.New(fmt.Sprintf("flag '--include-eds' can be used only when '--type=%s'", InspectionTypeConfigDump))
}

client, err := pctx.CurrentInspectEnvoyProxyClient(mesh.DataplaneResourceTypeDescriptor)
if err != nil {
Expand All @@ -101,7 +105,7 @@ func newInspectDataplaneCmd(pctx *cmd.RootContext) *cobra.Command {
}
return tmpl.Execute(cmd.OutOrStdout(), entryList)
case InspectionTypeConfigDump:
bytes, err := client.ConfigDump(context.Background(), resourceKey)
bytes, err := client.ConfigDump(context.Background(), resourceKey, includeEDS)
if err != nil {
return err
}
Expand Down Expand Up @@ -136,6 +140,7 @@ func newInspectDataplaneCmd(pctx *cmd.RootContext) *cobra.Command {
cmd.PersistentFlags().StringVar(&inspectionType, "type", InspectionTypePolicies, kuma_cmd.UsageOptions("inspection type", InspectionTypePolicies, InspectionTypeConfigDump, InspectionTypeStats, InspectionTypeClusters, InspectionConfig))
cmd.PersistentFlags().BoolVar(&configDump, "config-dump", false, "if set then the command returns envoy config dump for provided dataplane")
_ = cmd.PersistentFlags().MarkDeprecated("config-dump", "use --type=config-dump")
cmd.PersistentFlags().BoolVar(&includeEDS, "include-eds", false, "include EDS when dumping envoy config for dataplane")
cmd.PersistentFlags().StringVarP(&pctx.Args.Mesh, "mesh", "m", "default", "mesh to use")
cmd.PersistentFlags().BoolVar(&shadow, "shadow", false, "when computing XDS config the CP takes into account policies with 'kuma.io/effect: shadow' label")
cmd.PersistentFlags().StringSliceVar(&include, "include", []string{}, "an array of extra fields to include in the response. When `include=diff` the server computes a diff in JSONPatch format between the XDS config returned in 'xds' and the current proxy XDS config.")
Expand Down
7 changes: 6 additions & 1 deletion app/kumactl/cmd/inspect/inspect_zoneegress.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const inspectZoneEgressError = "Policies are not applied on ZoneEgress, please u
func newInspectZoneEgressCmd(pctx *cmd.RootContext) *cobra.Command {
var configDump bool
var inspectionType string
var includeEDS bool
cmd := &cobra.Command{
Use: "zoneegress NAME",
Short: "Inspect ZoneEgress",
Expand All @@ -28,6 +29,9 @@ func newInspectZoneEgressCmd(pctx *cmd.RootContext) *cobra.Command {
if configDump {
inspectionType = InspectionTypeConfigDump
}
if includeEDS && inspectionType != InspectionTypeConfigDump {
return errors.New(fmt.Sprintf("flag '--include-eds' can be used only when '--type=%s'", InspectionTypeConfigDump))
}

client, err := pctx.CurrentInspectEnvoyProxyClient(mesh.ZoneEgressResourceTypeDescriptor)
if err != nil {
Expand All @@ -38,7 +42,7 @@ func newInspectZoneEgressCmd(pctx *cmd.RootContext) *cobra.Command {

switch inspectionType {
case InspectionTypeConfigDump:
bytes, err := client.ConfigDump(context.Background(), resourceKey)
bytes, err := client.ConfigDump(context.Background(), resourceKey, includeEDS)
if err != nil {
return err
}
Expand Down Expand Up @@ -67,6 +71,7 @@ func newInspectZoneEgressCmd(pctx *cmd.RootContext) *cobra.Command {
}
cmd.PersistentFlags().BoolVar(&configDump, "config-dump", false, "if set then the command returns envoy config dump for provided dataplane")
_ = cmd.PersistentFlags().MarkDeprecated("config-dump", "use --type=config-dump")
cmd.PersistentFlags().BoolVar(&includeEDS, "include-eds", false, "include EDS when dumping envoy config for dataplane")
cmd.PersistentFlags().StringVar(&inspectionType, "type", InspectionTypeConfigDump, kuma_cmd.UsageOptions("inspection type", InspectionTypeConfigDump, InspectionTypeStats, InspectionTypeClusters))
return cmd
}
7 changes: 6 additions & 1 deletion app/kumactl/cmd/inspect/inspect_zoneingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const inspectZoneIngressError = "Policies are not applied on ZoneIngress, please

func newInspectZoneIngressCmd(pctx *cmd.RootContext) *cobra.Command {
var configDump bool
var includeEDS bool
var inspectionType string
cmd := &cobra.Command{
Use: "zoneingress NAME",
Expand All @@ -28,6 +29,9 @@ func newInspectZoneIngressCmd(pctx *cmd.RootContext) *cobra.Command {
if configDump {
inspectionType = InspectionTypeConfigDump
}
if includeEDS && inspectionType != InspectionTypeConfigDump {
return errors.New(fmt.Sprintf("flag '--include-eds' can be used only when '--type=%s'", InspectionTypeConfigDump))
}

client, err := pctx.CurrentInspectEnvoyProxyClient(mesh.ZoneIngressResourceTypeDescriptor)
if err != nil {
Expand All @@ -38,7 +42,7 @@ func newInspectZoneIngressCmd(pctx *cmd.RootContext) *cobra.Command {

switch inspectionType {
case InspectionTypeConfigDump:
bytes, err := client.ConfigDump(context.Background(), resourceKey)
bytes, err := client.ConfigDump(context.Background(), resourceKey, includeEDS)
if err != nil {
return err
}
Expand Down Expand Up @@ -67,6 +71,7 @@ func newInspectZoneIngressCmd(pctx *cmd.RootContext) *cobra.Command {
}
cmd.PersistentFlags().BoolVar(&configDump, "config-dump", false, "if set then the command returns envoy config dump for provided dataplane")
_ = cmd.PersistentFlags().MarkDeprecated("config-dump", "use --type=config-dump")
cmd.PersistentFlags().BoolVar(&includeEDS, "include-eds", false, "include EDS when dumping envoy config for dataplane")
cmd.PersistentFlags().StringVar(&inspectionType, "type", InspectionTypeConfigDump, kuma_cmd.UsageOptions("inspection type", InspectionTypeConfigDump, InspectionTypeStats, InspectionTypeClusters))
return cmd
}
6 changes: 3 additions & 3 deletions app/kumactl/pkg/resources/inspect_envoy_proxy_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

type InspectEnvoyProxyClient interface {
ConfigDump(ctx context.Context, rk core_model.ResourceKey) ([]byte, error)
ConfigDump(ctx context.Context, rk core_model.ResourceKey, includeEDS bool) ([]byte, error)
Stats(ctx context.Context, rk core_model.ResourceKey) ([]byte, error)
Clusters(ctx context.Context, rk core_model.ResourceKey) ([]byte, error)
Config(ctx context.Context, rk core_model.ResourceKey, shadow bool, include []string) ([]byte, error)
Expand All @@ -35,8 +35,8 @@ type httpInspectEnvoyProxyClient struct {

var _ InspectEnvoyProxyClient = &httpInspectEnvoyProxyClient{}

func (h *httpInspectEnvoyProxyClient) ConfigDump(ctx context.Context, rk core_model.ResourceKey) ([]byte, error) {
return h.executeInspectRequest(ctx, rk, "xds", url.Values{})
func (h *httpInspectEnvoyProxyClient) ConfigDump(ctx context.Context, rk core_model.ResourceKey, includeEDS bool) ([]byte, error) {
return h.executeInspectRequest(ctx, rk, "xds", url.Values{"include_eds": {strconv.FormatBool(includeEDS)}})
}

func (h *httpInspectEnvoyProxyClient) Stats(ctx context.Context, rk core_model.ResourceKey) ([]byte, error) {
Expand Down

0 comments on commit 515a8cb

Please sign in to comment.