diff --git a/pkg/cmd/create.go b/pkg/cmd/create.go index 756a117a..d48c5be7 100644 --- a/pkg/cmd/create.go +++ b/pkg/cmd/create.go @@ -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" @@ -57,6 +59,7 @@ var ( clusterStackVersion string clusterAddonVersion string nodeImageVersion string + remote string ) // CreateOptions contains config for creating a release. @@ -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. @@ -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) } @@ -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) }