Skip to content

Commit

Permalink
added: allow switch for assetclient in create command
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Eiselt <eiselt@b1-systems.de>
  • Loading branch information
DEiselt committed Oct 16, 2024
1 parent 67ba98a commit 43bcf6d
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pkg/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/SovereignCloudStack/csctl/pkg/assetsclient"
"github.com/SovereignCloudStack/csctl/pkg/assetsclient/github"
"github.com/SovereignCloudStack/csctl/pkg/assetsclient/oci"
"os"
"path/filepath"

"github.com/SovereignCloudStack/csctl/pkg/assetsclient/github"
"github.com/SovereignCloudStack/csctl/pkg/clusterstack"
"github.com/SovereignCloudStack/csctl/pkg/hash"
"github.com/SovereignCloudStack/csctl/pkg/providerplugin"
Expand Down Expand Up @@ -57,6 +59,7 @@ var (
clusterStackVersion string
clusterAddonVersion string
nodeImageVersion string
remote string
)

// CreateOptions contains config for creating a release.
Expand Down Expand Up @@ -88,6 +91,7 @@ func init() {
createCmd.Flags().StringVar(&clusterStackVersion, "cluster-stack-version", "", "It is used to specify the semver version for the cluster stack in the custom mode")
createCmd.Flags().StringVar(&clusterAddonVersion, "cluster-addon-version", "", "It is used to specify the semver version for the cluster addon in the custom mode")
createCmd.Flags().StringVar(&nodeImageVersion, "node-image-version", "", "It is used to specify the semver version for the node images in the custom mode")
createCmd.Flags().StringVar(&remote, "remote", "github", "Which remote repository to use and thus which credentials are required. Currently supported are 'github' and 'oci'.")
}

// GetCreateOptions create a Create Option for create command.
Expand Down Expand Up @@ -129,12 +133,21 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
case stableMode:
createOption.Metadata = &clusterstack.MetaData{}

gc, err := github.NewFactory().NewClient(ctx)
var remoteFactory assetsclient.Factory

switch remote {
case "github":
remoteFactory = github.NewFactory()
case "oci":
remoteFactory = oci.NewFactory()
}

ac, err := remoteFactory.NewClient(ctx)
if err != nil {
return nil, fmt.Errorf("failed to create new github client: %w", err)
return nil, fmt.Errorf("failed to create new asset client: %w", err)
}

latestRepoRelease, err := getLatestReleaseFromRemoteRepository(ctx, mode, config, gc)
latestRepoRelease, err := getLatestReleaseFromRemoteRepository(ctx, mode, config, ac)
if err != nil {
return nil, fmt.Errorf("failed to get latest release form remote repository: %w", err)
}
Expand All @@ -147,7 +160,7 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
createOption.Metadata.Versions.Components.ClusterAddon = "v1"
createOption.Metadata.Versions.Components.NodeImage = "v1"
} else {
if err := downloadReleaseAssets(ctx, latestRepoRelease, "./.tmp/release/", gc); err != nil {
if err := downloadReleaseAssets(ctx, latestRepoRelease, "./.tmp/release/", ac); err != nil {
return nil, fmt.Errorf("failed to download release asset: %w", err)
}

Expand Down

0 comments on commit 43bcf6d

Please sign in to comment.