Skip to content

Commit

Permalink
feat: add kubernete_workflow_tool property to the kubernetes schema (
Browse files Browse the repository at this point in the history
…#592)

* feat: add kubernetes_custom_workflow property for kubernetes schema

* test: kubernetes_custom_workflow

* docs: add kubernetes_workflow_tool info

* fix: kubeclt_version invalid field name

* test: fix resource test for kubernetes workflows

* chore: check GA

---------

Co-authored-by: Piotr Truszkowski <[email protected]>
  • Loading branch information
michalrom089 and truszkowski authored Jan 13, 2025
1 parent ca71331 commit fbbbfbe
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 1 deletion.
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

0 comments on commit fbbbfbe

Please sign in to comment.