Skip to content

Commit

Permalink
Merge pull request #5503 from r-vasquez/fix-enable-by-default-sr
Browse files Browse the repository at this point in the history
rpk: sample config to include empty structs
  • Loading branch information
twmb committed Jul 19, 2022
2 parents 5808440 + 7551561 commit dca215d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
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:
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))
}

0 comments on commit dca215d

Please sign in to comment.