github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv2/api_service.go (about) 1 package containerv2 2 3 import ( 4 gohttp "net/http" 5 6 bluemix "github.com/IBM-Cloud/bluemix-go" 7 "github.com/IBM-Cloud/bluemix-go/authentication" 8 "github.com/IBM-Cloud/bluemix-go/client" 9 "github.com/IBM-Cloud/bluemix-go/http" 10 "github.com/IBM-Cloud/bluemix-go/rest" 11 "github.com/IBM-Cloud/bluemix-go/session" 12 ) 13 14 //ErrCodeAPICreation ... 15 const ErrCodeAPICreation = "APICreationError" 16 17 //ContainerServiceAPI is the Aramda K8s client ... 18 type ContainerServiceAPI interface { 19 Monitoring() Monitoring 20 Logging() Logging 21 Clusters() Clusters 22 VPCs() VPCs 23 WorkerPools() WorkerPool 24 Albs() Alb 25 Workers() Workers 26 Kms() Kms 27 Ingresses() Ingress 28 Subnets() Subnets 29 NlbDns() Nlbdns 30 Satellite() Satellite 31 DedicatedHost() DedicatedHost 32 DedicatedHostPool() DedicatedHostPool 33 DedicatedHostFlavor() DedicatedHostFlavor 34 35 //TODO Add other services 36 } 37 38 //VpcContainerService holds the client 39 type csService struct { 40 *client.Client 41 } 42 43 //New ... 44 func New(sess *session.Session) (ContainerServiceAPI, error) { 45 config := sess.Config.Copy() 46 err := config.ValidateConfigForService(bluemix.VpcContainerService) 47 if err != nil { 48 return nil, err 49 } 50 if config.HTTPClient == nil { 51 config.HTTPClient = http.NewHTTPClient(config) 52 } 53 tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{ 54 DefaultHeader: gohttp.Header{ 55 "X-Original-User-Agent": []string{config.UserAgent}, 56 "User-Agent": []string{http.UserAgent()}, 57 }, 58 HTTPClient: config.HTTPClient, 59 }) 60 if err != nil { 61 return nil, err 62 } 63 if config.IAMAccessToken == "" { 64 err := authentication.PopulateTokens(tokenRefreher, config) 65 if err != nil { 66 return nil, err 67 } 68 } 69 if config.Endpoint == nil { 70 ep, err := config.EndpointLocator.ContainerEndpoint() 71 if err != nil { 72 return nil, err 73 } 74 config.Endpoint = &ep 75 } 76 77 return &csService{ 78 Client: client.New(config, bluemix.VpcContainerService, tokenRefreher), 79 }, nil 80 } 81 82 //Clusters implements Clusters API 83 func (c *csService) Satellite() Satellite { 84 return newSatelliteAPI(c.Client) 85 } 86 87 //Clusters implements Clusters API 88 func (c *csService) Clusters() Clusters { 89 return newClusterAPI(c.Client) 90 } 91 92 //VPCs implements Cluster VPCs API 93 func (c *csService) VPCs() VPCs { 94 return newVPCsAPI(c.Client) 95 } 96 97 //Monitor implements Monitor API 98 func (c *csService) Monitoring() Monitoring { 99 return newMonitoringAPI(c.Client) 100 } 101 102 //Logging implements Monitor API 103 func (c *csService) Logging() Logging { 104 return newLoggingAPI(c.Client) 105 } 106 107 //WorkerPools implements Cluster WorkerPools API 108 func (c *csService) WorkerPools() WorkerPool { 109 return newWorkerPoolAPI(c.Client) 110 } 111 func (c *csService) Albs() Alb { 112 return newAlbAPI(c.Client) 113 } 114 func (c *csService) NlbDns() Nlbdns { 115 return newNlbdnsAPI(c.Client) 116 } 117 func (c *csService) Ingresses() Ingress { 118 return newIngressAPI(c.Client) 119 } 120 121 //Kms implements Cluster Kms API 122 func (c *csService) Kms() Kms { 123 return newKmsAPI(c.Client) 124 } 125 126 //Workers implements Cluster Workers API 127 func (c *csService) Workers() Workers { 128 return newWorkerAPI(c.Client) 129 } 130 131 //Subnets implements Cluster Subnets API 132 func (c *csService) Subnets() Subnets { 133 return newSubnetsAPI(c.Client) 134 } 135 136 //DedicatedHost implements DedicatedHost API 137 func (c *csService) DedicatedHost() DedicatedHost { 138 return newDedicatedHostAPI(c.Client) 139 } 140 141 //DedicatedHostPool implements DedicatedHostPool API 142 func (c *csService) DedicatedHostPool() DedicatedHostPool { 143 return newDedicatedHostPoolAPI(c.Client) 144 } 145 146 //DedicatedHostFlavor implements DedicatedHostFlavor API 147 func (c *csService) DedicatedHostFlavor() DedicatedHostFlavor { 148 return newDedicatedHostFlavorAPI(c.Client) 149 }