Skip to content

Commit 742e30b

Browse files
aseembajajMaxrovr
authored andcommitted
Added - Support for Preemptible Worker Nodes
1 parent 86f3837 commit 742e30b

File tree

4 files changed

+180
-0
lines changed

4 files changed

+180
-0
lines changed

internal/service/containerengine/containerengine_node_pool_resource.go

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,50 @@ func ContainerengineNodePoolResource() *schema.Resource {
145145
Type: schema.TypeString,
146146
},
147147
},
148+
"preemptible_node_config": {
149+
Type: schema.TypeList,
150+
Optional: true,
151+
Computed: true,
152+
MaxItems: 1,
153+
MinItems: 1,
154+
Elem: &schema.Resource{
155+
Schema: map[string]*schema.Schema{
156+
// Required
157+
"preemption_action": {
158+
Type: schema.TypeList,
159+
Required: true,
160+
MaxItems: 1,
161+
MinItems: 1,
162+
Elem: &schema.Resource{
163+
Schema: map[string]*schema.Schema{
164+
// Required
165+
"type": {
166+
Type: schema.TypeString,
167+
Required: true,
168+
DiffSuppressFunc: tfresource.EqualIgnoreCaseSuppressDiff,
169+
ValidateFunc: validation.StringInSlice([]string{
170+
"TERMINATE",
171+
}, true),
172+
},
173+
174+
// Optional
175+
"is_preserve_boot_volume": {
176+
Type: schema.TypeBool,
177+
Optional: true,
178+
Computed: true,
179+
},
180+
181+
// Computed
182+
},
183+
},
184+
},
185+
186+
// Optional
187+
188+
// Computed
189+
},
190+
},
191+
},
148192

149193
// Computed
150194
},
@@ -1589,6 +1633,17 @@ func (s *ContainerengineNodePoolResourceCrud) mapToNodePoolPlacementConfigDetail
15891633
}
15901634
}
15911635

