Skip to content

Commit 6d3f7e1

Browse files
authored
Merge pull request #832 from rawmind0/clustersync
Cluster and cluster sync fixes
2 parents bb72b70 + e8b24f4 commit 6d3f7e1

3 files changed

Lines changed: 37 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
## 1.22.2 (Unreleased)
2+
3+
FEATURES:
4+
5+
6+
7+
ENHANCEMENTS:
8+
9+
* Added k8s specialized verbs `bind`, `escalate`, `impersonate` and `use` support, to `rancher2_global_role` and `rancher2_role_template` rules
10+
11+
BUG FIXES:
12+
13+
* Fix `rancher2_cluster_sync.state_confirm` behaviour https://github.com/rancher/terraform-provider-rancher2/issues/797
14+
* Fix `rancher2_cluster` monitoring flips on resource update https://github.com/rancher/terraform-provider-rancher2/issues/825
15+
116
## 1.22.1 (December 23, 2021)
217

318
FEATURES:
@@ -23,7 +38,7 @@ FEATURES:
2338

2439
ENHANCEMENTS:
2540

26-
* Updated `rancher2_cluster_v2` docs adding labels and annotations arguments. https://github.com/rancher/terraform-provider-rancher2/issues/784
41+
* Updated `rancher2_cluster_v2` docs adding labels and annotations arguments https://github.com/rancher/terraform-provider-rancher2/issues/784
2742
* Updated `findClusterRegistrationToken` function checking for correct Cluster Registration Token https://github.com/rancher/terraform-provider-rancher2/issues/791
2843
* Updated `getClusterKubeconfig` function to properly delete a cluster if cluster not available https://github.com/rancher/terraform-provider-rancher2/issues/788
2944
* Updated `rancher2_machine_config_v2` resource to allow its use by Rancher standard users https://github.com/rancher/terraform-provider-rancher2/issues/824

rancher2/resource_rancher2_cluster.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err
281281
"dockerRootDir": d.Get("docker_root_dir").(string),
282282
"fleetWorkspaceName": d.Get("fleet_workspace_name").(string),
283283
"enableClusterAlerting": d.Get("enable_cluster_alerting").(bool),
284+
"enableClusterMonitoring": d.Get("enable_cluster_monitoring").(bool),
284285
"enableNetworkPolicy": &enableNetworkPolicy,
285286
"istioEnabled": d.Get("enable_cluster_istio").(bool),
286287
"localClusterAuthEndpoint": expandClusterAuthEndpoint(d.Get("cluster_auth_endpoint").([]interface{})),
@@ -289,6 +290,11 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err
289290
"labels": toMapString(d.Get("labels").(map[string]interface{})),
290291
}
291292

293+
// cluster_monitoring is not updated here. Setting old `enable_cluster_monitoring` value if it was updated
294+
if d.HasChange("enable_cluster_monitoring") {
295+
update["enableClusterMonitoring"] = !d.Get("enable_cluster_monitoring").(bool)
296+
}
297+
292298
if clusterTemplateID, ok := d.Get("cluster_template_id").(string); ok && len(clusterTemplateID) > 0 {
293299
update["clusterTemplateId"] = clusterTemplateID
294300
if clusterTemplateRevisionID, ok := d.Get("cluster_template_revision_id").(string); ok && len(clusterTemplateRevisionID) > 0 {
@@ -373,6 +379,7 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err
373379
return fmt.Errorf("[ERROR] waiting for cluster (%s) to be updated: %s", newCluster.ID, waitErr)
374380
}
375381

382+
// cluster_monitoring is updated here
376383
if d.HasChange("enable_cluster_monitoring") || d.HasChange("cluster_monitoring_input") {
377384
clusterResource := &norman.Resource{
378385
ID: newCluster.ID,
@@ -381,12 +388,6 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err
381388
Actions: newCluster.Actions,
382389
}
383390
enableMonitoring := d.Get("enable_cluster_monitoring").(bool)
384-
if !enableMonitoring && len(newCluster.Actions[monitoringActionDisable]) > 0 {
385-
err = client.APIBaseClient.Action(managementClient.ClusterType, monitoringActionDisable, clusterResource, nil, nil)
386-
if err != nil {
387-
return err
388-
}
389-
}
390391
if enableMonitoring {
391392
monitoringInput := expandMonitoringInput(d.Get("cluster_monitoring_input").([]interface{}))
392393
if len(newCluster.Actions[monitoringActionEnable]) > 0 {
@@ -431,6 +432,11 @@ func resourceRancher2ClusterUpdate(d *schema.ResourceData, meta interface{}) err
431432
return err
432433
}
433434
}
435+
} else if len(newCluster.Actions[monitoringActionDisable]) > 0 {
436+
err = client.APIBaseClient.Action(managementClient.ClusterType, monitoringActionDisable, clusterResource, nil, nil)
437+
if err != nil {
438+
return err
439+
}
434440
}
435441
}
436442

rancher2/resource_rancher2_cluster_sync.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ func resourceRancher2ClusterSyncCreate(d *schema.ResourceData, meta interface{})
3131
if err != nil {
3232
return err
3333
}
34+
if retries, ok := d.Get("state_confirm").(int); ok && retries > 1 {
35+
for i := 1; i < retries; i++ {
36+
time.Sleep(rancher2RetriesWait * time.Second)
37+
cluster, err = meta.(*Config).WaitForClusterState(clusterID, clusterActiveCondition, d.Timeout(schema.TimeoutCreate))
38+
if err != nil {
39+
return err
40+
}
41+
}
42+
}
3443

3544
if cluster.EnableClusterMonitoring && d.Get("wait_monitoring").(bool) {
3645
_, err := meta.(*Config).WaitForClusterState(clusterID, clusterMonitoringEnabledCondition, d.Timeout(schema.TimeoutCreate))

0 commit comments

Comments
 (0)