Skip to content

Commit

Permalink
PLT-678: Added support for admin kube config
Browse files Browse the repository at this point in the history
  • Loading branch information
SivaanandM committed Sep 12, 2023
1 parent b5f9e0b commit 59002ba
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion examples/data-sources/spectrocloud_cluster/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ resource "local_file" "kubeconfig" {
filename = "client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
}

resource "local_file" "adminkubeconfig" {
content = data.spectrocloud_cluster.cluster.admin_kube_config
filename = "admin-client-101.kubeconfig"
file_permission = "0644"
directory_permission = "0755"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ require (
)

//replace github.com/spectrocloud/hapi => ../hapi
//replace github.com/spectrocloud/palette-sdk-go => ../palette-sdk-go
replace github.com/spectrocloud/palette-sdk-go => ../palette-sdk-go
8 changes: 8 additions & 0 deletions spectrocloud/cluster_common_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ func readCommonFields(c *client.V1Client, d *schema.ResourceData, cluster *model
return diag.FromErr(err), true
}

adminKubeConfig, err := c.GetClusterAdminKubeConfig(d.Id(), ClusterContext)
if err != nil {
return diag.FromErr(err), true
}
if err := d.Set("admin_kube_config", adminKubeConfig); err != nil {
return diag.FromErr(err), true
}

if err := d.Set("tags", flattenTags(cluster.Metadata.Labels)); err != nil {
return diag.FromErr(err), true
}
Expand Down
10 changes: 10 additions & 0 deletions spectrocloud/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func dataSourceCluster() *schema.Resource {
Required: true,
ForceNew: true,
},
"admin_kube_config": {
Type: schema.TypeString,
Computed: true,
},
"kube_config": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -50,6 +54,12 @@ func dataSourceClusterRead(_ context.Context, d *schema.ResourceData, m interfac
if err := d.Set("kube_config", kubeConfig); err != nil {
return diag.FromErr(err)
}
adminKubeConfig, _ := c.GetClusterAdminKubeConfig(cluster.Metadata.UID, ClusterContext)
if adminKubeConfig != "" {
if err := d.Set("admin_kube_config", adminKubeConfig); err != nil {
return diag.FromErr(err)
}
}
d.SetId(cluster.Metadata.UID)
if err := d.Set("name", cluster.Metadata.Name); err != nil {
return diag.FromErr(err)
Expand Down
5 changes: 5 additions & 0 deletions spectrocloud/resource_cluster_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func resourceClusterAws() *schema.Resource {
Computed: true,
Description: "Kubeconfig for the cluster. This can be used to connect to the cluster using `kubectl`.",
},
"admin_kube_config": {
Type: schema.TypeString,
Computed: true,
Description: "Admin Kube-config for the cluster. This can be used to connect to the cluster using `kubectl`, With admin privilege.",
},
"cloud_config": {
Type: schema.TypeList,
ForceNew: true,
Expand Down

0 comments on commit 59002ba

Please sign in to comment.