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

Function createModule

cyctl/internal/create/modules.go:32–103  ·  view source on GitHub ↗

createModule allows you to create module Custom Resource.

(clientset *client.CyclopsV1Alpha1Client, moduleName, repo, path, version, namespace, valuesFile, templateName, outputFormat string)

Source from the content-addressed store, hash-verified

30
31// createModule allows you to create module Custom Resource.
32func createModule(clientset *client.CyclopsV1Alpha1Client, moduleName, repo, path, version, namespace, valuesFile, templateName, outputFormat string) {
33
34 values, err := os.ReadFile(valuesFile)
35 if err != nil {
36 log.Fatalf("Error reading values file: %v", err)
37 }
38 jsonValues, err := yaml.YAMLToJSON(values)
39 if err != nil {
40 log.Fatalf("Error converting values file to JSON: %v", err)
41 }
42
43 if templateName != "" && (repo == "" && path == "" && version == "") {
44 temp, err := clientset.TemplateStore("cyclops").Get(templateName)
45 if err != nil {
46 fmt.Printf("Error from server (Template NotFound): %v\n", err)
47 return
48 }
49 repo = temp.Spec.URL
50 path = temp.Spec.Path
51 version = temp.Spec.Version
52 }
53
54 // Define a new Module object
55 newModule := v1alpha1.Module{
56 TypeMeta: v1.TypeMeta{
57 APIVersion: "cyclops-ui.com/v1alpha1",
58 Kind: "Module",
59 },
60 ObjectMeta: v1.ObjectMeta{
61 Name: moduleName,
62 Namespace: namespace,
63 },
64 Spec: v1alpha1.ModuleSpec{
65 TemplateRef: v1alpha1.TemplateRef{
66 URL: repo,
67 Path: path,
68 Version: version,
69 },
70 Values: apiextensionsv1.JSON{Raw: jsonValues},
71 },
72 }
73
74 if outputFormat == "yaml" {
75 // Marshal the newModule object to JSON
76 jsonOutput, err := json.Marshal(newModule)
77 if err != nil {
78 log.Fatalf("Error marshalling module to JSON: %v", err)
79 }
80 // Convert JSON to YAML
81 yamlOutput, err := yaml.JSONToYAML(jsonOutput)
82 if err != nil {
83 log.Fatalf("Error converting module to YAML: %v", err)
84 }
85 fmt.Printf("---\n%s\n", yamlOutput)
86 } else if outputFormat == "json" {
87 output, err := json.MarshalIndent(newModule, "", " ")
88 if err != nil {
89 log.Fatalf("Error converting module to JSON: %v", err)

Callers 1

modules.goFile · 0.70

Calls 5

TemplateStoreMethod · 0.80
PrintfMethod · 0.80
ModulesMethod · 0.80
GetMethod · 0.65
CreateMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…