Skip to content

Commit

Permalink
Add tests for unmarshaling and remarshaling configs for rpk.schema_re…
Browse files Browse the repository at this point in the history
…gistry in redpanda.yaml
  • Loading branch information
andrewstucki committed Nov 6, 2024
1 parent 3dc87d8 commit 7965711
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 31 deletions.
8 changes: 3 additions & 5 deletions src/go/rpk/pkg/config/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,9 @@ func (c *Config) ensureBrokerAddrs() {
if len(dst.Rpk.AdminAPI.Addresses) == 0 {
dst.Rpk.AdminAPI.Addresses = []string{net.JoinHostPort("127.0.0.1", strconv.Itoa(DefaultAdminPort))}
}
if len(dst.Rpk.SR.Addresses) == 0 {
dst.Rpk.SR.Addresses = []string{net.JoinHostPort("127.0.0.1", strconv.Itoa(DefaultSchemaRegPort))}
}
}
{
dst := c.rpkYaml.Profile(c.rpkYaml.CurrentProfile) // must exist by this function
Expand All @@ -1450,11 +1453,6 @@ func (c *Config) ensureBrokerAddrs() {
if len(dst.AdminAPI.Addresses) == 0 {
dst.AdminAPI.Addresses = []string{net.JoinHostPort("127.0.0.1", strconv.Itoa(DefaultAdminPort))}
}
}
{
dst := c.rpkYaml.Profile(c.rpkYaml.CurrentProfile)
// Schema Registry is only supported in profiles. Not in old rpk section
// of our redpanda.yaml
if len(dst.SR.Addresses) == 0 {
dst.SR.Addresses = []string{net.JoinHostPort("127.0.0.1", strconv.Itoa(DefaultSchemaRegPort))}
}
Expand Down
41 changes: 38 additions & 3 deletions src/go/rpk/pkg/config/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ rpk:
admin_api:
addresses:
- 127.0.0.1:9644
schema_registry:
addresses:
- 127.0.0.1:8081
`,
},
{
Expand Down Expand Up @@ -100,6 +103,9 @@ rpk:
- 127.0.0.1:4444
- 10.0.0.1:4444
- 122.65.33.12:4444
schema_registry:
addresses:
- 127.0.0.1:8081
`,
},
{
Expand All @@ -117,6 +123,9 @@ rpk:
kafka_api:
brokers:
- 127.0.0.1:9092
schema_registry:
addresses:
- 127.0.0.1:8081
`,
exp: `redpanda:
seed_servers: []
Expand All @@ -131,6 +140,9 @@ rpk:
kafka_api:
brokers:
- 127.0.0.1:9092
schema_registry:
addresses:
- 127.0.0.1:8081
`,
},
{
Expand All @@ -151,6 +163,9 @@ rpk:
kafka_api:
brokers:
- 127.0.0.1:9092
schema_registry:
addresses:
- 127.0.0.1:8081
`,
exp: `redpanda:
data_directory: /var/lib/redpanda/data
Expand All @@ -168,6 +183,9 @@ rpk:
admin_api:
addresses:
- 127.0.0.1:9644
schema_registry:
addresses:
- 127.0.0.1:8081
`,
},
}
Expand Down Expand Up @@ -718,6 +736,9 @@ rpk:
admin_api:
addresses:
- 127.0.0.1:9644
schema_registry:
addresses:
- 127.0.0.1:8081
overprovisioned: true
coredump_dir: /var/lib/redpanda/coredump
pandaproxy: {}
Expand Down Expand Up @@ -781,6 +802,9 @@ cloud_auth:
- address: 0.0.0.3
port: 9092
rpk:
schema_registry:
addresses:
- 127.0.0.1:3232
enable_memory_locking: true
tune_network: true
tune_disk_scheduler: true
Expand Down Expand Up @@ -808,6 +832,9 @@ rpk:
admin_api:
addresses:
- 0.0.0.3:9644
schema_registry:
addresses:
- 127.0.0.1:3232
enable_memory_locking: true
tune_network: true
tune_disk_scheduler: true
Expand Down Expand Up @@ -841,7 +868,7 @@ profiles:
- 0.0.0.3:9644
schema_registry:
addresses:
- 127.0.0.1:8081
- 127.0.0.1:3232
cloud_auth:
- name: default
organization: Default organization
Expand Down Expand Up @@ -971,6 +998,9 @@ cloud_auth:
- address: admin.com
port: 4444
rpk:
schema_registry:
addresses:
- 127.0.0.1:8081
enable_memory_locking: true
tune_network: true
tune_disk_scheduler: true
Expand Down Expand Up @@ -1000,7 +1030,9 @@ profiles:
brokers:
- 128.0.0.4
admin_api: {}
schema_registry: {}
schema_registry:
addresses:
- 127.0.0.1:3232
cloud_auth: []
`,

Expand All @@ -1020,6 +1052,9 @@ rpk:
admin_api:
addresses:
- 128.0.0.4:9644
schema_registry:
addresses:
- 127.0.0.1:3232
enable_memory_locking: true
tune_network: true
tune_disk_scheduler: true
Expand Down Expand Up @@ -1054,7 +1089,7 @@ profiles:
- 128.0.0.4:9644
schema_registry:
addresses:
- 127.0.0.1:8081
- 127.0.0.1:3232
cloud_auth:
- name: default
organization: Default organization
Expand Down
64 changes: 41 additions & 23 deletions src/go/rpk/pkg/config/weak.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,29 +411,30 @@ func (rpkc *RpkNodeConfig) UnmarshalYAML(n *yaml.Node) error {
// Deprecated 2021-07-1
SASL *SASL `yaml:"sasl"`

KafkaAPI RpkKafkaAPI `yaml:"kafka_api"`
AdminAPI RpkAdminAPI `yaml:"admin_api"`
AdditionalStartFlags weakStringArray `yaml:"additional_start_flags"`
TuneNetwork weakBool `yaml:"tune_network"`
TuneDiskScheduler weakBool `yaml:"tune_disk_scheduler"`
TuneNomerges weakBool `yaml:"tune_disk_nomerges"`
TuneDiskWriteCache weakBool `yaml:"tune_disk_write_cache"`
TuneDiskIrq weakBool `yaml:"tune_disk_irq"`
TuneFstrim weakBool `yaml:"tune_fstrim"`
TuneCPU weakBool `yaml:"tune_cpu"`
TuneAioEvents weakBool `yaml:"tune_aio_events"`
TuneClocksource weakBool `yaml:"tune_clocksource"`
TuneSwappiness weakBool `yaml:"tune_swappiness"`
TuneTransparentHugePages weakBool `yaml:"tune_transparent_hugepages"`
EnableMemoryLocking weakBool `yaml:"enable_memory_locking"`
TuneCoredump weakBool `yaml:"tune_coredump"`
CoredumpDir weakString `yaml:"coredump_dir"`
TuneBallastFile weakBool `yaml:"tune_ballast_file"`
BallastFilePath weakString `yaml:"ballast_file_path"`
BallastFileSize weakString `yaml:"ballast_file_size"`
WellKnownIo weakString `yaml:"well_known_io"`
Overprovisioned weakBool `yaml:"overprovisioned"`
SMP *weakInt `yaml:"smp"`
KafkaAPI RpkKafkaAPI `yaml:"kafka_api"`
AdminAPI RpkAdminAPI `yaml:"admin_api"`
SR RpkSchemaRegistryAPI `yaml:"schema_registry"`
AdditionalStartFlags weakStringArray `yaml:"additional_start_flags"`
TuneNetwork weakBool `yaml:"tune_network"`
TuneDiskScheduler weakBool `yaml:"tune_disk_scheduler"`
TuneNomerges weakBool `yaml:"tune_disk_nomerges"`
TuneDiskWriteCache weakBool `yaml:"tune_disk_write_cache"`
TuneDiskIrq weakBool `yaml:"tune_disk_irq"`
TuneFstrim weakBool `yaml:"tune_fstrim"`
TuneCPU weakBool `yaml:"tune_cpu"`
TuneAioEvents weakBool `yaml:"tune_aio_events"`
TuneClocksource weakBool `yaml:"tune_clocksource"`
TuneSwappiness weakBool `yaml:"tune_swappiness"`
TuneTransparentHugePages weakBool `yaml:"tune_transparent_hugepages"`
EnableMemoryLocking weakBool `yaml:"enable_memory_locking"`
TuneCoredump weakBool `yaml:"tune_coredump"`
CoredumpDir weakString `yaml:"coredump_dir"`
TuneBallastFile weakBool `yaml:"tune_ballast_file"`
BallastFilePath weakString `yaml:"ballast_file_path"`
BallastFileSize weakString `yaml:"ballast_file_size"`
WellKnownIo weakString `yaml:"well_known_io"`
Overprovisioned weakBool `yaml:"overprovisioned"`
SMP *weakInt `yaml:"smp"`
}
if err := n.Decode(&internal); err != nil {
return err
Expand All @@ -442,6 +443,7 @@ func (rpkc *RpkNodeConfig) UnmarshalYAML(n *yaml.Node) error {
// backcompat, immediately convert to new tls
rpkc.KafkaAPI = internal.KafkaAPI
rpkc.AdminAPI = internal.AdminAPI
rpkc.SR = internal.SR
if rpkc.KafkaAPI.TLS == nil {
rpkc.KafkaAPI.TLS = internal.TLS
}
Expand All @@ -451,6 +453,9 @@ func (rpkc *RpkNodeConfig) UnmarshalYAML(n *yaml.Node) error {
if rpkc.AdminAPI.TLS == nil {
rpkc.AdminAPI.TLS = internal.TLS
}
if rpkc.SR.TLS == nil {
rpkc.SR.TLS = internal.TLS
}
rpkc.AdditionalStartFlags = internal.AdditionalStartFlags
rpkc.EnableMemoryLocking = bool(internal.EnableMemoryLocking)
rpkc.Overprovisioned = bool(internal.Overprovisioned)
Expand Down Expand Up @@ -503,6 +508,19 @@ func (r *RpkAdminAPI) UnmarshalYAML(n *yaml.Node) error {
return nil
}

func (r *RpkSchemaRegistryAPI) UnmarshalYAML(n *yaml.Node) error {
var internal struct {
Addresses weakStringArray `yaml:"addresses"`
TLS *TLS `yaml:"tls"`
}
if err := n.Decode(&internal); err != nil {
return err
}
r.Addresses = internal.Addresses
r.TLS = internal.TLS
return nil
}

func (p *Pandaproxy) UnmarshalYAML(n *yaml.Node) error {
var internal struct {
PandaproxyAPI namedAuthNSocketAddresses `yaml:"pandaproxy_api"`
Expand Down
22 changes: 22 additions & 0 deletions src/go/rpk/pkg/config/weak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,13 @@ rpk:
tls:
cert_file: ~/certs/admin-cert.pem
truststore_file: ~/certs/admin-ca.pem
schema_registry:
addresses:
- 192.168.72.34:8081
- 192.168.72.35:8081
tls:
cert_file: ~/certs/admin-cert.pem
truststore_file: ~/certs/admin-ca.pem
tune_network: false
tune_disk_scheduler: false
tune_cpu: true
Expand Down Expand Up @@ -1071,6 +1078,10 @@ rpk:
Addresses: []string{"192.168.72.34:9644", "192.168.72.35:9644"},
TLS: &TLS{CertFile: "~/certs/admin-cert.pem", TruststoreFile: "~/certs/admin-ca.pem"},
},
SR: RpkSchemaRegistryAPI{
Addresses: []string{"192.168.72.34:8081", "192.168.72.35:8081"},
TLS: &TLS{CertFile: "~/certs/admin-cert.pem", TruststoreFile: "~/certs/admin-ca.pem"},
},
Tuners: RpkNodeTuners{
TuneNetwork: false,
TuneDiskScheduler: false,
Expand Down Expand Up @@ -1293,6 +1304,13 @@ rpk:
tls:
cert_file: ~/certs/admin-cert.pem
truststore_file: ~/certs/admin-ca.pem
schema_registry:
addresses:
- 192.168.72.34:8081
- 192.168.72.35:8081
tls:
cert_file: ~/certs/admin-cert.pem
truststore_file: ~/certs/admin-ca.pem
tune_network: false
tune_disk_scheduler: false
tune_cpu: 1
Expand Down Expand Up @@ -1390,6 +1408,10 @@ rpk:
Addresses: []string{"192.168.72.34:9644", "192.168.72.35:9644"},
TLS: &TLS{CertFile: "~/certs/admin-cert.pem", TruststoreFile: "~/certs/admin-ca.pem"},
},
SR: RpkSchemaRegistryAPI{
Addresses: []string{"192.168.72.34:8081", "192.168.72.35:8081"},
TLS: &TLS{CertFile: "~/certs/admin-cert.pem", TruststoreFile: "~/certs/admin-ca.pem"},
},
Tuners: RpkNodeTuners{
TuneNetwork: false,
TuneDiskScheduler: false,
Expand Down

0 comments on commit 7965711

Please sign in to comment.