Skip to content

Commit

Permalink
Create schema for data source using resource schema
Browse files Browse the repository at this point in the history
  • Loading branch information
kasia-kujawa committed Nov 12, 2024
1 parent 223f422 commit 31a73af
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 102 deletions.
116 changes: 15 additions & 101 deletions castai/data_source_resource_rebalancing_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,110 +9,24 @@ import (
)

func dataSourceRebalancingSchedule() *schema.Resource {
return &schema.Resource{
dataSourceRebalancingSchedule := &schema.Resource{
Description: "Retrieve Rebalancing Schedule ",
ReadContext: dataSourceRebalancingScheduleRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "Name of the Rebalancing schedule",
},
"schedule": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cron": {
Type: schema.TypeString,
Computed: true,
Description: "Cron expression defining when the schedule should trigger.",
},
},
},
},
"trigger_conditions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"savings_percentage": {
Type: schema.TypeFloat,
Computed: true,
Description: "Defines the minimum percentage of savings expected.",
},
"ignore_savings": {
Type: schema.TypeBool,
Computed: true,
Description: "If true, the savings percentage will be ignored and the rebalancing will be triggered regardless of the savings percentage.",
},
},
},
},
"launch_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"node_ttl_seconds": {
Type: schema.TypeInt,
Computed: true,
Description: "Specifies amount of time since node creation before the node is allowed to be considered for automated rebalancing.",
},
"num_targeted_nodes": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum number of nodes that will be selected for rebalancing.",
},
"rebalancing_min_nodes": {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum number of nodes that should be kept in the cluster after rebalancing.",
},
"keep_drain_timeout_nodes": {
Type: schema.TypeBool,
Computed: true,
Description: "Defines whether the nodes that failed to get drained until a predefined timeout, will be kept with a rebalancing.cast.ai/status=drain-failed annotation instead of forcefully drained.",
},
"aggressive_mode": {
Type: schema.TypeBool,
Computed: true,
Description: "When enabled rebalancing will also consider problematic pods (pods without controller, job pods, pods with removal-disabled annotation) as not-problematic.",
},
"execution_conditions": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Computed: true,
Description: "Enables or disables the execution conditions.",
},
"achieved_savings_percentage": {
Type: schema.TypeInt,
Computed: true,
Description: "The percentage of the predicted savings that must be achieved in order to fully execute the plan." +
"If the savings are not achieved after creating the new nodes, the plan will fail and delete the created nodes.",
},
},
},
},
"selector": {
Type: schema.TypeString,
Computed: true,
Description: "Node selector in JSON format.",
},
"target_node_selection_algorithm": {
Type: schema.TypeString,
Computed: true,
Description: "Defines the algorithm used to select the target nodes for rebalancing.",
},
},
},
},
},
Schema: map[string]*schema.Schema{},
}

resourceRebalancingSchedule := resourceRebalancingSchedule()
for key, value := range resourceRebalancingSchedule.Schema {
dataSourceRebalancingSchedule.Schema[key] = value
if key != "name" {
// only name is provided in terraform configuration by user
// other parameters are "computed" from existing rebalancing schedule
dataSourceRebalancingSchedule.Schema[key].Computed = true
dataSourceRebalancingSchedule.Schema[key].Required = false

}
}
return dataSourceRebalancingSchedule
}

func dataSourceRebalancingScheduleRead(ctx context.Context, data *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
1 change: 1 addition & 0 deletions castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/data-sources/rebalancing_schedule.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 31a73af

Please sign in to comment.