Skip to content

Commit 176267b

Browse files
CR-12478 uninstall managed (#437)
* - added DeleteManaged to runtime api - added isc api * add managed to runtime query * add managed to get runtime query * small fix
1 parent 0a97362 commit 176267b

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

pkg/codefresh/ap_isc.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package codefresh
2+
3+
import (
4+
"context"
5+
"fmt"
6+
)
7+
8+
type (
9+
IAppProxyIscAPI interface {
10+
RemoveRuntimeFromIscRepo(ctx context.Context, runtimeName string) (int, error)
11+
}
12+
13+
appProxyIsc struct {
14+
codefresh *codefresh
15+
}
16+
17+
graphqlAppProxyRemoveRuntimeFromIscRepoResponse struct {
18+
Data struct {
19+
RemoveRuntimeFromIscRepo int
20+
}
21+
Errors []graphqlError
22+
}
23+
)
24+
25+
func newAppProxyIscAPI(c *codefresh) IAppProxyIscAPI {
26+
return &appProxyIsc{codefresh: c}
27+
}
28+
29+
func (c *appProxyIsc) RemoveRuntimeFromIscRepo(ctx context.Context, runtimeName string) (int, error) {
30+
jsonData := map[string]interface{}{
31+
"query": `
32+
mutation RemoveRuntimeFromIscRepo(
33+
$runtime: String!
34+
) {
35+
removeRuntimeFromIscRepo(runtime: $runtime)
36+
}
37+
`,
38+
"variables": map[string]interface{}{
39+
"runtime": runtimeName,
40+
},
41+
}
42+
43+
res := &graphqlAppProxyRemoveRuntimeFromIscRepoResponse{}
44+
err := c.codefresh.graphqlAPI(ctx, jsonData, res)
45+
if err != nil {
46+
return 0, fmt.Errorf("failed to remove runtime from isc repo: %w", err)
47+
}
48+
49+
if len(res.Errors) > 0 {
50+
return 0, graphqlErrorResponse{errors: res.Errors}
51+
}
52+
53+
return res.Data.RemoveRuntimeFromIscRepo, nil
54+
}

pkg/codefresh/argo_runtime.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type (
1414
List(ctx context.Context) ([]model.Runtime, error)
1515
ReportErrors(ctx context.Context, opts *model.ReportRuntimeErrorsArgs) (int, error)
1616
Delete(ctx context.Context, runtimeName string) (int, error)
17+
DeleteManaged(ctx context.Context, runtimeName string) (int, error)
1718
SetSharedConfigRepo(ctx context.Context, suggestedSharedConfigRepo string) (string, error)
1819
}
1920

@@ -56,6 +57,13 @@ type (
5657
Errors []graphqlError
5758
}
5859

60+
graphQlDeleteManagedRuntimeResponse struct {
61+
Data struct {
62+
DeleteManagedRuntime int
63+
}
64+
Errors []graphqlError
65+
}
66+
5967

6068
graphQlSuggestIscRepoResponse struct {
6169
Data struct {
@@ -121,6 +129,7 @@ func (r *argoRuntime) Get(ctx context.Context, name string) (*model.Runtime, err
121129
runtimeVersion
122130
installationStatus
123131
repo
132+
managed
124133
}
125134
}
126135
`,
@@ -168,6 +177,7 @@ func (r *argoRuntime) List(ctx context.Context) ([]model.Runtime, error) {
168177
ingressHost
169178
runtimeVersion
170179
installationStatus
180+
managed
171181
}
172182
}
173183
}
@@ -246,6 +256,33 @@ func (r *argoRuntime) Delete(ctx context.Context, runtimeName string) (int, erro
246256
return res.Data.DeleteRuntime, nil
247257
}
248258

259+
func (r *argoRuntime) DeleteManaged(ctx context.Context, runtimeName string) (int, error) {
260+
jsonData := map[string]interface{}{
261+
"query": `
262+
mutation DeleteManagedRuntime(
263+
$name: String!
264+
) {
265+
deleteManagedRuntime(name: $name)
266+
}
267+
`,
268+
"variables": map[string]interface{}{
269+
"name": runtimeName,
270+
},
271+
}
272+
273+
res := graphQlDeleteManagedRuntimeResponse{}
274+
err := r.codefresh.graphqlAPI(ctx, jsonData, &res)
275+
if err != nil {
276+
return 0, fmt.Errorf("failed making a graphql API call to deleteManagedRuntime: %w", err)
277+
}
278+
279+
if len(res.Errors) > 0 {
280+
return 0, graphqlErrorResponse{errors: res.Errors}
281+
}
282+
283+
return res.Data.DeleteManagedRuntime, nil
284+
}
285+
249286
func (r *argoRuntime) SetSharedConfigRepo(ctx context.Context, suggestedSharedConfigRepo string) (string, error) {
250287
jsonData := map[string]interface{}{
251288
"query": `

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type (
5151
GitIntegrations() IAppProxyGitIntegrationsAPI
5252
VersionInfo() IAppProxyVersionInfoAPI
5353
AppProxyGitSources() IAppProxyGitSourcesAPI
54+
AppProxyIsc() IAppProxyIscAPI
5455
}
5556
)
5657

@@ -182,6 +183,10 @@ func (c *codefresh) AppProxyGitSources() IAppProxyGitSourcesAPI {
182183
return newAppProxyGitSourcesAPI(c)
183184
}
184185

186+
func (c *codefresh) AppProxyIsc() IAppProxyIscAPI {
187+
return newAppProxyIscAPI(c)
188+
}
189+
185190
func (c *codefresh) requestAPI(opt *requestOptions) (*http.Response, error) {
186191
return c.requestAPIWithContext(context.Background(), opt)
187192
}

0 commit comments

Comments
 (0)