MCPcopy
hub / github.com/cyclops-ui/cyclops / CreateModule

Method CreateModule

cyclops-ctrl/internal/controller/modules.go:293–334  ·  view source on GitHub ↗
(ctx *gin.Context)

Source from the content-addressed store, hash-verified

291}
292
293func (m *Modules) CreateModule(ctx *gin.Context) {
294 ctx.Header("Access-Control-Allow-Origin", "*")
295
296 var request dto.Module
297 if err := ctx.BindJSON(&request); err != nil {
298 fmt.Println("error binding request", request)
299 ctx.JSON(http.StatusBadRequest, dto.NewError("Error loading template", err.Error()))
300 return
301 }
302
303 module, err := mapper.RequestToModule(request)
304 if err != nil {
305 fmt.Println(err)
306 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error mapping module", err.Error()))
307 return
308 }
309
310 if len(m.moduleTargetNamespace) > 0 {
311 module.Spec.TargetNamespace = m.moduleTargetNamespace
312 }
313
314 m.telemetryClient.ModuleCreation()
315
316 if module.GetAnnotations() != nil && len(module.GetAnnotations()[v1alpha1.GitOpsWriteRepoAnnotation]) != 0 {
317 err := m.gitWriteClient.Write(module)
318 if err != nil {
319 fmt.Println(err)
320 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error pushing to git", err.Error()))
321 }
322 return
323 }
324
325 err = m.kubernetesClient.CreateModule(module)
326 if err != nil {
327 fmt.Println(err)
328 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating module", err.Error()))
329 return
330 }
331
332 m.monitor.IncModule()
333 ctx.Status(http.StatusOK)
334}
335
336func (m *Modules) UpdateModule(ctx *gin.Context) {
337 ctx.Header("Access-Control-Allow-Origin", "*")

Callers

nothing calls this directly

Calls 6

PrintlnMethod · 0.80
ErrorMethod · 0.80
IncModuleMethod · 0.80
ModuleCreationMethod · 0.65
CreateModuleMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected