Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpk: sample config to include empty structs #5503

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conf/redpanda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ redpanda:
developer_mode: true

# Enable Pandaproxy
pandaproxy:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the {} are now required, does that mean that we still have a backwards compatibility issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat.

Old versions are already converted to using {} through old rpk. The only problem will be if somebody uses an old redpanda.yaml that has never been touched by rpk, with the new rpk.

pandaproxy: {}

# Enable Schema Registry
schema_registry:
schema_registry: {}

rpk:
# TLS configuration.
Expand Down
101 changes: 101 additions & 0 deletions src/go/rpk/pkg/config/params_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package config

import (
"os"
"strings"
"testing"

"github.com/spf13/afero"
"github.com/stretchr/testify/require"
)

func TestParams_Write(t *testing.T) {
Expand Down Expand Up @@ -129,3 +131,102 @@ rpk:
})
}
}

func TestRedpandaSampleFile(t *testing.T) {
// Config from 'redpanda/conf/redpanda.yaml'.
sample, err := os.ReadFile("../../../../../conf/redpanda.yaml")
if err != nil {
t.Errorf("unexpected error while reading sample config file: %s", err)
return
}
fs := afero.NewMemMapFs()
err = afero.WriteFile(fs, "/etc/redpanda/redpanda.yaml", sample, 0o644)
if err != nil {
t.Errorf("unexpected error while writing sample config file: %s", err)
return
}
expCfg := &Config{
ConfigFile: "/etc/redpanda/redpanda.yaml",
loadedPath: "/etc/redpanda/redpanda.yaml",
Redpanda: RedpandaConfig{
Directory: "/var/lib/redpanda/data",
RPCServer: SocketAddress{
Address: "0.0.0.0",
Port: 33145,
},
KafkaAPI: []NamedSocketAddress{{
Address: "0.0.0.0",
Port: 9092,
}},
AdminAPI: []NamedSocketAddress{{
Address: "0.0.0.0",
Port: 9644,
}},
ID: 1,
SeedServers: []SeedServer{},
DeveloperMode: true,
},
Rpk: RpkConfig{
CoredumpDir: "/var/lib/redpanda/coredump",
EnableUsageStats: true,
},
Pandaproxy: &Pandaproxy{},
SchemaRegistry: &SchemaRegistry{},
}
// Load and check we load it correctly
cfg, err := new(Params).Load(fs)
if err != nil {
t.Errorf("unexpected error while loading sample config file: %s", err)
return
}
cfg = cfg.FileOrDefaults() // we want to check that we correctly load the raw file
require.Equal(t, expCfg, cfg)

// Write to the file and check we don't mangle the config properties
err = cfg.Write(fs)
if err != nil {
t.Errorf("unexpected error while writing config file: %s", err)
return
}
file, err := afero.ReadFile(fs, "/etc/redpanda/redpanda.yaml")
if err != nil {
t.Errorf("unexpected error while reading config file from fs: %s", err)
return
}
require.Equal(t, `config_file: /etc/redpanda/redpanda.yaml
redpanda:
data_directory: /var/lib/redpanda/data
node_id: 1
seed_servers: []
rpc_server:
address: 0.0.0.0
port: 33145
kafka_api:
- address: 0.0.0.0
port: 9092
admin:
- address: 0.0.0.0
port: 9644
developer_mode: true
rpk:
enable_usage_stats: true
tune_network: false
tune_disk_scheduler: false
tune_disk_nomerges: false
tune_disk_write_cache: false
tune_disk_irq: false
tune_fstrim: false
tune_cpu: false
tune_aio_events: false
tune_clocksource: false
tune_swappiness: false
tune_transparent_hugepages: false
enable_memory_locking: false
tune_coredump: false
coredump_dir: /var/lib/redpanda/coredump
tune_ballast_file: false
overprovisioned: false
pandaproxy: {}
schema_registry: {}
`, string(file))
}