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

[CN-3737] increase wait time for application creation #9

Merged
merged 1 commit into from
Dec 3, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Test
Expand All @@ -30,10 +30,10 @@ jobs:
GPG_PRIVATE_KEY: ${{ secrets.TERRAFORM_GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.TERRAFORM_GPG_PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --rm-dist --skip-publish --snapshot
args: release --clean --snapshot
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Unshallow
run: git fetch --prune --unshallow
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Test
Expand All @@ -26,10 +26,10 @@ jobs:
GPG_PRIVATE_KEY: ${{ secrets.TERRAFORM_GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.TERRAFORM_GPG_PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: release --rm-dist
args: release --clean
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/plugin"

"terraform-provider-spinnaker/spinnaker"
"terraform-provider-spinnaker/spinnaker"
)

func main() {
Expand Down
49 changes: 28 additions & 21 deletions spinnaker/api/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func GetApplication(client *gate.GatewayClient, applicationName string, dest interface{}) error {
app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)})
app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)})
if resp != nil {
if resp != nil && resp.StatusCode == http.StatusNotFound {
return fmt.Errorf("Application '%s' not found\n", applicationName)
Expand All @@ -25,7 +25,7 @@ func GetApplication(client *gate.GatewayClient, applicationName string, dest int
}

if err != nil {
return FormatAPIErrorMessage ("ApplicationControllerApi.GetApplicationUsingGET", err)
return FormatAPIErrorMessage("ApplicationControllerApi.GetApplicationUsingGET", err)
}

if err := mapstructure.Decode(app, dest); err != nil {
Expand All @@ -37,16 +37,16 @@ func GetApplication(client *gate.GatewayClient, applicationName string, dest int

func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, email,
applicationDescription string, platformHealthOnly, platformHealthOnlyShowOverride bool,
cloud_providers []interface{}, permissions *schema.Set) error {
cloud_providers []interface{}, permissions *schema.Set) error {

jobType := "createApplication"
jobDescription := fmt.Sprintf("Create Application: %s", applicationName)
app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)})
app, resp, err := client.ApplicationControllerApi.GetApplicationUsingGET(client.Context, applicationName, &gateapi.ApplicationControllerApiGetApplicationUsingGETOpts{Expand: optional.NewBool(false)})
if resp != nil && resp.StatusCode == http.StatusOK && err == nil {
jobType = "updateApplication"
jobDescription = fmt.Sprintf("Update Application: %s", applicationName)
}

app = map[string]interface{}{
"instancePort": 80,
"name": applicationName,
Expand All @@ -56,28 +56,30 @@ func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, emai
"description": applicationDescription,
}

if len(cloud_providers) > 0 {
if len(cloud_providers) > 0 {
providers_csv := ""
for i := range cloud_providers {
if (i > 0) { providers_csv += "," }
if i > 0 {
providers_csv += ","
}
providers_csv += cloud_providers[i].(string)
}
app["cloudProviders"] = providers_csv
}

if permissions.Len() == 1 {
if permissions.Len() == 1 {
permissions_object := make(map[string]interface{})
list := permissions.List()
for k, value := range list[0].(map[string]interface{}) {
switch key := k; key {
case "read":
permissions_object["READ"] = value
case "execute":
permissions_object["EXECUTE"] = value
case "write":
permissions_object["WRITE"] = value
default:
return fmt.Errorf("invalid permissions type of %s", key)
case "read":
permissions_object["READ"] = value
case "execute":
permissions_object["EXECUTE"] = value
case "write":
permissions_object["WRITE"] = value
default:
return fmt.Errorf("invalid permissions type of %s", key)
}
}
app["permissions"] = permissions_object
Expand All @@ -91,25 +93,30 @@ func CreateOrUpdateApplication(client *gate.GatewayClient, applicationName, emai

ref, _, err := client.TaskControllerApi.TaskUsingPOST1(client.Context, createAppTask)
if err != nil {
return FormatAPIErrorMessage ("TaskControllerApi.TaskUsingPOST1", err)
return FormatAPIErrorMessage("TaskControllerApi.TaskUsingPOST1", err)
}

toks := strings.Split(ref["ref"].(string), "/")
id := toks[len(toks)-1]

task, resp, err := client.TaskControllerApi.GetTaskUsingGET1(client.Context, id)
attempts := 0
for (task == nil || !taskCompleted(task)) && attempts < 5 {
maxAttempts := 40
for (task == nil || !taskCompleted(task)) && attempts < maxAttempts {
toks := strings.Split(ref["ref"].(string), "/")
id := toks[len(toks)-1]

task, resp, err = client.TaskControllerApi.GetTaskUsingGET1(client.Context, id)
attempts += 1
time.Sleep(time.Duration(attempts*attempts) * time.Second)
sleepDuration := time.Duration(attempts*attempts) * time.Second
if sleepDuration > 30*time.Second {
sleepDuration = 30 * time.Second
}
time.Sleep(sleepDuration)
}

if err != nil {
return FormatAPIErrorMessage ("TaskControllerApi.GetTaskUsingGET1", err)
return FormatAPIErrorMessage("TaskControllerApi.GetTaskUsingGET1", err)
}
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return fmt.Errorf("Encountered an error saving application, status code: %d\n", resp.StatusCode)
Expand Down Expand Up @@ -138,7 +145,7 @@ func DeleteAppliation(client *gate.GatewayClient, applicationName string) error
_, resp, err := client.TaskControllerApi.TaskUsingPOST1(client.Context, deleteAppTask)

if err != nil {
return FormatAPIErrorMessage ("TaskControllerApi.TaskUsingPOST1", err)
return FormatAPIErrorMessage("TaskControllerApi.TaskUsingPOST1", err)
}

if resp.StatusCode != http.StatusOK {
Expand Down
8 changes: 4 additions & 4 deletions spinnaker/api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func CreatePipeline(client *gate.GatewayClient, pipeline interface{}) error {
resp, err := client.PipelineControllerApi.SavePipelineUsingPOST(client.Context, pipeline, nil)

if err != nil {
return FormatAPIErrorMessage ("PipelineControllerApi.SavePipelineUsingPOST", err)
return FormatAPIErrorMessage("PipelineControllerApi.SavePipelineUsingPOST", err)
}

if resp.StatusCode != http.StatusOK {
Expand All @@ -33,7 +33,7 @@ func GetPipeline(client *gate.GatewayClient, applicationName, pipelineName strin
}
return jsonMap, fmt.Errorf("Encountered an error getting pipeline %s, %s\n",
pipelineName,
FormatAPIErrorMessage ("PipelineControllerApi.GetPipelineConfigUsingGET", err))
FormatAPIErrorMessage("PipelineControllerApi.GetPipelineConfigUsingGET", err))
}

if resp.StatusCode != http.StatusOK {
Expand All @@ -58,7 +58,7 @@ func UpdatePipeline(client *gate.GatewayClient, pipelineID string, pipeline inte
_, resp, err := client.PipelineControllerApi.UpdatePipelineUsingPUT(client.Context, pipelineID, pipeline)

if err != nil {
return FormatAPIErrorMessage ("PipelineControllerApi.UpdatePipelineUsingPUT", err)
return FormatAPIErrorMessage("PipelineControllerApi.UpdatePipelineUsingPUT", err)
}

if resp.StatusCode != http.StatusOK {
Expand All @@ -72,7 +72,7 @@ func DeletePipeline(client *gate.GatewayClient, applicationName, pipelineName st
resp, err := client.PipelineControllerApi.DeletePipelineUsingDELETE(client.Context, applicationName, pipelineName)

if err != nil {
return FormatAPIErrorMessage ("PipelineControllerApi.DeletePipelineUsingDELETE", err)
return FormatAPIErrorMessage("PipelineControllerApi.DeletePipelineUsingDELETE", err)
}

if resp.StatusCode != http.StatusOK {
Expand Down
Loading