Skip to content

Commit 4e34792

Browse files
authored
Merge pull request #128 from oracle/jah/127
Fixes #127 - delete terminal nodes
2 parents 8fb26e6 + bdce41c commit 4e34792

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

pkg/oci/client/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ func (c *client) GetInstanceByNodeName(nodeName string) (*baremetal.Instance, er
222222
}
223223
}
224224

225-
func isInstanceInTerminalState(instance *baremetal.Instance) bool {
225+
// IsInstanceInTerminalState returns true if the instance is in a terminal state, false otherwise.
226+
func IsInstanceInTerminalState(instance *baremetal.Instance) bool {
226227
return instance.State == baremetal.ResourceTerminated ||
227228
instance.State == baremetal.ResourceTerminating ||
228229
instance.State == "UNKNOWN"
@@ -231,7 +232,7 @@ func isInstanceInTerminalState(instance *baremetal.Instance) bool {
231232
func getNonTerminalInstances(instances []baremetal.Instance) []baremetal.Instance {
232233
var result []baremetal.Instance
233234
for _, instance := range instances {
234-
if !isInstanceInTerminalState(&instance) {
235+
if !IsInstanceInTerminalState(&instance) {
235236
result = append(result, instance)
236237
}
237238
}
@@ -266,7 +267,7 @@ func (c *client) findInstanceByNodeNameIsVnic(nodeName string) (*baremetal.Insta
266267
return nil, err
267268
}
268269

269-
if isInstanceInTerminalState(instance) {
270+
if IsInstanceInTerminalState(instance) {
270271
glog.Warningf("Instance %q is in state %q which is a terminal state", instance.ID, instance.State)
271272
continue
272273
}

pkg/oci/client/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ func TestInstanceTerminalState(t *testing.T) {
5353

5454
for name, tc := range testCases {
5555
t.Run(name, func(t *testing.T) {
56-
result := isInstanceInTerminalState(&baremetal.Instance{
56+
result := IsInstanceInTerminalState(&baremetal.Instance{
5757
State: tc.state,
5858
})
5959
if result != tc.expected {
60-
t.Errorf("isInstanceInTerminalState(%q) = %v ; wanted %v", tc.state, result, tc.expected)
60+
t.Errorf("IsInstanceInTerminalState(%q) = %v ; wanted %v", tc.state, result, tc.expected)
6161
}
6262
})
6363
}

pkg/oci/instances.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ func (cp *CloudProvider) CurrentNodeName(hostname string) (types.NodeName, error
143143
func (cp *CloudProvider) InstanceExistsByProviderID(providerID string) (bool, error) {
144144
glog.V(4).Infof("InstanceExistsByProviderID(%q) called", providerID)
145145
instanceID := util.MapProviderIDToInstanceID(providerID)
146-
r, err := cp.client.GetInstance(instanceID)
147-
return (r != nil), err
146+
instance, err := cp.client.GetInstance(instanceID)
147+
if client.IsNotFound(err) {
148+
return false, nil
149+
}
150+
if err != nil {
151+
return false, err
152+
}
153+
154+
return !client.IsInstanceInTerminalState(instance), nil
148155
}

0 commit comments

Comments
 (0)