Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add kubernete_workflow_tool property to the kubernetes schema #592

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/data-sources/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Read-Only:
Read-Only:

- `kubectl_version` (String)
- `kubernetes_workflow_tool` (String)
- `namespace` (String)


Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/stacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ Read-Only:
Read-Only:

- `kubectl_version` (String)
- `kubernetes_workflow_tool` (String)
- `namespace` (String)


Expand Down
1 change: 1 addition & 0 deletions docs/resources/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Read-Only:
Optional:

- `kubectl_version` (String) Kubectl version.
- `kubernetes_workflow_tool` (String) Defines the tool that will be used to execute the workflow. This can be one of `KUBERNETES` or `CUSTOM`. Defaults to `KUBERNETES`.
- `namespace` (String) Namespace of the Kubernetes cluster to run commands on. Leave empty for multi-namespace Stacks.


Expand Down
5 changes: 5 additions & 0 deletions spacelift/data_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ func dataStack() *schema.Resource {
Description: "Kubectl version.",
Computed: true,
},
"kubernetes_workflow_tool": {
Type: schema.TypeString,
Description: "Defines the tool that will be used to execute the workflow. This can be one of `KUBERNETES` or `CUSTOM`. Defaults to `KUBERNETES`.",
Computed: true,
},
},
},
},
Expand Down
26 changes: 26 additions & 0 deletions spacelift/data_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ func TestStackData(t *testing.T) {
Check: Resource(
"data.spacelift_stack.test",
Attribute("kubernetes.0.kubectl_version", IsNotEmpty()),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")),
),
}})
})
Expand All @@ -214,6 +215,31 @@ func TestStackData(t *testing.T) {
Check: Resource(
"data.spacelift_stack.test",
Attribute("kubernetes.0.kubectl_version", Equals("1.2.3")),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")),
),
}})
})

t.Run("with Kubernetes stack with a kubernetes workflow tool", func(t *testing.T) {
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)

testSteps(t, []resource.TestStep{{
Config: fmt.Sprintf(`
resource "spacelift_stack" "test" {
branch = "master"
name = "Test stack %s"
repository = "demo"
kubernetes {
kubernetes_workflow_tool = "CUSTOM"
}
}
data "spacelift_stack" "test" {
stack_id = spacelift_stack.test.id
}
`, randomID),
Check: Resource(
"data.spacelift_stack.test",
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("CUSTOM")),
),
}})
})
Expand Down
3 changes: 3 additions & 0 deletions spacelift/internal/structs/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ type Stack struct {
Kubernetes struct {
Namespace string `graphql:"namespace"`
KubectlVersion *string `graphql:"kubectlVersion"`
KubernetesWorkflowTool *string `graphql:"kubernetesWorkflowTool"`
} `graphql:"... on StackConfigVendorKubernetes"`
Pulumi struct {
LoginURL string `graphql:"loginURL"`
Expand Down Expand Up @@ -136,6 +137,7 @@ func (s *Stack) IaCSettings() (string, map[string]interface{}) {
return "kubernetes", map[string]interface{}{
"namespace": s.VendorConfig.Kubernetes.Namespace,
"kubectl_version": s.VendorConfig.Kubernetes.KubectlVersion,
"kubernetes_workflow_tool": s.VendorConfig.Kubernetes.KubernetesWorkflowTool,
}
case StackConfigVendorPulumi:
return "pulumi", map[string]interface{}{
Expand Down Expand Up @@ -281,6 +283,7 @@ func PopulateStack(d *schema.ResourceData, stack *Stack) error {
m := map[string]interface{}{
"namespace": stack.VendorConfig.Kubernetes.Namespace,
"kubectl_version": stack.VendorConfig.Kubernetes.KubectlVersion,
"kubernetes_workflow_tool": stack.VendorConfig.Kubernetes.KubernetesWorkflowTool,
}

d.Set("kubernetes", []interface{}{m})
Expand Down
1 change: 1 addition & 0 deletions spacelift/internal/structs/stack_input.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type CloudFormationInput struct {
type KubernetesInput struct {
Namespace graphql.String `json:"namespace"`
KubectlVersion *graphql.String `json:"kubectlVersion"`
KubernetesWorkflowTool *graphql.String `json:"kubernetesWorkflowTool"`
}

// PulumiInput represents Pulumi-specific configuration.
Expand Down
10 changes: 10 additions & 0 deletions spacelift/resource_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,13 @@ func resourceStack() *schema.Resource {
Computed: true,
ValidateDiagFunc: validations.DisallowEmptyString,
},
"kubernetes_workflow_tool": {
Type: schema.TypeString,
Description: "Defines the tool that will be used to execute the workflow. This can be one of `KUBERNETES` or `CUSTOM`. Defaults to `KUBERNETES`.",
Optional: true,
Computed: true,
ValidateDiagFunc: validations.DisallowEmptyString,
},
},
},
},
Expand Down Expand Up @@ -961,6 +968,9 @@ func getVendorConfig(d *schema.ResourceData) *structs.VendorConfigInput {
if s := toOptionalString(kubernetesSettings["kubectl_version"]); *s != "" {
vendorConfig.Kubernetes.KubectlVersion = s
}
if s := toOptionalString(kubernetesSettings["kubernetes_workflow_tool"]); *s != "" {
vendorConfig.Kubernetes.KubernetesWorkflowTool = s
}
}
return vendorConfig
}
Expand Down
27 changes: 26 additions & 1 deletion spacelift/resource_stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func TestStackResource(t *testing.T) {
})
})

