Skip to content

Commit c5cb7e7

Browse files
authored
feat: add support of maintenance_window (#139)
1 parent f383821 commit c5cb7e7

File tree

7 files changed

+551
-58
lines changed

7 files changed

+551
-58
lines changed

cloud/data_source_pulsar_cluster.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,40 @@ func dataSourcePulsarCluster() *schema.Resource {
287287
Computed: true,
288288
Description: descriptions["iam_policy"],
289289
},
290+
"maintenance_window": {
291+
Type: schema.TypeList,
292+
Computed: true,
293+
Description: "Maintenance window configuration for the Pulsar cluster",
294+
Elem: &schema.Resource{
295+
Schema: map[string]*schema.Schema{
296+
"window": {
297+
Type: schema.TypeList,
298+
Computed: true,
299+
Description: "Maintenance execution window",
300+
Elem: &schema.Resource{
301+
Schema: map[string]*schema.Schema{
302+
"start_time": {
303+
Type: schema.TypeString,
304+
Computed: true,
305+
Description: "Start time of the maintenance window",
306+
},
307+
308+
"duration": {
309+
Type: schema.TypeString,
310+
Computed: true,
311+
Description: "Duration of the maintenance window",
312+
},
313+
},
314+
},
315+
},
316+
"recurrence": {
317+
Type: schema.TypeString,
318+
Computed: true,
319+
Description: "Recurrence pattern for maintenance (0-6 for Monday to Sunday)",
320+
},
321+
},
322+
},
323+
},
290324
},
291325
}
292326
}
@@ -449,6 +483,14 @@ func dataSourcePulsarClusterRead(ctx context.Context, d *schema.ResourceData, me
449483
}
450484
_ = d.Set("apply_lakehouse_to_all_topics", applyToAllTopics)
451485

486+
// Set maintenance window if configured
487+
if pulsarCluster.Spec.MaintenanceWindow != nil {
488+
err = d.Set("maintenance_window", flattenMaintenanceWindow(pulsarCluster.Spec.MaintenanceWindow))
489+
if err != nil {
490+
return diag.FromErr(fmt.Errorf("ERROR_READ_PULSAR_CLUSTER_MAINTENANCE_WINDOW: %w", err))
491+
}
492+
}
493+
452494
d.SetId(fmt.Sprintf("%s/%s", pulsarCluster.Namespace, pulsarCluster.Name))
453495
return nil
454496
}

cloud/pulsar_cluster_config.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,40 @@ func flattenCategories(in []string) []interface{} {
8181
}
8282
return att
8383
}
84+
85+
func flattenMaintenanceWindow(in *cloudv1alpha1.MaintenanceWindow) []interface{} {
86+
if in == nil {
87+
return []interface{}{}
88+
}
89+
90+
att := make(map[string]interface{})
91+
92+
if in.Window != nil {
93+
att["window"] = flattenWindow(in.Window)
94+
}
95+
if in.Recurrence != "" {
96+
att["recurrence"] = in.Recurrence
97+
}
98+
99+
return []interface{}{att}
100+
}
101+
102+
func flattenWindow(in *cloudv1alpha1.Window) []interface{} {
103+
if in == nil {
104+
return []interface{}{}
105+
}
106+
107+
att := make(map[string]interface{})
108+
109+
// Set StartTime if provided
110+
if in.StartTime != "" {
111+
att["start_time"] = in.StartTime
112+
}
113+
114+
// Set Duration if provided
115+
if in.Duration != nil {
116+
att["duration"] = in.Duration.Duration.String()
117+
}
118+
119+
return []interface{}{att}
120+
}

0 commit comments

Comments
 (0)