diff --git a/backend/go.mod b/backend/go.mod index 727b182d..7701d217 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -11,11 +11,11 @@ require ( github.com/Azure/go-autorest/autorest/azure/auth v0.5.3 github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 github.com/Masterminds/sprig v2.22.0+incompatible - github.com/aws/aws-sdk-go-v2 v1.11.2 - github.com/aws/aws-sdk-go-v2/config v1.6.0 - github.com/aws/aws-sdk-go-v2/service/ec2 v1.25.0 - github.com/aws/aws-sdk-go-v2/service/eks v1.15.1 - github.com/aws/aws-sdk-go-v2/service/sts v1.6.1 + github.com/aws/aws-sdk-go-v2 v1.30.0 + github.com/aws/aws-sdk-go-v2/config v1.27.22 + github.com/aws/aws-sdk-go-v2/service/ec2 v1.167.0 + github.com/aws/aws-sdk-go-v2/service/eks v1.45.0 + github.com/aws/aws-sdk-go-v2/service/sts v1.30.0 github.com/binxio/gcloudconfig v0.1.5 github.com/ghodss/yaml v1.0.0 github.com/gobwas/glob v0.2.3 @@ -31,7 +31,6 @@ require ( github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.313 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sts v1.0.319 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tke v1.0.500 - github.krafton.com/xtrm/fox v1.1.1 go.uber.org/zap v1.17.0 golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 @@ -54,14 +53,16 @@ require ( github.com/Azure/go-autorest/tracing v0.6.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver v1.5.0 // indirect - github.com/aws/aws-sdk-go-v2/credentials v1.3.2 // indirect - github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.2 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.2 // indirect - github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0 // indirect - github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.5.2 // indirect - github.com/aws/aws-sdk-go-v2/service/sso v1.3.2 // indirect - github.com/aws/smithy-go v1.9.0 // indirect + github.com/aws/aws-sdk-go-v2/credentials v1.17.22 // indirect + github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect + github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect + github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14 // indirect + github.com/aws/aws-sdk-go-v2/service/sso v1.22.0 // indirect + github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0 // indirect + github.com/aws/smithy-go v1.20.2 // indirect github.com/cenkalti/backoff/v4 v4.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect diff --git a/backend/go.sum b/backend/go.sum index 7544972e..b157bd5c 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -132,32 +132,62 @@ github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZw github.com/aws/aws-sdk-go-v2 v1.8.0/go.mod h1:xEFuWz+3TYdlPRuo+CqATbeDWIWyaT5uAPwPaWtgse0= github.com/aws/aws-sdk-go-v2 v1.11.2 h1:SDiCYqxdIYi6HgQfAWRhgdZrdnOuGyLDJVRSWLeHWvs= github.com/aws/aws-sdk-go-v2 v1.11.2/go.mod h1:SQfA+m2ltnu1cA0soUkj4dRSsmITiVQUJvBIZjzfPyQ= +github.com/aws/aws-sdk-go-v2 v1.30.0 h1:6qAwtzlfcTtcL8NHtbDQAqgM5s6NDipQTkPxyH/6kAA= +github.com/aws/aws-sdk-go-v2 v1.30.0/go.mod h1:ffIFB97e2yNsv4aTSGkqtHnppsIJzw7G7BReUZ3jCXM= github.com/aws/aws-sdk-go-v2/config v1.6.0 h1:rtoCnNObhVm7me+v9sA2aY+NtHNZjjWWC3ifXVci+wE= github.com/aws/aws-sdk-go-v2/config v1.6.0/go.mod h1:TNtBVmka80lRPk5+S9ZqVfFszOQAGJJ9KbT3EM3CHNU= +github.com/aws/aws-sdk-go-v2/config v1.27.22 h1:TRkQVtpDINt+Na/ToU7iptyW6U0awAwJ24q4XN+59k8= +github.com/aws/aws-sdk-go-v2/config v1.27.22/go.mod h1:EYY3mVgFRUWkh6QNKH64MdyKs1YSUgatc0Zp3MDxi7c= github.com/aws/aws-sdk-go-v2/credentials v1.3.2 h1:Uud/fZzm0lqqhE8kvXYJFAJ3PGnagKoUcvHq1hXfBZw= github.com/aws/aws-sdk-go-v2/credentials v1.3.2/go.mod h1:PACKuTJdt6AlXvEq8rFI4eDmoqDFC5DpVKQbWysaDgM= +github.com/aws/aws-sdk-go-v2/credentials v1.17.22 h1:wu9kXQbbt64ul09v3ye4HYleAr4WiGV/uv69EXKDEr0= +github.com/aws/aws-sdk-go-v2/credentials v1.17.22/go.mod h1:pcvMtPcxJn3r2k6mZD9I0EcumLqPLA7V/0iCgOIlY+o= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0 h1:SGqDJun6tydgsSIFxv9+EYBJVqVUwg2QMJp6PbNq8C8= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.4.0/go.mod h1:Mj/U8OpDbcVcoctrYwA2bak8k/HFPdcLzI/vaiXMwuM= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8 h1:FR+oWPFb/8qMVYMWN98bUZAGqPvLHiyqg1wqQGfUAXY= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.8/go.mod h1:EgSKcHiuuakEIxJcKGzVNWh5srVAQ3jKaSrBGRYvM48= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.2 h1:XJLnluKuUxQG255zPNe+04izXl7GSyUVafIsgfv9aw4= github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.2/go.mod h1:SgKKNBIoDC/E1ZCDhhMW3yalWjwuLjMcpLzsM/QQnWo= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 h1:SJ04WXGTwnHlWIODtC5kJzKbeuHt+OUNOgKg7nfnUGw= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12/go.mod h1:FkpvXhA92gb3GE9LD6Og0pHHycTxW7xGpnEh5E7Opwo= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.2 h1:EauRoYZVNPlidZSZJDscjJBQ22JhVF2+tdteatax2Ak= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.0.2/go.mod h1:xT4XX6w5Sa3dhg50JrYyy3e4WPYo/+WjY/BXtqXVunU= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 h1:hb5KgeYfObi5MHkSSZMEudnIvX30iB+E21evI4r6BnQ= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12/go.mod h1:CroKe/eWJdyfy9Vx4rljP5wTUjNJfb+fPz1uMYUhEGM= github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0 h1:xu45foJnwMwBqSkIMKyJP9kbyHi5hdhZ/WiJ7D2sHZ0= github.com/aws/aws-sdk-go-v2/internal/ini v1.2.0/go.mod h1:Q5jATQc+f1MfZp3PDMhn6ry18hGvE0i8yvbXoKbnZaE= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 h1:hT8rVHwugYE2lEfdFE0QWVo81lF7jMrYJVDWI+f+VxU= +github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0/go.mod h1:8tu/lYfQfFe6IGnaOdrpVgEL2IrrDOf6/m9RQum4NkY= github.com/aws/aws-sdk-go-v2/service/ec2 v1.25.0 h1:IGQu0cPAeYsWz0neqt6FwYg7DED7Prz/fdQxq/PoWI0= github.com/aws/aws-sdk-go-v2/service/ec2 v1.25.0/go.mod h1:cIbz+b70nxJafXf9lT07Xj03pef6CsVdYTCCR0DQEQc= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.167.0 h1:70ZrLWVE70lfA+AFeZTWvP6uXHlAbSjfN3Ussy0qGQs= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.167.0/go.mod h1:Wv7N3iFOKVsZNIaw9MOBUmwCkX6VMmQQRFhMrHtNGno= github.com/aws/aws-sdk-go-v2/service/eks v1.15.1 h1:ZXSYFvB8bN8JpMJDPenUktAuvMpsTHMMPW1hC+ckEJE= github.com/aws/aws-sdk-go-v2/service/eks v1.15.1/go.mod h1:xbz8pEpGLX0sMb5xCCWNSmp2mWNWQMZsOj6fFuCskjw= +github.com/aws/aws-sdk-go-v2/service/eks v1.45.0 h1:PRDbU5dV3wheU9x3GdrnygeX8AOV32nO0Kdre/i59GE= +github.com/aws/aws-sdk-go-v2/service/eks v1.45.0/go.mod h1:dg9l/W4hXygeRNydRB4LWKY/MwHJhfUomGJUBwI29Dw= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 h1:Ji0DY1xUsUr3I8cHps0G+XM3WWU16lP6yG8qu1GAZAs= +github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2/go.mod h1:5CsjAbs3NlGQyZNFACh+zztPDI7fU6eW9QsxjfnuBKg= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.2/go.mod h1:NXmNI41bdEsJMrD0v9rUvbGCB5GwdBEpKvUvIY3vTFg= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.5.2 h1:CKdUNKmuilw/KNmO2Q53Av8u+ZyXMC2M9aX8Z+c/gzg= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.5.2/go.mod h1:FgR1tCsn8C6+Hf+N5qkfrE4IXvUL1RgW87sunJ+5J4I= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14 h1:zSDPny/pVnkqABXYRicYuPf9z2bTqfH13HT3v6UheIk= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.14/go.mod h1:3TTcI5JSzda1nw/pkVC9dhgLre0SNBFj2lYS4GctXKI= github.com/aws/aws-sdk-go-v2/service/sso v1.3.2 h1:b+U3WrF9ON3f32FH19geqmiod4uKcMv/q+wosQjjyyM= github.com/aws/aws-sdk-go-v2/service/sso v1.3.2/go.mod h1:J21I6kF+d/6XHVk7kp/cx9YVD2TMD2TbLwtRGVcinXo= +github.com/aws/aws-sdk-go-v2/service/sso v1.22.0 h1:lPIAPCRoJkmotLTU/9B6icUFlYDpEuWjKeL79XROv1M= +github.com/aws/aws-sdk-go-v2/service/sso v1.22.0/go.mod h1:lcQG/MmxydijbeTOp04hIuJwXGWPZGI3bwdFDGRTv14= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0 h1:/4r71ghx+hX9spr884cqXHPEmPzqH/J3K7fkE1yfcmw= +github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0/go.mod h1:z0P8K+cBIsFXUr5rzo/psUeJ20XjPN0+Nn8067Nd+E4= github.com/aws/aws-sdk-go-v2/service/sts v1.6.1 h1:1Pls85C5CFjhE3aH+h85/hyAk89kQNlAWlEQtIkaFyc= github.com/aws/aws-sdk-go-v2/service/sts v1.6.1/go.mod h1:hLZ/AnkIKHLuPGjEiyghNEdvJ2PP0MgOxcmv9EBJ4xs= +github.com/aws/aws-sdk-go-v2/service/sts v1.30.0 h1:9ja34PaKybhCJjVKvxtDsUjbATUJGN+eF6QnO58u5cI= +github.com/aws/aws-sdk-go-v2/service/sts v1.30.0/go.mod h1:N2mQiucsO0VwK9CYuS4/c2n6Smeh1v47Rz3dWCPFLdE= github.com/aws/smithy-go v1.7.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/aws/smithy-go v1.9.0 h1:c7FUdEqrQA1/UVKKCNDFQPNKGp4FQg3YW4Ck5SLTG58= github.com/aws/smithy-go v1.9.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= +github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= diff --git a/backend/pkg/factory_register.go b/backend/pkg/factory_register.go index 90b8ce22..eeb2f338 100644 --- a/backend/pkg/factory_register.go +++ b/backend/pkg/factory_register.go @@ -9,7 +9,6 @@ import ( _ "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service/aws" _ "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service/azure" - _ "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service/fox" _ "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service/gcp" _ "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service/kubeconfig" _ "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service/rancher" diff --git a/backend/pkg/service/cluster_metadata_service/fox/resolver.go b/backend/pkg/service/cluster_metadata_service/fox/resolver.go deleted file mode 100644 index 70f63caa..00000000 --- a/backend/pkg/service/cluster_metadata_service/fox/resolver.go +++ /dev/null @@ -1,143 +0,0 @@ -package fox - -import ( - "fmt" - "github.com/pubg/kubeconfig-updater/backend/application/configs" - "github.com/pubg/kubeconfig-updater/backend/pkg/service/cluster_metadata_service" - "strconv" - "strings" - - "github.com/mitchellh/mapstructure" - "github.com/pubg/kubeconfig-updater/backend/controller/protos" - "github.com/pubg/kubeconfig-updater/backend/pkg/types" - "github.krafton.com/xtrm/fox/client" - "github.krafton.com/xtrm/fox/source/pkg/document" -) - -func init() { - foxFactory := &cluster_metadata_service.BasicMetaResolverFactory{FactoryFunc: NewFoxAdapter} - cluster_metadata_service.RegisterBasicResolverFactories(foxFactory) -} - -type Resolver struct { - foxClient *client.FoxClient -} - -func NewFoxAdapter(ext *configs.Extension) ([]cluster_metadata_service.ClusterMetadataResolver, error) { - if ext.Fox.Enable { - resolver, err := NewFoxResolver(ext.Fox.Address) - if err != nil { - return nil, err - } - return []cluster_metadata_service.ClusterMetadataResolver{resolver}, err - } - return nil, nil -} - -func NewFoxResolver(addr string) (*Resolver, error) { - foxClient, err := client.NewClient(&client.FoxClientConfig{ - APIUrl: addr, - }) - if err != nil { - return nil, err - } - - return &Resolver{ - foxClient: foxClient, - }, nil -} - -func (f *Resolver) GetResolverDescription() string { - return "PUBG-Fox" -} - -func (f *Resolver) GetCluster(clusterName string) (*protos.ClusterMetadata, bool, error) { - docId := fmt.Sprintf("%[1]s-common", clusterName) - exists, err := f.foxClient.ExistDocument(docId) - if err != nil { - return nil, false, err - } - if !exists { - return nil, false, nil - } - - doc, err := f.foxClient.GetDocument(docId) - if err != nil { - return nil, false, err - } - - metadata, err := parseDoc(doc) - if err != nil { - return nil, false, err - } - return metadata, true, nil -} - -func (f *Resolver) ListClusters() ([]*protos.ClusterMetadata, error) { - perPageSize := 100 - pageIndex := 1 - - var allDocs []document.Document - for { - docs, err := f.foxClient.GetDocumentAll(perPageSize, pageIndex) - if err != nil { - return nil, err - } - if len(*docs) == 0 { - break - } - pageIndex++ - allDocs = append(allDocs, *docs...) - } - - var clusterMetas []*protos.ClusterMetadata - for _, doc := range allDocs { - if strings.HasSuffix(doc.Id, "-common") { - meta, err := parseDoc(&doc) - if err != nil { - fmt.Printf("[Error] Can't parse fox doc to cluster metadata %s (%s)\n", doc.Id, err.Error()) - } - clusterMetas = append(clusterMetas, meta) - } - } - return clusterMetas, nil -} - -func parseDoc(doc *document.Document) (*protos.ClusterMetadata, error) { - var foxMetadata FoxClusterMetadata - err := mapstructure.Decode(doc.Data, &foxMetadata) - if err != nil { - return nil, err - } - - targetMetadata := &protos.ClusterMetadata{ - ClusterTags: map[string]string{}, - } - targetMetadata.ClusterName = foxMetadata.ClusterName - targetMetadata.CredResolverId = foxMetadata.InfraAccountId - targetMetadata.ClusterTags[types.KnownClusterTag_ClusterRegion.String()] = foxMetadata.ClusterRegion - targetMetadata.ClusterTags["InfraAccountId"] = foxMetadata.InfraAccountId - targetMetadata.ClusterTags["ClusterEngine"] = foxMetadata.ClusterEngine - targetMetadata.ClusterTags["InfraVendor"] = foxMetadata.InfraVendor - targetMetadata.ClusterTags["ServicePhase"] = foxMetadata.ServicePhase - targetMetadata.ClusterTags["ServiceTag"] = foxMetadata.ServiceTag - targetMetadata.ClusterTags["CentralRole"] = strconv.FormatBool(foxMetadata.CentralRole) - targetMetadata.ClusterTags["OutgameRole"] = strconv.FormatBool(foxMetadata.OutgameRole) - targetMetadata.ClusterTags["IntgameRole"] = strconv.FormatBool(foxMetadata.IntgameRole) - return targetMetadata, nil -} - -type FoxClusterMetadata struct { - ClusterName string `json:"clusterName"` - ClusterRegion string `json:"clusterRegion"` - InfraAccountId string `json:"infraAccountId"` - ClusterEngine string `json:"clusterEngine"` - InfraVendor string `json:"infraVendor"` - ServicePhase string `json:"servicePhase"` - ServiceTag string `json:"serviceTag"` - CentralRole bool `json:"centralRole"` - OutgameRole bool `json:"outgameRole"` - IntgameRole bool `json:"intgameRole"` - ResourceGroup string `json:"resourceGroup"` - ClusterId string `json:"clusterId"` -} diff --git a/backend/pkg/service/cluster_metadata_service/fox/resolver_test.go b/backend/pkg/service/cluster_metadata_service/fox/resolver_test.go deleted file mode 100644 index b090c7b8..00000000 --- a/backend/pkg/service/cluster_metadata_service/fox/resolver_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package fox - -import ( - "fmt" - "os" - "testing" -) - -func TestFoxResolver_GetCluster(t *testing.T) { - resolver, err := NewFoxResolver(os.Getenv("FOX_ADDR")) - if err != nil { - t.Error(err) - } - - metadata, exists, err := resolver.GetCluster("central-ea") - if err != nil { - t.Error(err) - } - if exists { - fmt.Printf("Found Cluster Metadata\n") - fmt.Printf("%+v\n", metadata) - } else { - t.Errorf("Cluster Metadata is not exists") - } -} - -func TestFoxResolver_ListClusters(t *testing.T) { - resolver, err := NewFoxResolver(os.Getenv("FOX_ADDR")) - if err != nil { - t.Error(err) - } - - metadatas, err := resolver.ListClusters() - if err != nil { - t.Error(err) - } - fmt.Printf("Found Cluster Metadata\n") - for _, metadata := range metadatas { - fmt.Printf("%+v\n", metadata) - } -}