77 "github.com/mark3labs/mcp-go/client"
88 "github.com/mark3labs/mcp-go/mcp"
99 "github.com/mark3labs/mcp-go/server"
10+ "github.com/pkg/errors"
1011 "github.com/spf13/afero"
12+ "golang.org/x/sync/errgroup"
1113 corev1 "k8s.io/api/core/v1"
1214 rbacv1 "k8s.io/api/rbac/v1"
1315 apiextensionsv1spec "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
@@ -212,16 +214,28 @@ func inOpenShift(c *mcpContext) {
212214 "names": {"plural": "%s","singular": "%s","kind": "%s"}
213215 }
214216 }`
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+ }
219229}
220230
221231// inOpenShiftClear clears the kubernetes environment so it no longer seems to be running OpenShift
222232func 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+ }
225239}
226240
227241// newKubernetesClient creates a new Kubernetes client with the envTest kubeconfig
@@ -247,19 +261,20 @@ func (c *mcpContext) newApiExtensionsClient() *apiextensionsv1.ApiextensionsV1Cl
247261}
248262
249263// 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 {
251265 apiExtensionsV1Client := c .newApiExtensionsClient ()
252266 var crd = & apiextensionsv1spec.CustomResourceDefinition {}
253267 err := json .Unmarshal ([]byte (resource ), crd )
254268 _ , err = apiExtensionsV1Client .CustomResourceDefinitions ().Create (c .ctx , crd , metav1.CreateOptions {})
255269 if err != nil {
256- panic ( fmt .Errorf ("failed to create CRD %v" , err ) )
270+ return fmt .Errorf ("failed to create CRD %v" , err )
257271 }
258272 c .crdWaitUntilReady (crd .Name )
273+ return nil
259274}
260275
261276// 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 {
263278 apiExtensionsV1Client := c .newApiExtensionsClient ()
264279 err := apiExtensionsV1Client .CustomResourceDefinitions ().Delete (c .ctx , name , metav1.DeleteOptions {
265280 GracePeriodSeconds : ptr .To (int64 (0 )),
@@ -273,8 +288,9 @@ func (c *mcpContext) crdDelete(name string) {
273288 iteration ++
274289 }
275290 if err != nil {
276- panic ( fmt . Errorf ( "failed to delete CRD %v" , err ) )
291+ return errors . Wrap ( err , "failed to delete CRD" )
277292 }
293+ return nil
278294}
279295
280296// crdWaitUntilReady waits for a CRD to be established
0 commit comments