From f93dd0ddaef02701133d0edca7ad76dab3f5ccd8 Mon Sep 17 00:00:00 2001 From: rasta-rocket Date: Fri, 26 Jun 2026 12:09:50 +0200 Subject: [PATCH 1/2] fix(config): seed --catalog-name from default-catalog in config file When a config file set `default-catalog` to a non-"default" name, the CLI would silently ignore it because ParseConfig was called with the flag's default value of "default" before the config was consulted. Add ParseDefaultCatalog and apply it in main before the catalog lookup, so the config file's default-catalog seeds args.CatalogName when the flag is not explicitly passed on the command line. --- cmd/iceberg/main.go | 8 +++++++- config/config.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cmd/iceberg/main.go b/cmd/iceberg/main.go index d324ad9e2..260d9314b 100644 --- a/cmd/iceberg/main.go +++ b/cmd/iceberg/main.go @@ -236,7 +236,13 @@ func main() { } } - fileCfg := config.ParseConfig(config.LoadConfig(args.Config), args.CatalogName) + configData := config.LoadConfig(args.Config) + if !explicitFlags["catalog-name"] { + if defaultCatalog := config.ParseDefaultCatalog(configData); defaultCatalog != "" { + args.CatalogName = defaultCatalog + } + } + fileCfg := config.ParseConfig(configData, args.CatalogName) if fileCfg != nil { mergeConf(fileCfg, &args, explicitFlags) } diff --git a/config/config.go b/config/config.go index 4fbf2ef83..4c6288366 100644 --- a/config/config.go +++ b/config/config.go @@ -69,6 +69,15 @@ func LoadConfig(configPath string) []byte { return file } +func ParseDefaultCatalog(file []byte) string { + var config Config + if err := yaml.Unmarshal(file, &config); err != nil { + return "" + } + + return config.DefaultCatalog +} + func ParseConfig(file []byte, catalogName string) *CatalogConfig { var config Config err := yaml.Unmarshal(file, &config) From e0c19e22feed06ec6d46b5d459c0140b656c25a2 Mon Sep 17 00:00:00 2001 From: rasta-rocket Date: Sun, 28 Jun 2026 16:37:30 +0200 Subject: [PATCH 2/2] apply PR feedbacks --- cmd/iceberg/main.go | 11 ++++++----- config/config.go | 22 ++++++++++++---------- config/config_test.go | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 18 deletions(-) diff --git a/cmd/iceberg/main.go b/cmd/iceberg/main.go index 260d9314b..9d4ecdadf 100644 --- a/cmd/iceberg/main.go +++ b/cmd/iceberg/main.go @@ -237,12 +237,13 @@ func main() { } configData := config.LoadConfig(args.Config) - if !explicitFlags["catalog-name"] { - if defaultCatalog := config.ParseDefaultCatalog(configData); defaultCatalog != "" { - args.CatalogName = defaultCatalog - } + // Pass the catalog name only when it was set explicitly on the command line; otherwise + // pass "" so ParseConfig resolves it from the file's default-catalog. Explicit wins. + lookupName := "" + if explicitFlags["catalog-name"] { + lookupName = args.CatalogName } - fileCfg := config.ParseConfig(configData, args.CatalogName) + fileCfg := config.ParseConfig(configData, lookupName) if fileCfg != nil { mergeConf(fileCfg, &args, explicitFlags) } diff --git a/config/config.go b/config/config.go index 4c6288366..e9d7e93e4 100644 --- a/config/config.go +++ b/config/config.go @@ -69,21 +69,23 @@ func LoadConfig(configPath string) []byte { return file } -func ParseDefaultCatalog(file []byte) string { +// ParseConfig unmarshals the config file once and resolves the catalog to use. +// When catalogName is empty, it falls back to the file's default-catalog field and +// then to the built-in "default" name. It returns the matching CatalogConfig, or +// nil if no such catalog is defined in the file. +func ParseConfig(file []byte, catalogName string) *CatalogConfig { var config Config if err := yaml.Unmarshal(file, &config); err != nil { - return "" + return nil } - return config.DefaultCatalog -} - -func ParseConfig(file []byte, catalogName string) *CatalogConfig { - var config Config - err := yaml.Unmarshal(file, &config) - if err != nil { - return nil + if catalogName == "" { + catalogName = config.DefaultCatalog } + if catalogName == "" { + catalogName = "default" + } + res, ok := config.Catalogs[catalogName] if !ok { return nil diff --git a/config/config_test.go b/config/config_test.go index c07540613..bb12b4dd0 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -28,9 +28,9 @@ var testArgs = []struct { catName string expected *CatalogConfig }{ - // config file does not exist - {nil, "default", nil}, - // config does not have default catalog + // config file does not exist; empty name falls back to built-in "default" + {nil, "", nil}, + // config does not have requested catalog {[]byte(` catalog: custom-catalog: @@ -102,6 +102,39 @@ catalog: }, }, }, + // empty name resolves via the file's default-catalog field + { + []byte(` +default-catalog: custom-catalog +catalog: + custom-catalog: + type: rest + uri: http://localhost:8181/ + warehouse: my_wh +`), "", + &CatalogConfig{ + CatalogType: "rest", + URI: "http://localhost:8181/", + Warehouse: "my_wh", + }, + }, + // explicit name takes precedence over the file's default-catalog + { + []byte(` +default-catalog: custom-catalog +catalog: + custom-catalog: + type: rest + uri: http://localhost:8181/ + other: + type: rest + uri: http://other:8181/ +`), "other", + &CatalogConfig{ + CatalogType: "rest", + URI: "http://other:8181/", + }, + }, } func TestParseConfig(t *testing.T) {