Skip to content

fix(versions): log release versions when config is missing #745

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

pau-hedgehog
Copy link
Contributor

@pau-hedgehog pau-hedgehog commented Jul 8, 2025

When no fab.yaml is found, the versions command shows the release versions instead of an error:

pau@fedora:~/fabricator$ bin/hhfab versions
16:20:32 INF Hedgehog Fabricator version=v0.40.0-33-g4f106419-dirty-Im1446
16:20:32 ERR printing versions: config "fab.yaml": does not exist

VS:

pau@fedora:~/fabricator$ bin/hhfab versions
17:00:47 INF Hedgehog Fabricator version=v0.40.0-26-g1ed17d84-dirty-N51656
17:00:47 INF No configuration found file=fab.yaml action="Showing release versions"
fabric:
  agent: v0.82.0
  api: v0.82.0
  boot: v0.82.0
  controller: v0.82.0
  ctl: v0.82.0
  dhcpd: v0.82.0
  nos:
    sonic-bcm-base: v4.5.0
    sonic-bcm-campus: v4.5.0
    sonic-bcm-vs: v4.5.0
  proxy: 1.9.1
  proxyChart: v0.82.0
fabricator:
  api: v0.40.0-26-g1ed17d84-dirty-N51656
  controlISORoot: v4152.2.3-hh1
  controller: v0.40.0-26-g1ed17d84-dirty-N51656
  ctl: v0.40.0-26-g1ed17d84-dirty-N51656
  flatcar: v4152.2.3
  nodeConfig: v0.40.0-26-g1ed17d84-dirty-N51656
  pause: "3.6"
...

If there are overrides in fab.yaml or in the API object, they are shown:

pau@fedora:~/fabricator$ bin/hhfab versions
18:42:10 INF Hedgehog Fabricator version=v0.40.0-26-g1ed17d84-dirty-RB1838
18:42:10 INF Wiring hydrated successfully mode=if-not-present
18:42:10 INF Printing versions of all components (release → override)
fabric:
  agent: v0.82.0 → v0.40.1-custom
  api: v0.82.0
  boot: v0.82.0
  controller: v0.82.0 → v0.40.1-custom
  ctl: v0.82.0
  dhcpd: v0.82.0
  nos:
    sonic-bcm-base: v4.5.0
    sonic-bcm-campus: v4.5.0
    sonic-bcm-vs: v4.5.0
  proxy: 1.9.1
  proxyChart: v0.82.0
fabricator:
  api: v0.40.0-26-g1ed17d84-dirty-RB1838 → v0.40.1-test
  controlISORoot: v4152.2.3-hh1
  controller: v0.40.0-26-g1ed17d84-dirty-RB1838 → v0.40.1-test
  ctl: v0.40.0-26-g1ed17d84-dirty-RB1838 → v0.40.1-test
  flatcar: v4152.2.3
  nodeConfig: v0.40.0-26-g1ed17d84-dirty-RB1838 → v0.40.1-test
  pause: "3.6"
...

@pau-hedgehog pau-hedgehog self-assigned this Jul 8, 2025
@pau-hedgehog pau-hedgehog force-pushed the pau/hhfab_versions branch 2 times, most recently from 8a003bb to 3785e41 Compare July 8, 2025 21:18
@pau-hedgehog
Copy link
Contributor Author

I'm removing the skip-vlab label because I added the hhfab versions in the CI workflow to keep track of the versions tested

When no fab.yaml is found, the versions command shows the
release versions instead of an error

If there are overrides in fab.yaml, they are shown

Signed-off-by: Pau Capdevila <[email protected]>
hhfab versions --live

Signed-off-by: Pau Capdevila <[email protected]>
Signed-off-by: Pau Capdevila <[email protected]>
@pau-hedgehog pau-hedgehog marked this pull request as ready for review July 9, 2025 14:58
@pau-hedgehog pau-hedgehog requested review from a team as code owners July 9, 2025 14:58
@pau-hedgehog pau-hedgehog requested a review from Frostman July 10, 2025 13:10
@Frostman Frostman requested a review from Copilot July 11, 2025 19:21
Copy link

@Copilot Copilot AI left a comment

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 enhances the versions command to:

  • Fallback to printing built-in release versions when no fab.yaml is found
  • Introduce a --live flag to fetch versions from a running Fabricator in-cluster
  • Update CI workflows to invoke bin/hhfab versions and remove the old Versions in cmdconfig.go

Reviewed Changes

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

File Description
pkg/hhfab/cmdversions.go New command implementation handling missing config and live fetch
pkg/hhfab/cmdconfig.go Remove deprecated Versions function
cmd/hhfab/main.go Add --live flag to the versions command
.github/workflows/ci.yaml Invoke bin/hhfab versions in multiple CI steps
Comments suppressed due to low confidence (2)

pkg/hhfab/cmdversions.go:96

  • Add unit tests for formatVersions and compareVersionMaps to verify correct YAML output in both override and no-override scenarios.
func formatVersions(releaseVersions, overriddenVersions fabapi.Versions) (string, error) {

pkg/hhfab/cmdversions.go:21

  • [nitpick] Add a Go doc comment for the exported Versions function explaining its parameters and behavior (missing config vs live cluster).
func Versions(ctx context.Context, workDir, cacheDir string, hMode HydrateMode, live bool) error {

overriddenMap, err := convertToMap(overriddenVersions)
if err != nil {
slog.Warn("Failed to convert overridden versions", "error", err)
data, _ := kyaml.Marshal(releaseVersions)
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

Avoid ignoring the error from kyaml.Marshal here; handle or log it so that serialization failures in the fallback path are not silently dropped.

Suggested change
data, _ := kyaml.Marshal(releaseVersions)
data, marshalErr := kyaml.Marshal(releaseVersions)
if marshalErr != nil {
slog.Warn("Failed to marshal release versions", "error", marshalErr)
return "", fmt.Errorf("marshalling release versions: %w", marshalErr)
}

Copilot uses AI. Check for mistakes.

Comment on lines +52 to +64
freshFab := fabapi.Fabricator{}
if err := freshFab.CalculateVersions(fab.Versions); err != nil {
return fmt.Errorf("calculating default versions: %w", err)
}

versionsData, err := formatVersions(freshFab.Status.Versions, cfg.Fab.Status.Versions)
if err != nil {
return fmt.Errorf("formatting versions: %w", err)
}

fmt.Println(versionsData)

return nil
Copy link
Preview

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

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

[nitpick] There are multiple duplicated blocks that call CalculateVersions and print results; consider extracting common code into a helper to reduce duplication.

Suggested change
freshFab := fabapi.Fabricator{}
if err := freshFab.CalculateVersions(fab.Versions); err != nil {
return fmt.Errorf("calculating default versions: %w", err)
}
versionsData, err := formatVersions(freshFab.Status.Versions, cfg.Fab.Status.Versions)
if err != nil {
return fmt.Errorf("formatting versions: %w", err)
}
fmt.Println(versionsData)
return nil
return processVersions(fab.Versions, cfg.Fab.Status.Versions, false)

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants