From e2e617612a3cd00a350e36d50077d8f1c1769456 Mon Sep 17 00:00:00 2001 From: Rogger Vasquez Date: Mon, 22 Dec 2025 14:54:45 -0800 Subject: [PATCH] rpk shadow: enable --print-template for cloud We chose to manually inject the string instead of generating a full comment registry for just 2 fields. If the configuration for cloud expands we can revisit this mechanism. --- src/go/rpk/pkg/cli/shadow/config.go | 37 +++++++++++++++++++++++------ src/go/rpk/pkg/cli/shadow/types.go | 3 +++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/go/rpk/pkg/cli/shadow/config.go b/src/go/rpk/pkg/cli/shadow/config.go index 405e970787447..20b4212978ebd 100644 --- a/src/go/rpk/pkg/cli/shadow/config.go +++ b/src/go/rpk/pkg/cli/shadow/config.go @@ -84,7 +84,7 @@ Save the template with documentation to a file: Run: func(_ *cobra.Command, _ []string) { var outputData, successMsg string if printTemplate { - template := generateConfigTemplate() + template := generateConfigTemplate(cloud) outputData = template successMsg = "Template file generated successfully: %s\n" } else { @@ -225,10 +225,28 @@ func generateSampleConfig(cloud bool) *ShadowLinkConfig { return slCfg } -func generateConfigTemplate() string { +func generateConfigTemplate(cloud bool) string { var sb strings.Builder - sb.WriteString("# Shadow Link Configuration Template\n") + if cloud { + sb.WriteString("# Shadow Link Configuration Template for Redpanda Cloud\n") + } else { + sb.WriteString("# Shadow Link Configuration Template\n") + } + + // Manually add name field (not in ShadowLinkConfigurations proto, but in ShadowLink) + sb.WriteString("# The name of the shadow link\n") + sb.WriteString("name: \"\"\n") + + // Inject cloud_options manually (not in admin/v2 proto) + if cloud { + sb.WriteString("# Configurations for Shadow Link in Redpanda Cloud\n") + sb.WriteString("cloud_options:\n") + sb.WriteString(" # The ID of the source Redpanda Cloud cluster (optional)\n") + sb.WriteString(" source_redpanda_id: \"\"\n") + sb.WriteString(" # The ID of the shadow Redpanda Cloud cluster\n") + sb.WriteString(" shadow_redpanda_id: \"\"\n\n") + } // Get the message descriptor from the global registry cfg := &v2.ShadowLinkConfigurations{} @@ -252,7 +270,7 @@ func generateConfigTemplate() string { continue } - writeFieldTemplate(&sb, field, 0) + writeFieldTemplate(&sb, field, 0, cloud) } return sb.String() @@ -331,7 +349,12 @@ func toScreamingSnakeCase(s string) string { return strings.ToUpper(result.String()) } -func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, indent int) { +func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, indent int, cloud bool) { + // Skip tls_file_settings for Cloud (only tls_pem_settings is valid) + if cloud && string(field.Name()) == "tls_file_settings" { + return + } + indentStr := strings.Repeat(" ", indent) // Get field comment using the appropriate package registry @@ -373,7 +396,7 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, continue } - writeFieldTemplate(sb, nestedField, indent+2) + writeFieldTemplate(sb, nestedField, indent+2, cloud) } } else { // List of scalars @@ -409,7 +432,7 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, continue } - writeFieldTemplate(sb, nestedField, indent+1) + writeFieldTemplate(sb, nestedField, indent+1, cloud) } } } else { diff --git a/src/go/rpk/pkg/cli/shadow/types.go b/src/go/rpk/pkg/cli/shadow/types.go index c1251fee3bc2d..01d12e638aad2 100644 --- a/src/go/rpk/pkg/cli/shadow/types.go +++ b/src/go/rpk/pkg/cli/shadow/types.go @@ -31,7 +31,10 @@ type ShadowLinkConfig struct { } type CloudShadowLinkOptions struct { + // Source Redpanda cluster ID. This field is optional. If provided, fetches + // bootstrap server information. SourceRedpandaID string `json:"source_redpanda_id,omitempty" yaml:"source_redpanda_id,omitempty"` + // Shadow Redpanda cluster ID where the shadow link will be created. ShadowRedpandaID string `json:"shadow_redpanda_id,omitempty" yaml:"shadow_redpanda_id,omitempty"` }