@@ -9,8 +9,10 @@ import (
9
9
10
10
type (
11
11
IRuntimeAPI interface {
12
+ Get (ctx context.Context , name string ) (* model.Runtime , error )
12
13
List (ctx context.Context ) ([]model.Runtime , error )
13
14
Create (ctx context.Context , runtimeName string ) (* model.RuntimeCreationResponse , error )
15
+ Delete (ctx context.Context , runtimeName string ) (int , error )
14
16
}
15
17
16
18
argoRuntime struct {
@@ -24,18 +26,76 @@ type (
24
26
Errors []graphqlError
25
27
}
26
28
29
+ graphqlRuntimeResponse struct {
30
+ Data struct {
31
+ Runtime * model.Runtime
32
+ }
33
+ Errors []graphqlError
34
+ }
35
+
27
36
graphQlRuntimeCreationResponse struct {
28
37
Data struct {
29
38
Runtime model.RuntimeCreationResponse
30
39
}
31
40
Errors []graphqlError
32
41
}
42
+
43
+ graphQlDeleteRuntimeResponse struct {
44
+ Data struct {
45
+ DeleteRuntime int
46
+ }
47
+ Errors []graphqlError
48
+ }
33
49
)
34
50
35
51
func newArgoRuntimeAPI (codefresh * codefresh ) IRuntimeAPI {
36
52
return & argoRuntime {codefresh : codefresh }
37
53
}
38
54
55
+ func (r * argoRuntime ) Get (ctx context.Context , name string ) (* model.Runtime , error ) {
56
+ jsonData := map [string ]interface {}{
57
+ "query" : `
58
+ query GetRuntime(
59
+ $name: String!
60
+ ) {
61
+ runtime(name: $name) {
62
+ metadata {
63
+ name
64
+ namespace
65
+ }
66
+ self {
67
+ syncStatus
68
+ healthMessage
69
+ healthStatus
70
+ }
71
+ cluster
72
+ ingressHost
73
+ runtimeVersion
74
+ }
75
+ }
76
+ ` ,
77
+ "variables" : map [string ]interface {}{
78
+ "name" : name ,
79
+ },
80
+ }
81
+
82
+ res := graphqlRuntimeResponse {}
83
+ err := r .codefresh .graphqlAPI (ctx , jsonData , & res )
84
+ if err != nil {
85
+ return nil , fmt .Errorf ("failed making a graphql API call to runtime: %w" , err )
86
+ }
87
+
88
+ if len (res .Errors ) > 0 {
89
+ return nil , graphqlErrorResponse {errors : res .Errors }
90
+ }
91
+
92
+ if res .Data .Runtime == nil {
93
+ return nil , fmt .Errorf ("runtime '%s' does not exist" , name )
94
+ }
95
+
96
+ return res .Data .Runtime , nil
97
+ }
98
+
39
99
func (r * argoRuntime ) List (ctx context.Context ) ([]model.Runtime , error ) {
40
100
jsonData := map [string ]interface {}{
41
101
"query" : `{
@@ -107,3 +167,30 @@ func (r *argoRuntime) Create(ctx context.Context, runtimeName string) (*model.Ru
107
167
108
168
return & res .Data .Runtime , nil
109
169
}
170
+
171
+ func (r * argoRuntime ) Delete (ctx context.Context , runtimeName string ) (int , error ) {
172
+ jsonData := map [string ]interface {}{
173
+ "query" : `
174
+ mutation DeleteRuntime(
175
+ $name: String!
176
+ ) {
177
+ deleteRuntime(name: $name)
178
+ }
179
+ ` ,
180
+ "variables" : map [string ]interface {}{
181
+ "name" : runtimeName ,
182
+ },
183
+ }
184
+
185
+ res := graphQlDeleteRuntimeResponse {}
186
+ err := r .codefresh .graphqlAPI (ctx , jsonData , & res )
187
+ if err != nil {
188
+ return 0 , fmt .Errorf ("failed making a graphql API call to deleteRuntime: %w" , err )
189
+ }
190
+
191
+ if len (res .Errors ) > 0 {
192
+ return 0 , graphqlErrorResponse {errors : res .Errors }
193
+ }
194
+
195
+ return res .Data .DeleteRuntime , nil
196
+ }
0 commit comments