Skip to content

Commit 78e71ce

Browse files
authored
[PWX-24574] Added GetInstance() API for oracle cloud provider (#120)
Signed-off-by: Vinayak Shinde <vinayakshnd@gmail.com>
1 parent 48dfb6c commit 78e71ce

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

backoff/exponential.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ func (e *exponentialBackoff) InspectInstanceGroupForInstance(instanceID string)
8989
return instanceGroupInfo, origErr
9090
}
9191

92+
func (e *exponentialBackoff) GetInstance(displayName string) (interface{}, error) {
93+
var (
94+
instanceDetails interface{}
95+
origErr error
96+
)
97+
conditionFn := func() (bool, error) {
98+
instanceDetails, origErr = e.cloudOps.GetInstance(displayName)
99+
msg := fmt.Sprintf("Failed to get instance details for instance: %v.", displayName)
100+
return e.handleError(origErr, msg)
101+
}
102+
expErr := wait.ExponentialBackoff(e.backoff, conditionFn)
103+
if expErr == wait.ErrWaitTimeout {
104+
return nil, cloudops.NewStorageError(cloudops.ErrExponentialTimeout, origErr.Error(), "")
105+
}
106+
return instanceDetails, origErr
107+
}
108+
92109
func (e *exponentialBackoff) SetInstanceGroupSize(instanceGroupID string,
93110
count int64,
94111
timeout time.Duration) error {

cloudops.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ type Compute interface {
9797
// InspectInstanceGroupForInstance inspects the instance group to which the
9898
// cloud instance with given ID belongs
9999
InspectInstanceGroupForInstance(instanceID string) (*InstanceGroupInfo, error)
100+
// GetInstance returns cloud provider specific instance details
101+
GetInstance(displayName string) (interface{}, error)
100102
// SetInstanceGroupSize sets desired node count per availability zone
101103
// for given instance group
102104
SetInstanceGroupSize(instanceGroupID string,

oracle/oracle.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,26 @@ func (o *oracleOps) InspectInstance(instanceID string) (*cloudops.InstanceInfo,
280280
}, nil
281281
}
282282

283+
func (o *oracleOps) GetInstance(displayName string) (interface{}, error) {
284+
listInstanceReq := core.ListInstancesRequest{
285+
DisplayName: common.String(displayName),
286+
CompartmentId: common.String(o.compartmentID),
287+
}
288+
289+
listInstanceResp, err := o.compute.ListInstances(context.Background(), listInstanceReq)
290+
if err != nil {
291+
return nil, err
292+
}
293+
if len(listInstanceResp.Items) == 0 {
294+
return nil, fmt.Errorf("no oracle instance found with display name: %s", displayName)
295+
}
296+
// Currently, torpedo uses this API to fetch details of the instance created
297+
// by OKE. OKE ensures that all the worker nodes created, have unique display
298+
// names. In future, if we require to use this API to get details of vanilla
299+
// compute instances, then we can modify below array indexing.
300+
return listInstanceResp.Items[0], nil
301+
}
302+
283303
func (o *oracleOps) InspectInstanceGroupForInstance(instanceID string) (*cloudops.InstanceGroupInfo, error) {
284304
getNodePoolReq := containerengine.GetNodePoolRequest{
285305
NodePoolId: &o.poolID,
@@ -777,6 +797,10 @@ func (o *oracleOps) DeleteInstance(instanceID string, zone string, timeout time.
777797
}
778798
}
779799

800+
if nodePoolID == nil {
801+
return fmt.Errorf("node pool containing instance [%s] not found", instanceID)
802+
}
803+
780804
nodeDeleteReq := containerengine.DeleteNodeRequest{
781805
NodePoolId: nodePoolID,
782806
NodeId: &instanceID,

unsupported/unsupported.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ func (u *unsupportedCompute) InspectInstanceGroupForInstance(instanceID string)
3535
}
3636
}
3737

38+
func (u *unsupportedCompute) GetInstance(displayName string) (interface{}, error) {
39+
return nil, &cloudops.ErrNotSupported{
40+
Operation: "GetInstance",
41+
}
42+
}
43+
3844
func (u *unsupportedCompute) SetInstanceGroupSize(instanceGroupID string,
3945
count int64,
4046
timeout time.Duration) error {

0 commit comments

Comments
 (0)