Skip to content
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

🐛 Fix version bumps in stable mode #144

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")
janiskemper marked this conversation as resolved.
Show resolved Hide resolved
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