Skip to content

Commit 4462ab5

Browse files
authored
Cr 9843 add CreateArgoRollouts mutation (#419)
* renamed RemoveCluster to Delete * added cluster_v2 with `List` * updated version to 0.42.0
1 parent ae43f72 commit 4462ab5

File tree

5 files changed

+148
-10
lines changed

5 files changed

+148
-10
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.41.2
1+
0.42.0

pkg/codefresh/ap_clusters.go

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ package codefresh
33
import (
44
"context"
55
"fmt"
6-
7-
// model "github.com/codefresh-io/go-sdk/pkg/codefresh/model/app-proxy"
86
)
97

108
type (
119
IAppProxyClustersAPI interface {
12-
RemoveCluster(ctx context.Context, server string, runtime string) error
10+
CreateArgoRollouts(ctx context.Context, server string, namespace string) error
11+
Delete(ctx context.Context, server string, runtime string) error
1312
}
13+
1414
appProxyClusters struct {
1515
codefresh *codefresh
1616
}
1717

18-
graphqlClusterRemoveResponse struct {
18+
graphqlClusterResponse struct {
1919
Errors []graphqlError
2020
}
2121
)
@@ -24,7 +24,36 @@ func newAppProxyClustersAPI(c *codefresh) IAppProxyClustersAPI {
2424
return &appProxyClusters{codefresh: c}
2525
}
2626

27-
func (c *appProxyClusters) RemoveCluster(ctx context.Context, server string, runtime string) error {
27+
func (c *appProxyClusters)CreateArgoRollouts(ctx context.Context, server string, namespace string) error {
28+
jsonData := map[string]interface{}{
29+
"query": `
30+
mutation createArgoRollouts($args: CreateArgoRolloutsInput!) {
31+
createArgoRollouts(args: $args)
32+
}
33+
`,
34+
"variables": map[string]interface{}{
35+
"args": map[string]interface{}{
36+
"destServer": server,
37+
"destNamespace": namespace,
38+
},
39+
},
40+
}
41+
42+
res := &graphqlClusterResponse{}
43+
err := c.codefresh.graphqlAPI(ctx, jsonData, res)
44+
45+
if err != nil {
46+
return fmt.Errorf("failed making a graphql API call to add rollouts: %w", err)
47+
}
48+
49+
if len(res.Errors) > 0 {
50+
return graphqlErrorResponse{errors: res.Errors}
51+
}
52+
53+
return nil
54+
}
55+
56+
func (c *appProxyClusters)Delete(ctx context.Context, server string, runtime string) error {
2857
jsonData := map[string]interface{}{
2958
"query": `
3059
mutation RemoveCluster($server: String!, $runtime: String!) {
@@ -37,7 +66,7 @@ func (c *appProxyClusters) RemoveCluster(ctx context.Context, server string, run
3766
},
3867
}
3968

40-
res := &graphqlClusterRemoveResponse{}
69+
res := &graphqlClusterResponse{}
4170
err := c.codefresh.graphqlAPI(ctx, jsonData, res)
4271

4372
if err != nil {

pkg/codefresh/argo_runtime.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ func (r *argoRuntime) Create(ctx context.Context, opts *model.RuntimeInstallatio
9191
func (r *argoRuntime) Get(ctx context.Context, name string) (*model.Runtime, error) {
9292
jsonData := map[string]interface{}{
9393
"query": `
94-
query GetRuntime(
95-
$name: String!
96-
) {
94+
query GetRuntime($name: String!) {
9795
runtime(name: $name) {
9896
metadata {
9997
name

pkg/codefresh/cluster_v2.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package codefresh
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
8+
)
9+
10+
type (
11+
IClusterV2API interface {
12+
List(ctx context.Context, runtime string) ([]model.Cluster, error)
13+
}
14+
15+
clusterV2 struct {
16+
codefresh *codefresh
17+
}
18+
19+
graphqlClusterListResponse struct {
20+
Data struct {
21+
Clusters model.ClusterSlice
22+
}
23+
Errors []graphqlError
24+
}
25+
)
26+
27+
func newClusterV2API(codefresh *codefresh) IClusterV2API {
28+
return &clusterV2{codefresh: codefresh}
29+
}
30+
31+
func (c *clusterV2)List(ctx context.Context, runtime string) ([]model.Cluster, error) {
32+
after := ""
33+
clusters := make([]model.Cluster, 0)
34+
for {
35+
clusterSlice, err := c.getClusterSlice(ctx, runtime, after)
36+
if err != nil {
37+
return nil, err
38+
}
39+
40+
for i := range clusterSlice.Edges {
41+
clusters = append(clusters, *clusterSlice.Edges[i].Node)
42+
}
43+
44+
if clusterSlice.PageInfo.HasNextPage {
45+
after = *clusterSlice.PageInfo.EndCursor
46+
} else {
47+
break
48+
}
49+
}
50+
51+
return clusters, nil
52+
}
53+
54+
55+
func (c *clusterV2)getClusterSlice(ctx context.Context, runtime string, after string) (*model.ClusterSlice, error) {
56+
jsonData := map[string]interface{}{
57+
"query": `
58+
query clusters($runtime: String, $pagination: SlicePaginationArgs) {
59+
clusters(runtime: $runtime, pagination: $pagination) {
60+
edges {
61+
node {
62+
metadata {
63+
name
64+
runtime
65+
}
66+
server
67+
info {
68+
connectionState {
69+
status
70+
message
71+
}
72+
serverVersion
73+
cacheInfo {
74+
resourcesCount
75+
apisCount
76+
}
77+
}
78+
}
79+
}
80+
pageInfo {
81+
endCursor
82+
hasNextPage
83+
}
84+
}
85+
}
86+
`,
87+
"variables": map[string]interface{}{
88+
"runtime": runtime,
89+
"pagination": map[string]interface{}{
90+
"after": after,
91+
},
92+
},
93+
}
94+
95+
res := &graphqlClusterListResponse{}
96+
err := c.codefresh.graphqlAPI(ctx, jsonData, res)
97+
if err != nil {
98+
return nil, fmt.Errorf("failed getting cluster list: %w", err)
99+
}
100+
101+
if len(res.Errors) > 0 {
102+
return nil, graphqlErrorResponse{errors: res.Errors}
103+
}
104+
105+
return &res.Data.Clusters, nil
106+
}

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type (
3737

3838
V2API interface {
3939
Runtime() IRuntimeAPI
40+
Cluster() IClusterV2API
4041
GitSource() IGitSourceAPI
4142
Component() IComponentAPI
4243
Workflow() IWorkflowV2API
@@ -124,6 +125,10 @@ func (c *codefresh) CliReleases() ICliReleasesAPI {
124125
return newCliReleasesAPI(c)
125126
}
126127

128+
func (c *codefresh) Cluster() IClusterV2API {
129+
return newClusterV2API(c)
130+
}
131+
127132
func (c *codefresh) AppProxy(ctx context.Context, runtime string, insecure bool) (AppProxyAPI, error) {
128133
rt, err := c.V2().Runtime().Get(ctx, runtime)
129134
if err != nil {

0 commit comments

Comments
 (0)