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

Method Template

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

Source from the content-addressed store, hash-verified

696}
697
698func (m *Modules) Template(ctx *gin.Context) {
699 ctx.Header("Access-Control-Allow-Origin", "*")
700
701 module, err := m.kubernetesClient.GetModule(ctx.Param("name"))
702 if err != nil {
703 fmt.Println(err)
704 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching module", err.Error()))
705 return
706 }
707
708 currentTemplate, err := m.templatesRepo.GetTemplate(
709 module.Spec.TemplateRef.URL,
710 module.Spec.TemplateRef.Path,
711 module.Spec.TemplateRef.Version,
712 module.Status.TemplateResolvedVersion,
713 module.Spec.TemplateRef.SourceType,
714 )
715 if err != nil {
716 fmt.Println(err)
717 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error fetching template", err.Error()))
718 return
719 }
720
721 currentManifest, err := m.renderer.HelmTemplate(*module, currentTemplate)
722 if err != nil {
723 fmt.Println(err)
724 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error templating current", err.Error()))
725 return
726 }
727
728 proposedTemplate, err := m.templatesRepo.GetTemplate(
729 module.Spec.TemplateRef.URL,
730 module.Spec.TemplateRef.Path,
731 module.Spec.TemplateRef.Version,
732 module.Status.TemplateResolvedVersion,
733 module.Spec.TemplateRef.SourceType,
734 )
735 if err != nil {
736 fmt.Println(err)
737 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating proposed template", err.Error()))
738 return
739 }
740
741 proposedManifest, err := m.renderer.HelmTemplate(*module, proposedTemplate)
742 if err != nil {
743 fmt.Println(err)
744 ctx.JSON(http.StatusInternalServerError, dto.NewError("Error templating proposed", err.Error()))
745 return
746 }
747
748 res := dto.TemplatesResponse{
749 Current: currentManifest,
750 New: proposedManifest,
751 }
752
753 ctx.JSON(http.StatusOK, res)
754}
755

Callers

nothing calls this directly

Calls 5

PrintlnMethod · 0.80
ErrorMethod · 0.80
GetModuleMethod · 0.65
GetTemplateMethod · 0.65
HelmTemplateMethod · 0.45

Tested by

no test coverage detected