Skip to content

Commit

Permalink
🐛 Fix version bumps in stable mode (#144)
Browse files Browse the repository at this point in the history
In stable mode, we don't want to bump the dependencies if we don't have
to, i.e. cluster addons and node images.

For this, we compare the hashes. However, we forgot to set up the inputs
to the functions that do that correctly and one value was empty.

Signed-off-by: janiskemper <[email protected]>
  • Loading branch information
janiskemper authored Jul 25, 2024
1 parent 783b8ba commit 0a58860
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions pkg/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
return nil, fmt.Errorf("failed to download release asset: %w", err)
}

createOption.LatestReleaseHash, err = hash.ParseReleaseHash("./.tmp/release/hashes.json")
if err != nil {
return nil, fmt.Errorf("failed to read hash from the github: %w", err)
}

createOption.Metadata, err = clusterstack.HandleStableMode("./.tmp/release/", createOption.CurrentReleaseHash, createOption.LatestReleaseHash)
if err != nil {
return nil, fmt.Errorf("failed to handle stable mode: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/github/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func DownloadReleaseAssets(ctx context.Context, releaseTag, downloadPath string,
return fmt.Errorf("failed to fetch release tag %s with status code %d", releaseTag, resp.StatusCode)
}

assetlist := []string{"metadata.yaml", "cluster-addon-values.yaml", "cluster-addon", "cluster-class"}
assetlist := []string{"hashes.json", "metadata.yaml", "cluster-addon-values.yaml", "cluster-addon", "cluster-class"}

if err := gc.DownloadReleaseAssets(ctx, repoRelease, downloadPath, assetlist); err != nil {
// if download failed for some reason, delete the release directory so that it can be retried in the next reconciliation
Expand Down
16 changes: 16 additions & 0 deletions pkg/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package hash
import (
"crypto/sha256"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"os"
Expand All @@ -43,6 +44,21 @@ type ReleaseHash struct {
NodeImageDir string `json:"nodeImageDir,omitempty"`
}

// ParseReleaseHash parses the cluster-stack release hash.
func ParseReleaseHash(path string) (ReleaseHash, error) {
latestGitHubReleaseHashData, err := os.ReadFile(filepath.Clean(path))
if err != nil {
return ReleaseHash{}, fmt.Errorf("failed to read hash: %q: %w", path, err)
}

var releaseHash ReleaseHash
if err := json.Unmarshal(latestGitHubReleaseHashData, &releaseHash); err != nil {
return ReleaseHash{}, fmt.Errorf("failed to unmarshal json: %q: %w", path, err)
}

return releaseHash, nil
}

// GetHash returns the release hash.
func GetHash(path string) (ReleaseHash, error) {
entries, err := os.ReadDir(path)
Expand Down

0 comments on commit 0a58860

Please sign in to comment.