Skip to content

Commit a1f92c7

Browse files
authored
Merge pull request #29098 from r-vasquez/shadow-template-for-cloud
[UX-747] rpk shadow: enable --print-template for cloud
2 parents 130ffe5 + e2e6176 commit a1f92c7

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/go/rpk/pkg/cli/shadow/config.go

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Save the template with documentation to a file:
8484
Run: func(_ *cobra.Command, _ []string) {
8585
var outputData, successMsg string
8686
if printTemplate {
87-
template := generateConfigTemplate()
87+
template := generateConfigTemplate(cloud)
8888
outputData = template
8989
successMsg = "Template file generated successfully: %s\n"
9090
} else {
@@ -225,10 +225,28 @@ func generateSampleConfig(cloud bool) *ShadowLinkConfig {
225225
return slCfg
226226
}
227227

228-
func generateConfigTemplate() string {
228+
func generateConfigTemplate(cloud bool) string {
229229
var sb strings.Builder
230230

231-
sb.WriteString("# Shadow Link Configuration Template\n")
231+
if cloud {
232+
sb.WriteString("# Shadow Link Configuration Template for Redpanda Cloud\n")
233+
} else {
234+
sb.WriteString("# Shadow Link Configuration Template\n")
235+
}
236+
237+
// Manually add name field (not in ShadowLinkConfigurations proto, but in ShadowLink)
238+
sb.WriteString("# The name of the shadow link\n")
239+
sb.WriteString("name: \"\"\n")
240+
241+
// Inject cloud_options manually (not in admin/v2 proto)
242+
if cloud {
243+
sb.WriteString("# Configurations for Shadow Link in Redpanda Cloud\n")
244+
sb.WriteString("cloud_options:\n")
245+
sb.WriteString(" # The ID of the source Redpanda Cloud cluster (optional)\n")
246+
sb.WriteString(" source_redpanda_id: \"\"\n")
247+
sb.WriteString(" # The ID of the shadow Redpanda Cloud cluster\n")
248+
sb.WriteString(" shadow_redpanda_id: \"\"\n\n")
249+
}
232250

233251
// Get the message descriptor from the global registry
234252
cfg := &v2.ShadowLinkConfigurations{}
@@ -252,7 +270,7 @@ func generateConfigTemplate() string {
252270
continue
253271
}
254272

255-
writeFieldTemplate(&sb, field, 0)
273+
writeFieldTemplate(&sb, field, 0, cloud)
256274
}
257275

258276
return sb.String()
@@ -331,7 +349,12 @@ func toScreamingSnakeCase(s string) string {
331349
return strings.ToUpper(result.String())
332350
}
333351

334-
func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, indent int) {
352+
func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor, indent int, cloud bool) {
353+
// Skip tls_file_settings for Cloud (only tls_pem_settings is valid)
354+
if cloud && string(field.Name()) == "tls_file_settings" {
355+
return
356+
}
357+
335358
indentStr := strings.Repeat(" ", indent)
336359

337360
// Get field comment using the appropriate package registry
@@ -373,7 +396,7 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor,
373396
continue
374397
}
375398

376-
writeFieldTemplate(sb, nestedField, indent+2)
399+
writeFieldTemplate(sb, nestedField, indent+2, cloud)
377400
}
378401
} else {
379402
// List of scalars
@@ -409,7 +432,7 @@ func writeFieldTemplate(sb *strings.Builder, field protoreflect.FieldDescriptor,
409432
continue
410433
}
411434

412-
writeFieldTemplate(sb, nestedField, indent+1)
435+
writeFieldTemplate(sb, nestedField, indent+1, cloud)
413436
}
414437
}
415438
} else {

src/go/rpk/pkg/cli/shadow/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ type ShadowLinkConfig struct {
3131
}
3232

3333
type CloudShadowLinkOptions struct {
34+
// Source Redpanda cluster ID. This field is optional. If provided, fetches
35+
// bootstrap server information.
3436
SourceRedpandaID string `json:"source_redpanda_id,omitempty" yaml:"source_redpanda_id,omitempty"`
37+
// Shadow Redpanda cluster ID where the shadow link will be created.
3538
ShadowRedpandaID string `json:"shadow_redpanda_id,omitempty" yaml:"shadow_redpanda_id,omitempty"`
3639
}
3740

0 commit comments

Comments
 (0)