1636+
if preemptibleNodeConfig, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "preemptible_node_config")); ok {
1637+
if tmpList := preemptibleNodeConfig.([]interface{}); len(tmpList) > 0 {
1638+
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "preemptible_node_config"), 0)
1639+
tmp, err := s.mapToPreemptibleNodeConfigDetails(fieldKeyFormatNextLevel)
1640+
if err != nil {
1641+
return result, fmt.Errorf("unable to convert preemptible_node_config, encountered error: %v", err)
1642+
}
1643+
result.PreemptibleNodeConfig = &tmp
1644+
}
1645+
}
1646+
15921647
if subnetId, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "subnet_id")); ok {
15931648
tmp := subnetId.(string)
15941649
result.SubnetId = &tmp
@@ -1610,6 +1665,10 @@ func NodePoolPlacementConfigDetailsToMap(obj oci_containerengine.NodePoolPlaceme
16101665

16111666
result["fault_domains"] = obj.FaultDomains
16121667

1668+
if obj.PreemptibleNodeConfig != nil {
1669+
result["preemptible_node_config"] = []interface{}{PreemptibleNodeConfigDetailsToMap(obj.PreemptibleNodeConfig)}
1670+
}
1671+
16131672
if obj.SubnetId != nil {
16141673
result["subnet_id"] = string(*obj.SubnetId)
16151674
}
@@ -1767,6 +1826,78 @@ func NodeSourceOptionToMap(obj *oci_containerengine.NodeSourceOption) map[string
17671826
return result
17681827
}
17691828

1829+
func (s *ContainerengineNodePoolResourceCrud) mapToPreemptibleNodeConfigDetails(fieldKeyFormat string) (oci_containerengine.PreemptibleNodeConfigDetails, error) {
1830+
result := oci_containerengine.PreemptibleNodeConfigDetails{}
1831+
1832+
if preemptionAction, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "preemption_action")); ok {
1833+
if tmpList := preemptionAction.([]interface{}); len(tmpList) > 0 {
1834+
fieldKeyFormatNextLevel := fmt.Sprintf("%s.%d.%%s", fmt.Sprintf(fieldKeyFormat, "preemption_action"), 0)
1835+
tmp, err := s.mapToPreemptionAction(fieldKeyFormatNextLevel)
1836+
if err != nil {
1837+
return result, fmt.Errorf("unable to convert preemption_action, encountered error: %v", err)
1838+
}
1839+
result.PreemptionAction = tmp
1840+
}
1841+
}
1842+
1843+
return result, nil
1844+
}
1845+
1846+
func PreemptibleNodeConfigDetailsToMap(obj *oci_containerengine.PreemptibleNodeConfigDetails) map[string]interface{} {
1847+
result := map[string]interface{}{}
1848+
1849+
if obj.PreemptionAction != nil {
1850+
preemptionActionArray := []interface{}{}
1851+
if preemptionActionMap := PreemptionActionToMap(&obj.PreemptionAction); preemptionActionMap != nil {
1852+
preemptionActionArray = append(preemptionActionArray, preemptionActionMap)
1853+
}
1854+
result["preemption_action"] = preemptionActionArray
1855+
}
1856+
1857+
return result
1858+
}
1859+
1860+
func (s *ContainerengineNodePoolResourceCrud) mapToPreemptionAction(fieldKeyFormat string) (oci_containerengine.PreemptionAction, error) {
1861+
var baseObject oci_containerengine.PreemptionAction
1862+
//discriminator
1863+
typeRaw, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "type"))
1864+
var type_ string
1865+
if ok {
1866+
type_ = typeRaw.(string)
1867+
} else {
1868+
type_ = "" // default value
1869+
}
1870+
switch strings.ToLower(type_) {
1871+
case strings.ToLower("TERMINATE"):
1872+
details := oci_containerengine.TerminatePreemptionAction{}
1873+
if isPreserveBootVolume, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_preserve_boot_volume")); ok {
1874+
tmp := isPreserveBootVolume.(bool)
1875+
details.IsPreserveBootVolume = &tmp
1876+
}
1877+
baseObject = details
1878+
default:
1879+
return nil, fmt.Errorf("unknown type '%v' was specified", type_)
1880+
}
1881+
return baseObject, nil
1882+
}
1883+
1884+
func PreemptionActionToMap(obj *oci_containerengine.PreemptionAction) map[string]interface{} {
1885+
result := map[string]interface{}{}
1886+
switch v := (*obj).(type) {
1887+
case oci_containerengine.TerminatePreemptionAction:
1888+
result["type"] = "TERMINATE"
1889+
1890+
if v.IsPreserveBootVolume != nil {
1891+
result["is_preserve_boot_volume"] = bool(*v.IsPreserveBootVolume)
1892+
}
1893+
default:
1894+
log.Printf("[WARN] Received 'type' of unknown type %v", *obj)
1895+
return nil
1896+
}
1897+
1898+
return result
1899+
}
1900+
17701901
func placementConfigsHashCodeForSets(v interface{}) int {
17711902
var buf bytes.Buffer
17721903
m := v.(map[string]interface{})
@@ -1776,6 +1907,29 @@ func placementConfigsHashCodeForSets(v interface{}) int {
17761907
if capacityReservationId, ok := m["capacity_reservation_id"]; ok && capacityReservationId != "" {
17771908
buf.WriteString(fmt.Sprintf("%v-", capacityReservationId))
17781909
}
1910+
<<<<<<< ours
1911+
if faultDomains, ok := m["fault_domains"]; ok && faultDomains != "" {
1912+
}
1913+
if preemptibleNodeConfig, ok := m["preemptible_node_config"]; ok {
1914+
if tmpList := preemptibleNodeConfig.([]interface{}); len(tmpList) > 0 {
1915+
buf.WriteString("preemptible_node_config-")
1916+
preemptibleNodeConfigRaw := tmpList[0].(map[string]interface{})
1917+
if preemptionAction, ok := preemptibleNodeConfigRaw["preemption_action"]; ok {
1918+
if tmpList := preemptionAction.([]interface{}); len(tmpList) > 0 {
1919+
buf.WriteString("preemption_action-")
1920+
preemptionActionRaw := tmpList[0].(map[string]interface{})
1921+
if isPreserveBootVolume, ok := preemptionActionRaw["is_preserve_boot_volume"]; ok {
1922+
buf.WriteString(fmt.Sprintf("%v-", isPreserveBootVolume))
1923+
}
1924+
if type_, ok := preemptionActionRaw["type"]; ok && type_ != "" {
1925+
buf.WriteString(fmt.Sprintf("%v-", type_))
1926+
}
1927+
}
1928+
}
1929+
}
1930+
}
1931+
=======
1932+
>>>>>>> theirs
17791933
if subnetId, ok := m["subnet_id"]; ok && subnetId != "" {
17801934
buf.WriteString(fmt.Sprintf("%v-", subnetId))
17811935
}

website/docs/d/containerengine_node_pool.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ The following attributes are exported:
6060
* `availability_domain` - The availability domain in which to place nodes. Example: `Uocm:PHX-AD-1`
6161
* `capacity_reservation_id` - The OCID of the compute capacity reservation in which to place the compute instance.
6262
* `fault_domains` - A list of fault domains in which to place nodes.
63+
* `preemptible_node_config` - Configuration options for preemptible nodes.
64+
* `preemption_action` - The action to run when the preemptible node is interrupted for eviction.
65+
* `is_preserve_boot_volume` - Whether to preserve the boot volume that was used to launch the preemptible instance when the instance is terminated. Defaults to false if not specified.
66+
* `type` - The type of action to run when the instance is interrupted for eviction.
6367
* `subnet_id` - The OCID of the subnet in which to place nodes.
6468
* `size` - The number of nodes in the node pool.
6569
* `node_eviction_node_pool_settings` - Node Eviction Details configuration

website/docs/d/containerengine_node_pools.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ The following attributes are exported:
7474
* `availability_domain` - The availability domain in which to place nodes. Example: `Uocm:PHX-AD-1`
7575
* `capacity_reservation_id` - The OCID of the compute capacity reservation in which to place the compute instance.
7676
* `fault_domains` - A list of fault domains in which to place nodes.
77+
* `preemptible_node_config` - Configuration options for preemptible nodes.
78+
* `preemption_action` - The action to run when the preemptible node is interrupted for eviction.
79+
* `is_preserve_boot_volume` - Whether to preserve the boot volume that was used to launch the preemptible instance when the instance is terminated. Defaults to false if not specified.
80+
* `type` - The type of action to run when the instance is interrupted for eviction.
7781
* `subnet_id` - The OCID of the subnet in which to place nodes.
7882
* `size` - The number of nodes in the node pool.
7983
* `node_eviction_node_pool_settings` - Node Eviction Details configuration

website/docs/r/containerengine_node_pool.html.markdown

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ resource "oci_containerengine_node_pool" "test_node_pool" {
4242
#Optional
4343
capacity_reservation_id = oci_containerengine_capacity_reservation.test_capacity_reservation.id
4444
fault_domains = var.node_pool_node_config_details_placement_configs_fault_domains
45+
preemptible_node_config {
46+
#Required
47+
preemption_action {
48+
#Required
49+
type = var.node_pool_node_config_details_placement_configs_preemptible_node_config_preemption_action_type
50+
51+
#Optional
52+
is_preserve_boot_volume = var.node_pool_node_config_details_placement_configs_preemptible_node_config_preemption_action_is_preserve_boot_volume
53+
}
54+
}
4555
}
4656
size = var.node_pool_node_config_details_size
4757
@@ -119,6 +129,10 @@ The following arguments are supported:
119129
* `availability_domain` - (Required) (Updatable) The availability domain in which to place nodes. Example: `Uocm:PHX-AD-1`
120130
* `capacity_reservation_id` - (Optional) (Updatable) The OCID of the compute capacity reservation in which to place the compute instance.
121131
* `fault_domains` - (Optional) (Updatable) A list of fault domains in which to place nodes.
132+
* `preemptible_node_config` - (Optional) (Updatable) Configuration options for preemptible nodes.
133+
* `preemption_action` - (Required) (Updatable) The action to run when the preemptible node is interrupted for eviction.
134+
* `is_preserve_boot_volume` - (Optional) (Updatable) Whether to preserve the boot volume that was used to launch the preemptible instance when the instance is terminated. Defaults to false if not specified.
135+
* `type` - (Required) (Updatable) The type of action to run when the instance is interrupted for eviction.
122136
* `subnet_id` - (Required) (Updatable) The OCID of the subnet in which to place nodes.
123137
* `size` - (Required) (Updatable) The number of nodes that should be in the node pool.
124138
* `node_eviction_node_pool_settings` - (Optional) (Updatable) Node Eviction Details configuration
@@ -174,6 +188,10 @@ The following attributes are exported:
174188
* `availability_domain` - The availability domain in which to place nodes. Example: `Uocm:PHX-AD-1`
175189
* `capacity_reservation_id` - The OCID of the compute capacity reservation in which to place the compute instance.
176190
* `fault_domains` - A list of fault domains in which to place nodes.
191+
* `preemptible_node_config` - Configuration options for preemptible nodes.
192+
* `preemption_action` - The action to run when the preemptible node is interrupted for eviction.
193+
* `is_preserve_boot_volume` - Whether to preserve the boot volume that was used to launch the preemptible instance when the instance is terminated. Defaults to false if not specified.
194+
* `type` - The type of action to run when the instance is interrupted for eviction.
177195
* `subnet_id` - The OCID of the subnet in which to place nodes.
178196
* `size` - The number of nodes in the node pool.
179197
* `node_eviction_node_pool_settings` - Node Eviction Details configuration

0 commit comments

Comments
 (0)