Skip to content

Add cloudstack_kubernetes_cluster_config data source - #312

Open
sudo87 wants to merge 2 commits into
mainfrom
k8ClusterConfig
Open

Add cloudstack_kubernetes_cluster_config data source#312
sudo87 wants to merge 2 commits into
mainfrom
k8ClusterConfig

Conversation

@sudo87

@sudo87 sudo87 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds cloudstack_kubernetes_cluster_config, a data source that reads a CKS cluster's kubeconfig
    and exposes endpoint, cluster_ca_certificate, client_certificate, client_key, and raw
    config_data, so the kubernetes/helm providers can be wired to a CKS cluster directly.
  • Errors instead of guessing if a kubeconfig's current-context names a cluster/user missing from a
    multi-entry list, to avoid silently serving mismatched credentials.
  • config_data and client_key are marked Sensitive.

Test plan

  • TestParseKubernetesClusterConfig — 12 unit cases covering context resolution, missing
    sections, and malformed input
  • make build, make test, make vet, gofmt -l clean
  • TestProvider/TestProvider_impl confirm registration and schema validity

CloudStack's CKS clusters expose their kubeconfig only through the
getKubernetesClusterConfig API, with no Terraform-native way to feed it
into the kubernetes/helm providers. This adds a data source that fetches
it and parses out endpoint, cluster_ca_certificate, client_certificate,
and client_key as separate attributes named to match those providers'
own arguments, alongside the raw config_data for anything else.

Context resolution deliberately refuses to guess: if a kubeconfig's
current-context names a cluster or user absent from a list of more than
one entry, parsing errors instead of silently falling back, since a
wrong guess there would silently serve one cluster's endpoint paired
with a different cluster's credentials.

Closes #276.
Copilot AI lite review requested due to automatic review settings August 12, 2026 09:30
@sudo87 sudo87 linked an issue Aug 12, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Adds a new cloudstack_kubernetes_cluster_config data source to fetch a CKS cluster kubeconfig and expose connection fields suitable for wiring up the kubernetes and helm providers.

Changes:

  • Introduces cloudstack_kubernetes_cluster_config data source implementation, including kubeconfig parsing and base64 decoding of cert/key material.
  • Registers the new data source in the provider and adds YAML parsing dependency.
  • Adds documentation and unit tests for kubeconfig parsing and context/entry resolution behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
website/docs/d/kubernetes_cluster_config.html.markdown Documents the new data source, examples for provider wiring, and attribute semantics.
go.mod Adds YAML v3 dependency used for kubeconfig parsing.
cloudstack/provider.go Registers cloudstack_kubernetes_cluster_config in DataSourcesMap.
cloudstack/data_source_cloudstack_kubernetes_cluster_config.go Implements the new data source read + kubeconfig parsing/resolution helpers.
cloudstack/data_source_cloudstack_kubernetes_cluster_config_test.go Adds unit tests covering parsing, resolution, and error cases.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +149 to +162
if config.Configdata == "" {
return fmt.Errorf("Kubernetes Cluster %s returned an empty config; the cluster ID may not "+
"exist, the cluster may still be starting, or the Kubernetes service plugin may be disabled", clusterID)
}

credentials, err := parseKubernetesClusterConfig(config.Configdata)
if err != nil {
return fmt.Errorf("Failed to parse the config of Kubernetes Cluster %s: %s", clusterID, err)
}

if *credentials == (kubernetesClusterCredentials{}) {
return fmt.Errorf("The config of Kubernetes Cluster %s does not contain a cluster endpoint, "+
"CA certificate, client certificate or client key; use config_data directly instead", clusterID)
}
Comment thread cloudstack/data_source_cloudstack_kubernetes_cluster_config.go Outdated
Comment thread cloudstack/data_source_cloudstack_kubernetes_cluster_config.go
Copilot AI review requested due to automatic review settings August 12, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@sudo87
sudo87 requested a lite review from Copilot August 12, 2026 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create data get kubernetes cluster kubeconfig using terraform

4 participants