t.Run("with GitHub and Kubernetes configuration", func(t *testing.T) {
t.Run("with GitHub and Kubernetes (default tool) configuration", func(t *testing.T) {
testSteps(t, []resource.TestStep{
{
Config: getConfig(`kubernetes {}`),
Expand All @@ -493,6 +493,7 @@ func TestStackResource(t *testing.T) {
Attribute("id", StartsWith("provider-test-stack")),
Attribute("kubernetes.0.namespace", Equals("")),
Attribute("kubernetes.0.kubectl_version", IsNotEmpty()),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")),
Attribute("ansible.#", Equals("0")),
Attribute("pulumi.#", Equals("0")),
Attribute("cloudformation.#", Equals("0")),
Expand All @@ -508,6 +509,7 @@ func TestStackResource(t *testing.T) {
Attribute("id", StartsWith("provider-test-stack")),
Attribute("kubernetes.0.namespace", Equals("myapp-prod")),
Attribute("kubernetes.0.kubectl_version", IsNotEmpty()),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")),
Attribute("ansible.#", Equals("0")),
Attribute("pulumi.#", Equals("0")),
Attribute("cloudformation.#", Equals("0")),
Expand All @@ -522,6 +524,27 @@ func TestStackResource(t *testing.T) {
Attribute("id", StartsWith("provider-test-stack")),
Attribute("kubernetes.0.namespace", Equals("")),
Attribute("kubernetes.0.kubectl_version", Equals("1.2.3")),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")),
Attribute("ansible.#", Equals("0")),
Attribute("pulumi.#", Equals("0")),
Attribute("cloudformation.#", Equals("0")),
),
},
})
})

t.Run("with GitHub and Kubernetes (CUSTOM) configuration", func(t *testing.T) {
testSteps(t, []resource.TestStep{
{
Config: getConfig(`kubernetes {
namespace = "myapp-prod"
kubernetes_workflow_tool = "CUSTOM"
}`),
Check: Resource(
resourceName,
Attribute("id", StartsWith("provider-test-stack")),
Attribute("kubernetes.0.namespace", Equals("myapp-prod")),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("CUSTOM")),
Attribute("ansible.#", Equals("0")),
Attribute("pulumi.#", Equals("0")),
Attribute("cloudformation.#", Equals("0")),
Expand Down Expand Up @@ -1285,6 +1308,8 @@ func TestStackResourceSpace(t *testing.T) {
Attribute("repository", Equals("demo")),
Attribute("runner_image", Equals("custom_image:runner")),
Attribute("kubernetes.0.namespace", Equals("myapp-prod")),
Attribute("kubernetes.0.kubectl_version", IsNotEmpty()),
Attribute("kubernetes.0.kubernetes_workflow_tool", Equals("KUBERNETES")),
Attribute("ansible.#", Equals("0")),
Attribute("pulumi.#", Equals("0")),
Attribute("cloudformation.#", Equals("0")),
Expand Down
Loading