Skip to content

Commit

Permalink
feat: Add support to specify k8s namespace on kubectl script step
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn committed Feb 16, 2024
1 parent 5c486ca commit f02a38f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion octopusdeploy/schema_action_run_kubectl_script.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package octopusdeploy

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/deployments"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -13,6 +14,11 @@ func getRunKubectlScriptSchema() *schema.Schema {
addWorkerPoolSchema(element)
addWorkerPoolVariableSchema(element)

element.Schema["namespace"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
}

element.Schema["script_body"] = &schema.Schema{
Optional: true,
Type: schema.TypeString,
Expand All @@ -35,9 +41,18 @@ func getRunKubectlScriptSchema() *schema.Schema {
func expandRunKubectlScriptAction(flattenedAction map[string]interface{}) *deployments.DeploymentAction {
action := expandRunScriptAction(flattenedAction)
action.ActionType = "Octopus.KubernetesRunScript"

action.Properties["Octopus.Action.KubernetesContainers.Namespace"] = core.NewPropertyValue(flattenedAction["namespace"].(string), false)

return action
}

func flattenKubernetesRunScriptAction(action *deployments.DeploymentAction) map[string]interface{} {
return flattenRunScriptAction(action)
flattenedAction := flattenRunScriptAction(action)

if v, ok := action.Properties["Octopus.Action.KubernetesContainers.Namespace"]; ok {
flattenedAction["namespace"] = v.Value
}

return flattenedAction
}
6 changes: 6 additions & 0 deletions octopusdeploy/schema_action_run_kubectl_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func testAccRunKubectlScriptAction() string {
script_file_name = "Test.ps1"
script_parameters = "-Test 1"
namespace = "test-namespace"
}
`)
}
Expand All @@ -61,6 +63,10 @@ func testAccCheckRunKubectlScriptAction() resource.TestCheckFunc {
return fmt.Errorf("Action type is incorrect: %s", action.ActionType)
}

if action.Properties["Octopus.Action.KubernetesContainers.Namespace"].Value != "test-namespace" {
return fmt.Errorf("Kubernetes namespace is incorrect: %s", action.Properties["Octopus.Action.KubernetesContainers.Namespace"].Value)
}

if action.Properties["Octopus.Action.Script.ScriptFileName"].Value != "Test.ps1" {
return fmt.Errorf("ScriptFileName is incorrect: %s", action.Properties["Octopus.Action.Script.ScriptFileName"].Value)
}
Expand Down

0 comments on commit f02a38f

Please sign in to comment.