Skip to content

Commit 0a58860

Browse files
authoredJul 25, 2024
🐛 Fix version bumps in stable mode (#144)
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 <janis.kemper@syself.com>
1 parent 783b8ba commit 0a58860

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed
 

‎pkg/cmd/create.go

+5
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
152152
return nil, fmt.Errorf("failed to download release asset: %w", err)
153153
}
154154

155+
createOption.LatestReleaseHash, err = hash.ParseReleaseHash("./.tmp/release/hashes.json")
156+
if err != nil {
157+
return nil, fmt.Errorf("failed to read hash from the github: %w", err)
158+
}
159+
155160
createOption.Metadata, err = clusterstack.HandleStableMode("./.tmp/release/", createOption.CurrentReleaseHash, createOption.LatestReleaseHash)
156161
if err != nil {
157162
return nil, fmt.Errorf("failed to handle stable mode: %w", err)

‎pkg/github/release.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func DownloadReleaseAssets(ctx context.Context, releaseTag, downloadPath string,
3636
return fmt.Errorf("failed to fetch release tag %s with status code %d", releaseTag, resp.StatusCode)
3737
}
3838

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

4141
if err := gc.DownloadReleaseAssets(ctx, repoRelease, downloadPath, assetlist); err != nil {
4242
// if download failed for some reason, delete the release directory so that it can be retried in the next reconciliation

‎pkg/hash/hash.go

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package hash
2020
import (
2121
"crypto/sha256"
2222
"encoding/base64"
23+
"encoding/json"
2324
"fmt"
2425
"io"
2526
"os"
@@ -43,6 +44,21 @@ type ReleaseHash struct {
4344
NodeImageDir string `json:"nodeImageDir,omitempty"`
4445
}
4546

47+
// ParseReleaseHash parses the cluster-stack release hash.
48+
func ParseReleaseHash(path string) (ReleaseHash, error) {
49+
latestGitHubReleaseHashData, err := os.ReadFile(filepath.Clean(path))
50+
if err != nil {
51+
return ReleaseHash{}, fmt.Errorf("failed to read hash: %q: %w", path, err)
52+
}
53+
54+
var releaseHash ReleaseHash
55+
if err := json.Unmarshal(latestGitHubReleaseHashData, &releaseHash); err != nil {
56+
return ReleaseHash{}, fmt.Errorf("failed to unmarshal json: %q: %w", path, err)
57+
}
58+
59+
return releaseHash, nil
60+
}
61+
4662
// GetHash returns the release hash.
4763
func GetHash(path string) (ReleaseHash, error) {
4864
entries, err := os.ReadDir(path)

0 commit comments

Comments
 (0)
Please sign in to comment.