@@ -12,48 +12,13 @@ import (
1212
1313func UpsertIntegration (ctx context.Context , client * api.ClientWithResponses , locationId * types.UUID , locationName string ) error {
1414 log .Info ("Upserting location %s" , locationName )
15- location , err := client .UpsertKubernetesIntegrationWithResponse (ctx , api.UpsertKubernetesIntegrationJSONRequestBody {
15+ res , err := client .UpsertKubernetesIntegrationWithResponse (ctx , api.UpsertKubernetesIntegrationJSONRequestBody {
1616 Name : locationName ,
1717 LocationId : locationId ,
1818 })
1919 if err != nil {
2020 return err
2121 }
22- if location .JSON200 != nil {
23- return location .JSON200 , func () {
24- fmt .Println ("Location:" , * location .JSON200 .Name )
25- fmt .Println ("Type:" , * location .JSON200 .Type )
26- fmt .Println ("Id:" , * location .JSON200 .Id )
27- }, nil
28- } else if location .JSON400 != nil {
29- return nil , nil , fmt .Errorf ("unable to create location: %s" , location .JSON400 .Message )
30- } else if location .JSON500 != nil {
31- return nil , nil , fmt .Errorf ("unable to create location: %s" , location .JSON500 .Message )
32- } else {
33- return nil , nil , fmt .Errorf ("unable to create location: Unknown error" )
34- }
35-
36- integrations , err := client .GetV1IntegrationsKubernetesWithResponse (ctx )
37- if err != nil {
38- return err
39- }
40-
41- for _ , integration := range * integrations .JSON200 {
42- if integration .LocationId == locationId {
43- log .Info ("Integration already exists, skipping" )
44- return nil
45- }
46- }
47-
48- time .Sleep (2 * time .Second )
49- log .Info ("Integration not found, creating" )
50- res , err := client .PostV1IntegrationsKubernetesWithResponse (ctx , api.PostV1IntegrationsKubernetesJSONRequestBody {
51- LocationId : locationId ,
52- Name : locationName ,
53- })
54- if err != nil {
55- return err
56- }
5722 if res .JSON200 != nil {
5823 log .Info ("Integration created successfully" )
5924 return nil
@@ -67,4 +32,5 @@ func UpsertIntegration(ctx context.Context, client *api.ClientWithResponses, loc
6732 } else {
6833 return fmt .Errorf ("unable to create integration: Unknown error" )
6934 }
35+ return nil
7036}
0 commit comments