Skip to content

Commit

Permalink
Enable Kubernetes Object Status Check by default on all Kubernetes st…
Browse files Browse the repository at this point in the history
…eps (#654)
  • Loading branch information
APErebus authored Jun 25, 2024
1 parent 9added4 commit c5117c5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/library_variable_sets.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Read-Only:
- `name` (String) The name of this resource.
- `space_id` (String) The space ID associated with this resource.
- `template` (List of Object) (see [below for nested schema](#nestedatt--library_variable_sets--template))
- `template_ids` (Map of String)
- `variable_set_id` (String)

<a id="nestedatt--library_variable_sets--template"></a>
Expand Down
1 change: 1 addition & 0 deletions docs/resources/deployment_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ Optional:
- `id` (String) The unique ID for this resource.
- `is_disabled` (Boolean) Indicates the disabled status of this deployment action.
- `is_required` (Boolean) Indicates the required status of this deployment action.
- `kubernetes_object_status_check_enabled` (Boolean) Indicates the status of the Kubernetes Object Status feature
- `notes` (String) The notes associated with this deployment action.
- `package` (Block List) The package assocated with this action. (see [below for nested schema](#nestedblock--step--deploy_kubernetes_secret_action--package))
- `properties` (Map of String) The properties associated with this deployment action.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/library_variable_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This resource manages library variable sets in Octopus Deploy.

### Read-Only

- `template_ids` (Map of String)
- `variable_set_id` (String)

<a id="nestedblock--template"></a>
Expand Down
1 change: 1 addition & 0 deletions docs/resources/runbook_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ Optional:
- `id` (String) The unique ID for this resource.
- `is_disabled` (Boolean) Indicates the disabled status of this deployment action.
- `is_required` (Boolean) Indicates the required status of this deployment action.
- `kubernetes_object_status_check_enabled` (Boolean) Indicates the status of the Kubernetes Object Status feature
- `notes` (String) The notes associated with this deployment action.
- `package` (Block List) The package assocated with this action. (see [below for nested schema](#nestedblock--step--deploy_kubernetes_secret_action--package))
- `properties` (Map of String) The properties associated with this deployment action.
Expand Down
16 changes: 16 additions & 0 deletions octopusdeploy/schema_action_deploy_kubernetes_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func expandDeployKubernetesSecretAction(flattenedAction map[string]interface{})
action.Properties["Octopus.Action.KubernetesContainers.SecretValues"] = core.NewPropertyValue(string(j), false)
}

if v, ok := flattenedAction["kubernetes_object_status_check_enabled"]; ok {
action.Properties["Octopus.Action.Kubernetes.ResourceStatusCheck"] = core.NewPropertyValue(formatBoolForActionProperty(v.(bool)), false)
}

return action
}

Expand All @@ -37,6 +41,11 @@ func flattenDeployKubernetesSecretAction(action *deployments.DeploymentAction) m
flattenedAction["secret_name"] = v.Value
}

if v, ok := action.Properties["Octopus.Action.Kubernetes.ResourceStatusCheck"]; ok {
statusCheckEnabled, _ := strconv.ParseBool(v.Value)
flattenedAction["kubernetes_object_status_check_enabled"] = statusCheckEnabled
}

if len(action.WorkerPool) > 0 {
flattenedAction["worker_pool_id"] = action.WorkerPool
}
Expand Down Expand Up @@ -72,5 +81,12 @@ func getDeployKubernetesSecretActionSchema() *schema.Schema {
Type: schema.TypeMap,
}

element.Schema["kubernetes_object_status_check_enabled"] = &schema.Schema{
Optional: true,
Default: true,
Type: schema.TypeBool,
Description: "Indicates the status of the Kubernetes Object Status feature",
}

return actionSchema
}
15 changes: 10 additions & 5 deletions octopusdeploy/schema_action_deploy_kubernetes_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccOctopusDeployDeployKuberentesSecretAction(t *testing.T) {
func TestAccOctopusDeployDeployKubernetesSecretAction(t *testing.T) {
resource.Test(t, resource.TestCase{
CheckDestroy: resource.ComposeTestCheckFunc(
testAccProjectCheckDestroy,
Expand All @@ -20,21 +20,22 @@ func TestAccOctopusDeployDeployKuberentesSecretAction(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDeployKuberentesSecretAction(),
Config: testAccDeployKubernetesSecretAction(),
Check: resource.ComposeTestCheckFunc(
testAccCheckDeployKuberentesSecretAction(),
testAccCheckDeployKubernetesSecretAction(),
),
},
},
})
}

func testAccDeployKuberentesSecretAction() string {
func testAccDeployKubernetesSecretAction() string {
return testAccBuildTestAction(`
deploy_kubernetes_secret_action {
name = "Run Script"
run_on_server = true
secret_name = "secret name"
kubernetes_object_status_check_enabled = false
secret_values = {
"key-123" = "value-123",
Expand All @@ -44,7 +45,7 @@ func testAccDeployKuberentesSecretAction() string {
`)
}

func testAccCheckDeployKuberentesSecretAction() resource.TestCheckFunc {
func testAccCheckDeployKubernetesSecretAction() resource.TestCheckFunc {
return func(s *terraform.State) error {
client := testAccProvider.Meta().(*client.Client)

Expand All @@ -67,6 +68,10 @@ func testAccCheckDeployKuberentesSecretAction() resource.TestCheckFunc {
return fmt.Errorf("SecretValue is incorrect: %s", action.Properties["Octopus.Action.KubernetesContainers.SecretValues"].Value)
}

if action.Properties["Octopus.Action.Kubernetes.ResourceStatusCheck"].Value != "False" {
return fmt.Errorf("Kubernetes Object Status Check is incorrect: %s", action.Properties["Octopus.Action.Kubernetes.ResourceStatusCheck"].Value)
}

return nil
}
}
19 changes: 19 additions & 0 deletions octopusdeploy/schema_deployment_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,5 +517,24 @@ func expandAction(flattenedAction map[string]interface{}) *deployments.Deploymen
}
}

// Polyfill the Kubernetes Object status check to default to true if not specified for Kubernetes steps
switch actionType {
case "Octopus.KubernetesDeployContainers":
fallthrough
case "Octopus.KubernetesDeployRawYaml":
fallthrough
case "Octopus.KubernetesDeployService":
fallthrough
case "Octopus.KubernetesDeployIngress":
fallthrough
case "Octopus.KubernetesDeployConfigMap":
fallthrough
case "Octopus.Kustomize":
if _, exists := action.Properties["Octopus.Action.Kubernetes.ResourceStatusCheck"]; !exists {
action.Properties["Octopus.Action.Kubernetes.ResourceStatusCheck"] = core.NewPropertyValue(formatBoolForActionProperty(true), false)
}
break
}

return action
}
7 changes: 7 additions & 0 deletions octopusdeploy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,10 @@ func stringHashCode(s string) int {
}
return 0
}

func formatBoolForActionProperty(b bool) string {
if b {
return "True"
}
return "False"
}

0 comments on commit c5117c5

Please sign in to comment.