Skip to content

Commit

Permalink
Taints working
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Mar 19, 2024
1 parent 44baee7 commit e6dadef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 58 deletions.
48 changes: 8 additions & 40 deletions civo/kubernetes/datasource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ func DataSourceKubernetesCluster() *schema.Resource {
Description: "A list of application installed",
},
"installed_applications": dataSourceApplicationSchema(),
"pools": dataSourcenodePoolSchema(),
"pools": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: nodePoolSchema(false),
},
},
"status": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -115,44 +121,6 @@ func DataSourceKubernetesCluster() *schema.Resource {
}
}

// schema for the node pool in the cluster
func dataSourcenodePoolSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"label": {
Type: schema.TypeString,
Computed: true,
Description: "Node pool label, if you don't provide one, we will generate one for you",
},
"node_count": {
Type: schema.TypeInt,
Computed: true,
Description: "The size of the pool",
},
"size": {
Type: schema.TypeString,
Computed: true,
Description: "The size of each node inside the pool",
},
"instance_names": {
Type: schema.TypeSet,
Computed: true,
Description: "A list of the instance in the pool",
Elem: &schema.Schema{Type: schema.TypeString},
},
"public_ip_node_pool": {
Type: schema.TypeBool,
Computed: true,
Description: "Node pool belongs to the public ip node pool",
},
},
},
}
}

// schema for the application in the cluster
func dataSourceApplicationSchema() *schema.Schema {
return &schema.Schema{
Expand Down Expand Up @@ -188,7 +156,7 @@ func dataSourceApplicationSchema() *schema.Schema {
func dataSourceKubernetesClusterRead(_ context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
apiClient := m.(*civogo.Client)

// overwrite the region if is define in the datasource
// overwrite the region if it is defined in the datasource
if region, ok := d.GetOk("region"); ok {
apiClient.Region = region.(string)
}
Expand Down
26 changes: 8 additions & 18 deletions civo/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,24 +158,14 @@ func expandNodePools(nodePools []interface{}) []civogo.KubernetesClusterPoolConf

// Initialize taints slice only if they are provided and valid
var taints []corev1.Taint
if rawTaints, ok := pool["taints"].([]interface{}); ok {
for _, rawTaint := range rawTaints {
taintMap, ok := rawTaint.(map[string]interface{})
if !ok {
continue
}

key, okKey := taintMap["key"].(string)
value, okValue := taintMap["value"].(string)
effect, okEffect := taintMap["effect"].(string)

if okKey && okValue && okEffect {
taints = append(taints, corev1.Taint{
Key: key,
Value: value,
Effect: corev1.TaintEffect(effect),
})
}
if taintSet, ok := pool["taint"].(*schema.Set); ok {
for _, taintInterface := range taintSet.List() {
taintMap := taintInterface.(map[string]interface{})
taints = append(taints, corev1.Taint{
Key: taintMap["key"].(string),
Value: taintMap["value"].(string),
Effect: corev1.TaintEffect(taintMap["effect"].(string)),
})
}
}

Expand Down

0 comments on commit e6dadef

Please sign in to comment.