Skip to content

Commit 9406311

Browse files
Tapas Sharmahkantare
Tapas Sharma
authored andcommitted
Added support for Satellite-v1 Endpoints API
1. Added new endpoint locator for returning the link endpoint 2. Added new container-v2 API to get location details 3. Added GET,POST,DELETE for satellite endpoints Signed-off-by: Tapas Sharma <[email protected]>
1 parent e7648c2 commit 9406311

File tree

5 files changed

+471
-0
lines changed

5 files changed

+471
-0
lines changed

api/container/containerv2/api_service.go

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type ContainerServiceAPI interface {
2727
Ingresses() Ingress
2828
Subnets() Subnets
2929
NlbDns() Nlbdns
30+
Satellite() Satellite
3031

3132
//TODO Add other services
3233
}
@@ -74,6 +75,11 @@ func New(sess *session.Session) (ContainerServiceAPI, error) {
7475
}, nil
7576
}
7677

78+
//Clusters implements Clusters API
79+
func (c *csService) Satellite() Satellite {
80+
return newSatelliteAPI(c.Client)
81+
}
82+
7783
//Clusters implements Clusters API
7884
func (c *csService) Clusters() Clusters {
7985
return newClusterAPI(c.Client)
+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package containerv2
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/IBM-Cloud/bluemix-go/client"
7+
)
8+
9+
type SatelliteLocationInfo struct {
10+
ID string `json:"id"`
11+
Name string `json:"name"`
12+
Region string `json:"region"`
13+
ResourceGroup string `json:"resourceGroup"`
14+
ResourceGroupName string `json:"resourceGroupName"`
15+
PodSubnet string `json:"podSubnet"`
16+
ServiceSubnet string `json:"serviceSubnet"`
17+
CreatedDate string `json:"createdDate"`
18+
MasterKubeVersion string `json:"masterKubeVersion"`
19+
TargetVersion string `json:"targetVersion"`
20+
WorkerCount int `json:"workerCount"`
21+
Location string `json:"location"`
22+
Datacenter string `json:"datacenter"`
23+
MultiAzCapable bool `json:"multiAzCapable"`
24+
Provider string `json:"provider"`
25+
State string `json:"state"`
26+
Status string `json:"status"`
27+
VersionEOS string `json:"versionEOS"`
28+
IsPaid bool `json:"isPaid"`
29+
Entitlement string `json:"entitlement"`
30+
Type string `json:"type"`
31+
Addons interface{} `json:"addons"`
32+
EtcdPort string `json:"etcdPort"`
33+
MasterURL string `json:"masterURL"`
34+
Ingress struct {
35+
Hostname string `json:"hostname"`
36+
SecretName string `json:"secretName"`
37+
Status string `json:"status"`
38+
Message string `json:"message"`
39+
} `json:"ingress"`
40+
CaCertRotationStatus struct {
41+
Status string `json:"status"`
42+
ActionTriggerDate string `json:"actionTriggerDate"`
43+
ActionCompletedDate string `json:"actionCompletedDate"`
44+
} `json:"caCertRotationStatus"`
45+
ImageSecurityEnabled bool `json:"imageSecurityEnabled"`
46+
DisableAutoUpdate bool `json:"disableAutoUpdate"`
47+
Crn string `json:"crn"`
48+
WorkerZones []string `json:"workerZones"`
49+
Lifecycle struct {
50+
MasterStatus string `json:"masterStatus"`
51+
MasterStatusModifiedDate string `json:"masterStatusModifiedDate"`
52+
MasterHealth string `json:"masterHealth"`
53+
MasterState string `json:"masterState"`
54+
ModifiedDate string `json:"modifiedDate"`
55+
} `json:"lifecycle"`
56+
ServiceEndpoints struct {
57+
PrivateServiceEndpointEnabled bool `json:"privateServiceEndpointEnabled"`
58+
PrivateServiceEndpointURL string `json:"privateServiceEndpointURL"`
59+
PublicServiceEndpointEnabled bool `json:"publicServiceEndpointEnabled"`
60+
PublicServiceEndpointURL string `json:"publicServiceEndpointURL"`
61+
} `json:"serviceEndpoints"`
62+
Features struct {
63+
KeyProtectEnabled bool `json:"keyProtectEnabled"`
64+
PullSecretApplied bool `json:"pullSecretApplied"`
65+
} `json:"features"`
66+
Vpcs interface{} `json:"vpcs"`
67+
CosConfig struct {
68+
Region string `json:"region"`
69+
Bucket string `json:"bucket"`
70+
Endpoint string `json:"endpoint"`
71+
ServiceInstance struct {
72+
Crn string `json:"crn"`
73+
} `json:"serviceInstance"`
74+
} `json:"cos_config"`
75+
Description string `json:"description"`
76+
Deployments struct {
77+
Enabled bool `json:"enabled"`
78+
Message string `json:"message"`
79+
} `json:"deployments"`
80+
Hosts struct {
81+
Total int `json:"total"`
82+
Available int `json:"available"`
83+
} `json:"hosts"`
84+
Iaas struct {
85+
Provider string `json:"provider"`
86+
Region string `json:"region"`
87+
} `json:"iaas"`
88+
OpenVpnServerPort int `json:"open_vpn_server_port"`
89+
}
90+
91+
type Satellite interface {
92+
GetLocationInfo(name string, target ClusterTargetHeader) (*SatelliteLocationInfo, error)
93+
}
94+
95+
type satellite struct {
96+
client *client.Client
97+
pathPrefix string
98+
}
99+
100+
func newSatelliteAPI(c *client.Client) Satellite {
101+
return &satellite{
102+
client: c,
103+
}
104+
}
105+
106+
func (s *satellite) GetLocationInfo(name string, target ClusterTargetHeader) (*SatelliteLocationInfo, error) {
107+
SatLocationInfo := &SatelliteLocationInfo{}
108+
rawURL := fmt.Sprintf("/v2/satellite/getController?controller=%s", name)
109+
_, err := s.client.Get(rawURL, &SatLocationInfo, target.ToMap())
110+
if err != nil {
111+
return nil, err
112+
}
113+
return SatLocationInfo, err
114+
}
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package satellitev1
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+
//SatelliteServiceAPI is the Aramda K8s client ...
18+
type SatelliteServiceAPI interface {
19+
Endpoint() Endpoint
20+
21+
//TODO Add other services
22+
}
23+
24+
type satService struct {
25+
*client.Client
26+
}
27+
28+
func New(sess *session.Session) (SatelliteServiceAPI, error) {
29+
config := sess.Config.Copy()
30+
err := config.ValidateConfigForService(bluemix.VpcContainerService)
31+
if err != nil {
32+
return nil, err
33+
}
34+
if config.HTTPClient == nil {
35+
config.HTTPClient = http.NewHTTPClient(config)
36+
}
37+
tokenRefreher, err := authentication.NewIAMAuthRepository(config, &rest.Client{
38+
DefaultHeader: gohttp.Header{
39+
"User-Agent": []string{http.UserAgent()},
40+
},
41+
HTTPClient: config.HTTPClient,
42+
})
43+
if err != nil {
44+
return nil, err
45+
}
46+
if config.IAMAccessToken == "" {
47+
err := authentication.PopulateTokens(tokenRefreher, config)
48+
if err != nil {
49+
return nil, err
50+
}
51+
}
52+
if config.Endpoint == nil {
53+
ep, err := config.EndpointLocator.SatelliteEndpoint()
54+
if err != nil {
55+
return nil, err
56+
}
57+
config.Endpoint = &ep
58+
}
59+
60+
return &satService{
61+
Client: client.New(config, bluemix.VpcContainerService, tokenRefreher),
62+
}, nil
63+
}
64+
65+
//Clusters implements Clusters API
66+
func (c *satService) Endpoint() Endpoint {
67+
return newEndpointAPI(c.Client)
68+
}

0 commit comments

Comments
 (0)