Skip to content

Commit 3ddc9cf

Browse files
authored
Merge pull request #830 from rawmind0/kubeconfig
Fix getClusterKubeconfig function to properly generate kubeconfig for Rancher lower than v2.6.x
2 parents 35084fe + c9f6711 commit 3ddc9cf

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 1.22.1 (December 23, 2021)
2+
3+
FEATURES:
4+
5+
6+
7+
ENHANCEMENTS:
8+
9+
10+
BUG FIXES:
11+
12+
* Fix `getClusterKubeconfig` function to properly generate kubeconfig when `rancher2_cluster.LocalClusterAuthEndpoint` is enabled for Rancher lower than v2.6.x https://github.com/rancher/terraform-provider-rancher2/issues/829
13+
114
## 1.22.0 (December 22, 2021)
215

316
FEATURES:

docs/resources/cluster.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ The following attributes are exported:
616616
* `default_project_id` - (Computed) Default project ID for the cluster (string)
617617
* `driver` - (Computed) The driver used for the Cluster. `imported`, `azurekubernetesservice`, `amazonelasticcontainerservice`, `googlekubernetesengine` and `rancherKubernetesEngine` are supported (string)
618618
* `istio_enabled` - (Computed) Is istio enabled at cluster? Just for Rancher v2.3.x and above (bool)
619-
* `kube_config` - (Computed/Sensitive) Kube Config generated for the cluster (string)
619+
* `kube_config` - (Computed/Sensitive) Kube Config generated for the cluster. Note: For Rancher 2.6.0 and above, when the cluster has `cluster_auth_endpoint` enabled, the kube_config will not be available until the cluster is `connected` (string)
620620
* `ca_cert` - (Computed/Sensitive) K8s cluster ca cert (string)
621621
* `system_project_id` - (Computed) System project ID for the cluster (string)
622622

docs/resources/cluster_v2.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ The following attributes are exported:
230230

231231
* `id` - (Computed) The ID of the resource (string)
232232
* `cluster_registration_token` - (Computed/Sensitive) Cluster Registration Token generated for the cluster v2 (list maxitems:1)
233-
* `kube_config` - (Computed/Sensitive) Kube Config generated for the cluster v2 (string)
233+
* `kube_config` - (Computed/Sensitive) Kube Config generated for the cluster v2. Note: When the cluster has `local_auth_endpoint` enabled, the kube_config will not be available until the cluster is `connected` (string)
234234
* `cluster_v1_id` - (Computed) Cluster v1 id for cluster v2. (e.g to be used with `rancher2_sync`) (string)
235235
* `resource_version` - (Computed) Cluster v2 k8s resource version (string)
236236

rancher2/resource_rancher2_cluster.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,12 @@ func getClusterKubeconfig(c *Config, id string) (*managementClient.GenerateKubeC
596596
return nil, fmt.Errorf("Getting cluster Kubeconfig: %v", err)
597597
}
598598
} else if len(cluster.Actions[action]) > 0 {
599+
isRancher26, _ := c.IsRancherVersionGreaterThanOrEqual("2.6.0")
600+
if err != nil {
601+
return nil, err
602+
}
599603
kubeConfig := &managementClient.GenerateKubeConfigOutput{}
600-
if cluster.LocalClusterAuthEndpoint != nil && cluster.LocalClusterAuthEndpoint.Enabled {
604+
if cluster.LocalClusterAuthEndpoint != nil && cluster.LocalClusterAuthEndpoint.Enabled && isRancher26 {
601605
if connected, _, _ := c.isClusterConnected(cluster.ID); !connected {
602606
log.Printf("[WARN] Getting cluster Kubeconfig: kubeconfig is not yet available for cluster %s", cluster.Name)
603607
return kubeConfig, nil

0 commit comments

Comments
 (0)