Skip to content

Commit

Permalink
Renew kubeconfig when it expires. (#229)
Browse files Browse the repository at this point in the history
* fix expired kubeconfig when tf apply/plan

* update k8s resource docs
  • Loading branch information
nvthongswansea committed May 9, 2023
1 parent 3e17ddc commit 5c4d652
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gridscale/resource_gridscale_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,19 @@ func resourceGridscaleK8sRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("%s error setting name: %v", errorPrefix, err)
}
if len(creds) > 0 {
// if expiration_time of kubeconfig is reached, renew it and get new kubeconfig
if creds[0].ExpirationTime.Before(time.Now()) {
err = client.RenewK8sCredentials(context.Background(), d.Id())
if err != nil {
return fmt.Errorf("%s error renewing k8s kubeconfig: %v", errorPrefix, err)
}
paas, err = client.GetPaaSService(context.Background(), d.Id())
if err != nil {
return fmt.Errorf("%s error: %v", errorPrefix, err)
}
props = paas.Properties
creds = props.Credentials
}
if err = d.Set("kubeconfig", creds[0].KubeConfig); err != nil {
return fmt.Errorf("%s error setting kubeconfig: %v", errorPrefix, err)
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/k8s.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ This resource exports the following attributes:
* `service_template_uuid` - PaaS service template that k8s service uses. The `service_template_uuid` may not relate to `release`, if `service_template_uuid`/`release` is updated outside of terraform (e.g. the k8s service is upgraded by gridscale staffs).
* `service_template_category` - The template service's category used to create the service.
* `labels` - See Argument Reference above.
* `kubeconfig` - The kubeconfig file content of the k8s cluster.
* `network_uuid` - *DEPRECATED* Network UUID containing security zone, which is linked to the k8s cluster.
* `k8s_private_network_uuid` - Private network UUID which k8s nodes are attached to. It can be used to attach other PaaS/VMs.
* `node_pool` - See Argument Reference above.
Expand Down

0 comments on commit 5c4d652

Please sign in to comment.