From 515a8cbb6ed6e7f5657fc2257a00595b1c38aa01 Mon Sep 17 00:00:00 2001 From: Jay Jijie Chen <1180092+jijiechen@users.noreply.github.com> Date: Fri, 18 Oct 2024 10:23:13 +0800 Subject: [PATCH] feat(kubectl): include eds when inspecting config-dump (#11583) * feat(kubectl): introduce a new flag to specify whether eds should be included --------- Signed-off-by: Jay Chen <1180092+jijiechen@users.noreply.github.com> --- app/kumactl/cmd/completion/testdata/bash.golden | 3 +++ app/kumactl/cmd/inspect/inspect_dataplane.go | 7 ++++++- app/kumactl/cmd/inspect/inspect_zoneegress.go | 7 ++++++- app/kumactl/cmd/inspect/inspect_zoneingress.go | 7 ++++++- app/kumactl/pkg/resources/inspect_envoy_proxy_client.go | 6 +++--- 5 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/kumactl/cmd/completion/testdata/bash.golden b/app/kumactl/cmd/completion/testdata/bash.golden index e47defc100df..ad3c9b3f1f2f 100644 --- a/app/kumactl/cmd/completion/testdata/bash.golden +++ b/app/kumactl/cmd/completion/testdata/bash.golden @@ -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") @@ -5399,6 +5400,7 @@ _kumactl_inspect_zoneegress() flags_with_completion=() flags_completion=() + flags+=("--include-eds") flags+=("--type=") two_word_flags+=("--type") flags+=("--api-timeout=") @@ -5461,6 +5463,7 @@ _kumactl_inspect_zoneingress() flags_with_completion=() flags_completion=() + flags+=("--include-eds") flags+=("--type=") two_word_flags+=("--type") flags+=("--api-timeout=") diff --git a/app/kumactl/cmd/inspect/inspect_dataplane.go b/app/kumactl/cmd/inspect/inspect_dataplane.go index b3ac8bb9294b..8b2eca47c320 100644 --- a/app/kumactl/cmd/inspect/inspect_dataplane.go +++ b/app/kumactl/cmd/inspect/inspect_dataplane.go @@ -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 @@ -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 { @@ -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 } @@ -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.") diff --git a/app/kumactl/cmd/inspect/inspect_zoneegress.go b/app/kumactl/cmd/inspect/inspect_zoneegress.go index 6d978be9ac80..e1cd1d298d85 100644 --- a/app/kumactl/cmd/inspect/inspect_zoneegress.go +++ b/app/kumactl/cmd/inspect/inspect_zoneegress.go @@ -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", @@ -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 { @@ -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 } @@ -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 } diff --git a/app/kumactl/cmd/inspect/inspect_zoneingress.go b/app/kumactl/cmd/inspect/inspect_zoneingress.go index 292e2da1f161..519dc527055f 100644 --- a/app/kumactl/cmd/inspect/inspect_zoneingress.go +++ b/app/kumactl/cmd/inspect/inspect_zoneingress.go @@ -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", @@ -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 { @@ -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 } @@ -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 } diff --git a/app/kumactl/pkg/resources/inspect_envoy_proxy_client.go b/app/kumactl/pkg/resources/inspect_envoy_proxy_client.go index 14fc7b8ad9ac..e699e5941163 100644 --- a/app/kumactl/pkg/resources/inspect_envoy_proxy_client.go +++ b/app/kumactl/pkg/resources/inspect_envoy_proxy_client.go @@ -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) @@ -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) {