Skip to content

fix(config): support nested configurations in config apply#1024

Open
shellyco-code wants to merge 2 commits into
goharbor:mainfrom
shellyco-code:fix/config-apply-nested-configurations
Open

fix(config): support nested configurations in config apply#1024
shellyco-code wants to merge 2 commits into
goharbor:mainfrom
shellyco-code:fix/config-apply-nested-configurations

Conversation

@shellyco-code

@shellyco-code shellyco-code commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request resolves an issue where the harbor config apply command fails silently when applying configuration files that nest configuration parameters under a top-level configurations: key.

The unmarshaling block has been updated to attempt to parse the wrapped structure first, falling back to flat parsing if the wrapper is absent, ensuring full backward compatibility.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Defined configWrapper helper struct in apply.go to match the nested configurations block.
  • Updated JSON/YAML unmarshaling blocks in cmd/harbor/root/configurations/apply.go to attempt wrapper unmarshaling first and fall back to direct unmarshaling on failure or nil.
  • Created cmd/harbor/root/configurations/apply_test.go implementing metadata validation and CLI-level error checks using testutil.TestCmd.

Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@shellyco-code

Copy link
Copy Markdown
Contributor Author

@qcserestipy Hi! This PR implements the fix for the nested configuration parsing issue discussed in #1024. Whenever you have some time, I'd really appreciate your review. Thank you!

@qcserestipy qcserestipy requested review from Copilot and qcserestipy and removed request for Copilot June 30, 2026 09:39
@qcserestipy qcserestipy added the status/in-progress Work on this issue has started or a linked pull request is actively being developed. label Jun 30, 2026
@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 9.46%. Comparing base (60ad0bd) to head (fa79df2).
⚠️ Report is 188 commits behind head on main.

Files with missing lines Patch % Lines
cmd/harbor/root/configurations/apply.go 0.00% 12 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main   #1024      +/-   ##
=========================================
- Coverage   10.99%   9.46%   -1.53%     
=========================================
  Files         173     321     +148     
  Lines        8671   16090    +7419     
=========================================
+ Hits          953    1523     +570     
- Misses       7612   14432    +6820     
- Partials      106     135      +29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes harbor config apply to correctly read configuration files that wrap settings under a top-level configurations: (YAML) / "configurations" (JSON) key, preventing silent no-op applies for the documented file format (Fixes #1023).

Changes:

  • Add a configWrapper helper to support nested configurations payloads.
  • Update YAML/JSON unmarshaling logic in config apply to prefer wrapped parsing with fallback behavior.
  • Add basic command metadata/argument-validation tests for config apply.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
cmd/harbor/root/configurations/apply.go Adds wrapper-aware YAML/JSON parsing for config apply to handle nested configurations documents.
cmd/harbor/root/configurations/apply_test.go Adds baseline tests for command metadata and flag/arg validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/harbor/root/configurations/apply.go Outdated
Comment thread cmd/harbor/root/configurations/apply.go Outdated
Comment thread cmd/harbor/root/configurations/apply_test.go
Previously, the YAML and JSON parsing logic used a wrapper-first approach
that silently fell back to flat parsing whenever the wrapper unmarshal
produced a nil Configurations field. This reintroduced the original
silent no-op bug from goharbor#1023: a file with a 'configurations' key pointing
to an invalid type (string, list, null) would produce an empty
configurations object and report 'No changes detected.' instead of an
error.

Fix the logic by detecting the presence of the 'configurations' key using
a raw map before attempting typed unmarshaling. If the key exists, the
wrapper parse is mandatory and any failure (wrong type, null, empty) is
treated as a fatal error. If the key is absent the file is parsed as a
legacy flat document for backward compatibility.

Extract the parsing logic into dedicated parseYAMLConfig and
parseJSONConfig helpers to make the intent clear and to allow direct
unit testing without a live Harbor server.

Add regression tests that cover:
- valid wrapped YAML and JSON
- malformed wrapped YAML/JSON (scalar, list, null under configurations)
- legacy flat YAML and JSON
- empty configurations key
- invalid syntax

Fixes goharbor#1023

Signed-off-by: shellyco-code <shellychahar57@gmail.com>
@shellyco-code

Copy link
Copy Markdown
Contributor Author

Hey @qcserestipy , addressed all three Copilot comments — fixed the silent fallback bug for malformed wrapped files and added parsing regression tests. Would appreciate another review when you get a chance!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines +200 to +205
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tt.checkResult != nil {
tt.checkResult(t, got)
}
Comment on lines +286 to +291
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if tt.checkResult != nil {
tt.checkResult(t, got)
}

@qcserestipy qcserestipy left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@shellyco-code Thank you for your contribution, just a few small changes requested. Please also address the copilot points with respect to the tests.

// configuration document for backward compatibility.
func parseYAMLConfig(data []byte) (*models.Configurations, error) {
// Use a raw map to detect whether the top-level "configurations" key exists.
var rawMap map[string]interface{}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

interface{} can be replaced by anyanydefault

Configurations *models.Configurations `yaml:"configurations" json:"configurations"`
}

// parseYAMLConfig parses a YAML configuration file into *models.Configurations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

in principle looks good, can you shorten this doc string

@qcserestipy qcserestipy added bug Something isn't working Changes Requesed feedback that must be addressed before merging. labels Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Changes Requesed feedback that must be addressed before merging. status/in-progress Work on this issue has started or a linked pull request is actively being developed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: config apply -f fails silently to parse configuration files using the configurations wrapper

3 participants