-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature. implementation importing cluster
- Loading branch information
Showing
4 changed files
with
93 additions
and
3 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
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,6 +1,9 @@ | ||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= | ||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= | ||
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= | ||
github.com/openinfradev/tks-api v0.0.0-20231017022609-fe95bb67dc60 h1:aKcP0zqiuQuruwJ3j+Eb06QKkZKvddFuZ9XPMsANpgg= | ||
github.com/openinfradev/tks-api v0.0.0-20231017022609-fe95bb67dc60/go.mod h1:91WDknrRu9zZZ1rI1OGhj7dqqc4DQJb830y7EU5t85I= | ||
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= | ||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= | ||
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= | ||
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd h1:e0TwkXOdbnH/1x5rc5MZ/VYyiZ4v+RdVfrGMqEwT68I= | ||
google.golang.org/grpc v1.46.2 h1:u+MLGgVf7vRdjEYZ8wDFhAVNmhkbJ5hmrA1LMWK1CAQ= | ||
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= |
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,86 @@ | ||
package commands | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
_apiClient "github.com/openinfradev/tks-api/pkg/api-client" | ||
"github.com/openinfradev/tks-api/pkg/domain" | ||
"github.com/openinfradev/tks-client/internal/helper" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewClusterImportCommand(globalOpts *GlobalOptions) *cobra.Command { | ||
var ( | ||
name string | ||
clusterType string | ||
organizationId string | ||
description string | ||
stackTemplateId string | ||
kubeconfigPath string | ||
) | ||
|
||
var command = &cobra.Command{ | ||
Use: "import", | ||
Short: "Import a TKS Cluster.", | ||
Long: `Import a TKS Cluster. | ||
Example: | ||
tks cluster import <CLUSTERNAME> [--cloud-service AWS] [--template TEMPLATE_NAME]`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if len(args) == 0 { | ||
fmt.Println("You must specify cluster name.") | ||
return errors.New("Usage: tks cluster import <CLUSTERNAME> --contract-id <CONTRACTID>") | ||
} | ||
|
||
if len(args) == 1 { | ||
name = args[0] | ||
} | ||
|
||
kubeconfig, err := os.ReadFile(kubeconfigPath) | ||
if err != nil { | ||
log.Fatalf("Failed to read kubeconfig from [%s] path", err) | ||
log.Fatalf("Failed to read kubeconfig from [%s] path", kubeconfigPath) | ||
} | ||
input := domain.ImportClusterRequest{ | ||
OrganizationId: organizationId, | ||
StackTemplateId: stackTemplateId, | ||
Name: name, | ||
Description: description, | ||
ClusterType: clusterType, | ||
Kubeconfig: kubeconfig, | ||
} | ||
|
||
apiClient, err := _apiClient.NewWithToken(globalOpts.ServerAddr, globalOpts.AuthToken) | ||
helper.CheckError(err) | ||
|
||
body, err := apiClient.Post("clusters/import", input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var out domain.ImportClusterResponse | ||
helper.Transcode(body, &out) | ||
|
||
fmt.Println("clusterId : ", out.ID) | ||
|
||
return nil | ||
}, | ||
} | ||
command.Flags().StringVarP(&organizationId, "organization-id", "o", "", "the organizationId with clusters") | ||
helper.CheckError(command.MarkFlagRequired("organization-id")) | ||
|
||
command.Flags().StringVar(&clusterType, "cluster-type", "USER", "the cluster type (USER | ADMIN)") | ||
|
||
command.Flags().StringVarP(&stackTemplateId, "stack-template-id", "t", "", "the template for installation") | ||
helper.CheckError(command.MarkFlagRequired("stack-template-id")) | ||
|
||
command.Flags().StringVarP(&name, "name", "n", "", "the name of organization") | ||
command.Flags().StringVarP(&description, "description", "d", "", "the description of organization") | ||
|
||
command.Flags().StringVar(&kubeconfigPath, "kubeconfig-path", "~/.kube/config", "the path of kubeconfig") | ||
|
||
return command | ||
} |
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