7
7
"github.com/mark3labs/mcp-go/client"
8
8
"github.com/mark3labs/mcp-go/mcp"
9
9
"github.com/mark3labs/mcp-go/server"
10
+ "github.com/pkg/errors"
10
11
"github.com/spf13/afero"
12
+ "golang.org/x/sync/errgroup"
11
13
corev1 "k8s.io/api/core/v1"
12
14
rbacv1 "k8s.io/api/rbac/v1"
13
15
apiextensionsv1spec "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -212,16 +214,28 @@ func inOpenShift(c *mcpContext) {
212
214
"names": {"plural": "%s","singular": "%s","kind": "%s"}
213
215
}
214
216
}`
215
- c .crdApply (fmt .Sprintf (crdTemplate , "projects.project.openshift.io" , "project.openshift.io" ,
216
- "Cluster" , "projects" , "project" , "Project" ))
217
- c .crdApply (fmt .Sprintf (crdTemplate , "routes.route.openshift.io" , "route.openshift.io" ,
218
- "Namespaced" , "routes" , "route" , "Route" ))
217
+ tasks , _ := errgroup .WithContext (c .ctx )
218
+ tasks .Go (func () error {
219
+ return c .crdApply (fmt .Sprintf (crdTemplate , "projects.project.openshift.io" , "project.openshift.io" ,
220
+ "Cluster" , "projects" , "project" , "Project" ))
221
+ })
222
+ tasks .Go (func () error {
223
+ return c .crdApply (fmt .Sprintf (crdTemplate , "routes.route.openshift.io" , "route.openshift.io" ,
224
+ "Namespaced" , "routes" , "route" , "Route" ))
225
+ })
226
+ if err := tasks .Wait (); err != nil {
227
+ panic (err )
228
+ }
219
229
}
220
230
221
231
// inOpenShiftClear clears the kubernetes environment so it no longer seems to be running OpenShift
222
232
func inOpenShiftClear (c * mcpContext ) {
223
- c .crdDelete ("projects.project.openshift.io" )
224
- c .crdDelete ("routes.route.openshift.io" )
233
+ tasks , _ := errgroup .WithContext (c .ctx )
234
+ tasks .Go (func () error { return c .crdDelete ("projects.project.openshift.io" ) })
235
+ tasks .Go (func () error { return c .crdDelete ("routes.route.openshift.io" ) })
236
+ if err := tasks .Wait (); err != nil {
237
+ panic (err )
238
+ }
225
239
}
226
240
227
241
// newKubernetesClient creates a new Kubernetes client with the envTest kubeconfig
@@ -247,19 +261,20 @@ func (c *mcpContext) newApiExtensionsClient() *apiextensionsv1.ApiextensionsV1Cl
247
261
}
248
262
249
263
// crdApply creates a CRD from the provided resource string and waits for it to be established
250
- func (c * mcpContext ) crdApply (resource string ) {
264
+ func (c * mcpContext ) crdApply (resource string ) error {
251
265
apiExtensionsV1Client := c .newApiExtensionsClient ()
252
266
var crd = & apiextensionsv1spec.CustomResourceDefinition {}
253
267
err := json .Unmarshal ([]byte (resource ), crd )
254
268
_ , err = apiExtensionsV1Client .CustomResourceDefinitions ().Create (c .ctx , crd , metav1.CreateOptions {})
255
269
if err != nil {
256
- panic ( fmt .Errorf ("failed to create CRD %v" , err ) )
270
+ return fmt .Errorf ("failed to create CRD %v" , err )
257
271
}
258
272
c .crdWaitUntilReady (crd .Name )
273
+ return nil
259
274
}
260
275
261
276
// crdDelete deletes a CRD by name and waits for it to be removed
262
- func (c * mcpContext ) crdDelete (name string ) {
277
+ func (c * mcpContext ) crdDelete (name string ) error {
263
278
apiExtensionsV1Client := c .newApiExtensionsClient ()
264
279
err := apiExtensionsV1Client .CustomResourceDefinitions ().Delete (c .ctx , name , metav1.DeleteOptions {
265
280
GracePeriodSeconds : ptr .To (int64 (0 )),
@@ -273,8 +288,9 @@ func (c *mcpContext) crdDelete(name string) {
273
288
iteration ++
274
289
}
275
290
if err != nil {
276
- panic ( fmt . Errorf ( "failed to delete CRD %v" , err ) )
291
+ return errors . Wrap ( err , "failed to delete CRD" )
277
292
}
293
+ return nil
278
294
}
279
295
280
296
// crdWaitUntilReady waits for a CRD to be established
0 commit comments