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

Method UpdateModule

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

Source from the content-addressed store, hash-verified

334}
335
336func (m *Modules) UpdateModule(ctx *gin.Context) {
337 ctx.Header("Access-Control-Allow-Origin", "*")
338
339 var request dto.Module
340 if err := ctx.BindJSON(&request); err != nil {
341 fmt.Println(err)
342 ctx.JSON(http.StatusBadRequest, dto.NewError("Error mapping module request", err.Error()))
343 return
344 }
345
346 curr, err := m.kubernetesClient.GetModule(request.Name)
347 if err != nil {
348 fmt.Println(err)
349 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching module", err.Error()))
350 return
351 }
352
353 module, err := mapper.RequestToModule(request)
354 if err != nil {
355 fmt.Println(err)
356 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating module", err.Error()))
357 return
358 }
359
360 module.Spec.TemplateRef.SourceType = curr.Spec.TemplateRef.SourceType
361
362 module.Status.TemplateResolvedVersion = request.Template.ResolvedVersion
363 module.Status.ReconciliationStatus = curr.Status.ReconciliationStatus
364 module.Status.IconURL = curr.Status.IconURL
365 module.Status.ManagedGVRs = curr.Status.ManagedGVRs
366
367 module.Spec.TargetNamespace = curr.Spec.TargetNamespace
368 module.SetLabels(curr.GetLabels())
369
370 annotations := curr.GetAnnotations()
371 moduleAnnotations := module.GetAnnotations()
372
373 if annotations == nil {
374 annotations = make(map[string]string)
375 }
376
377 if moduleAnnotations != nil {
378 if _, ok := moduleAnnotations["cyclops-ui.com/write-repo"]; ok {
379 annotations["cyclops-ui.com/write-repo"] = moduleAnnotations["cyclops-ui.com/write-repo"]
380 }
381 if _, ok := moduleAnnotations["cyclops-ui.com/write-path"]; ok {
382 annotations["cyclops-ui.com/write-path"] = moduleAnnotations["cyclops-ui.com/write-path"]
383 }
384 if _, ok := moduleAnnotations["cyclops-ui.com/write-revision"]; ok {
385 annotations["cyclops-ui.com/write-revision"] = moduleAnnotations["cyclops-ui.com/write-revision"]
386 }
387 }
388
389 if len(moduleAnnotations) == 0 || len(moduleAnnotations[v1alpha1.GitOpsWriteRepoAnnotation]) == 0 {
390 delete(annotations, v1alpha1.GitOpsWriteRepoAnnotation)
391 }
392 if len(moduleAnnotations) == 0 || len(moduleAnnotations[v1alpha1.GitOpsWritePathAnnotation]) == 0 {
393 delete(annotations, v1alpha1.GitOpsWritePathAnnotation)

Callers

nothing calls this directly

Calls 6

PrintlnMethod · 0.80
ErrorMethod · 0.80
GetModuleMethod · 0.65
UpdateModuleStatusMethod · 0.65
UpdateModuleMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected