-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Aniruddha Basak <[email protected]>
- Loading branch information
1 parent
3bcc4fc
commit 93a5567
Showing
13 changed files
with
401 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
|
||
.envrc | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package github | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sort" | ||
|
||
csoclusterstack "github.com/SovereignCloudStack/cluster-stack-operator/pkg/clusterstack" | ||
"github.com/SovereignCloudStack/cluster-stack-operator/pkg/version" | ||
"github.com/SovereignCloudStack/csmctl/pkg/clusterstack" | ||
githubclient "github.com/SovereignCloudStack/csmctl/pkg/github/client" | ||
) | ||
|
||
// GetLatestReleaseFromRemoteRepository returns the latest release from the github repository. | ||
func GetLatestReleaseFromRemoteRepository(ctx context.Context, mode string, config *clusterstack.CsmctlConfig, gc githubclient.Client) (string, error) { | ||
ghReleases, resp, err := gc.ListRelease(ctx) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to list releases on remote Git repository: %w", err) | ||
} | ||
if resp != nil && resp.StatusCode != 200 { | ||
return "", fmt.Errorf("got unexpected status from call to remote Git repository: %s", resp.Status) | ||
} | ||
|
||
var clusterStacks csoclusterstack.ClusterStacks | ||
|
||
for _, ghRelease := range ghReleases { | ||
clusterStackObject, matches, err := matchesSpec(ghRelease.GetTagName(), mode, config) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get match release tag %q with spec of ClusterStack: %w", ghRelease.GetTagName(), err) | ||
} | ||
|
||
if matches { | ||
clusterStacks = append(clusterStacks, clusterStackObject) | ||
} | ||
} | ||
|
||
if len(clusterStacks) == 0 { | ||
return "", nil | ||
} | ||
|
||
sort.Sort(clusterStacks) | ||
|
||
str := clusterStacks.Latest().String() | ||
return str, nil | ||
} | ||
|
||
func matchesSpec(releaseTagName, mode string, cs *clusterstack.CsmctlConfig) (csoclusterstack.ClusterStack, bool, error) { | ||
csObject, err := csoclusterstack.NewFromClusterStackReleaseProperties(releaseTagName) | ||
if err != nil { | ||
return csoclusterstack.ClusterStack{}, false, fmt.Errorf("failed to get clusterstack object from string %q: %w", releaseTagName, err) | ||
} | ||
|
||
kubernetesVersion, err := cs.ParseKubernetesVersion() | ||
if err != nil { | ||
return csoclusterstack.ClusterStack{}, false, fmt.Errorf("failed to parse kubernetes version %q: %w", cs.Config.ClusterStackName, err) | ||
} | ||
|
||
return csObject, csObject.Version.Channel == version.Channel(mode) && | ||
csObject.KubernetesVersion.StringWithDot() == kubernetesVersion.StringWithDot() && | ||
csObject.Name == cs.Config.ClusterStackName && | ||
csObject.Provider == cs.Config.Provider.Type, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.