Skip to content

Commit

Permalink
Update the name
Browse files Browse the repository at this point in the history
Signed-off-by: corvofeng <corvofeng@gmail.com>
  • Loading branch information
corvofeng committed May 9, 2024
1 parent 39ca78e commit 8d6d325
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 21 deletions.
46 changes: 30 additions & 16 deletions cmd/kubemux/internal/command/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package command

import (
"fmt"
"kubemux/lib/kubernetes"
"kubemux/lib/kubernetes/kmaws"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/eks"
"github.com/spf13/cobra"
)

Expand All @@ -22,22 +21,37 @@ func awsCmd(rootCmd *rootCmd) *cobra.Command {
}

func awsCMDExec() {
sess, err := session.NewSession(&aws.Config{
Region: aws.String("eu-north-1"),
})
// aws.NewEKS("eu-north-1")
k, err := kmaws.NewEKS("eu-north-1")
if err != nil {
fmt.Println("Error creating session:", err)
return
fmt.Println("Error creating EKS client:", err)
}

input := &eks.ListClustersInput{}
svc := eks.New(sess)
svc.ListClustersPages(input, func(page *eks.ListClustersOutput, lastPage bool) bool {
for _, cluster := range page.Clusters {
fmt.Println(*cluster)
}
return !lastPage
})
ch := make(chan *kubernetes.Cluster)
go k.GetClusters(ch)
clusters := []*kubernetes.Cluster{}
for c := range ch {
clusters = append(clusters, c)
fmt.Println(c.Name)
}
fmt.Println(clusters)

// sess, err := session.NewSession(&aws.Config{
// Region: aws.String("eu-north-1"),
// })
// if err != nil {
// fmt.Println("Error creating session:", err)
// return
// }

// input := &eks.ListClustersInput{}
// svc := eks.New(sess)
// svc.ListClustersPages(input, func(page *eks.ListClustersOutput, lastPage bool) bool {
// for _, cluster := range page.Clusters {
// fmt.Println(*cluster)
// }
// return !lastPage
// })

// input = &eks.DescribeClusterInput{}
// regions, err := svc.DescribeCluster(input)
Expand Down
5 changes: 2 additions & 3 deletions lib/kubernetes/aws/eks.go → lib/kubernetes/kmaws/eks.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package internal provides wrapper for creating aws sessions
package aws
package kmaws

import (
"encoding/base64"
Expand Down Expand Up @@ -72,13 +72,12 @@ func (c *EKSClient) GetClusters(ch chan<- *cluster.Cluster) {

close(ch)
}

func (c *EKSClient) detailCluster(cName string) (*cluster.Cluster, error) {
input := &eks.DescribeClusterInput{
Name: aws.String(cName),
}
result, err := c.EKS.DescribeCluster(input)

result, err := c.EKS.(input)
if err != nil {
// TODO(mmicu): handle errors better here
if aerr, ok := err.(awserr.Error); ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package internal provides wrapper for creating aws sessions
package aws
package kmaws

import (
"encoding/base64"
Expand Down Expand Up @@ -88,7 +88,7 @@ func (c *mockEKSClient) DescribeCluster(input *eks.DescribeClusterInput) (*eks.D
cluster.Arn = &localCluster.ID
cluster.Endpoint = &localCluster.Endpoint
cluster.Name = &localCluster.Name
cluster.Status = &localCluster.Status
// cluster.Status = &localCluster.Status

cert := eks.Certificate{}
data := base64.StdEncoding.EncodeToString([]byte(cls.CertificateAuthorityData))
Expand Down

0 comments on commit 8d6d325

Please sign in to comment.