Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support common git source #567

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5f50e06
support common git source
petar-cvit Sep 11, 2024
0ea80a1
⚙️ update cyclops to v0.11.1-rc.1
github-actions[bot] Sep 12, 2024
69af811
✨ copy labels from current module (#569)
petar-cvit Sep 12, 2024
29125cf
⬆️ bump v0.11.1 (#571)
petar-cvit Sep 13, 2024
28b70ab
🕒 progressing deployment state (#570)
petar-cvit Sep 17, 2024
e52078d
✏️ civo x cyclops (#573)
KaradzaJuraj Sep 17, 2024
7b7d3cc
🪝 fetch resources by cyclops module
nitintecg Sep 18, 2024
c19397c
⛓️ fetch module list periodicaly (#577)
petar-cvit Sep 19, 2024
85299a2
💧 immutable dropdown (#578)
petar-cvit Sep 19, 2024
9519252
🖋️ immutable fields docsw (#579)
petar-cvit Sep 19, 2024
7dd794c
🆙 bump to 0.12.0 (#580)
petar-cvit Sep 19, 2024
07fc158
💿 sts progressing status (#581)
petar-cvit Sep 20, 2024
7e59c87
🌊 stream all module resources (#582)
petar-cvit Sep 23, 2024
d642fad
✨ default target namespace (#583)
petar-cvit Sep 23, 2024
455d6b4
🧮 pass commit sha to get template (#584)
petar-cvit Sep 23, 2024
486c9c2
🤖 bump express from 4.19.2 to 4.21.0 in /cyclops-ui (#576)
dependabot[bot] Sep 23, 2024
9a03005
✨ smaller default template image (#587)
petar-cvit Sep 23, 2024
35234aa
🪗 advanced module section (#588)
petar-cvit Sep 23, 2024
9b3c01e
⚙️ update cyclops to v0.13.0
github-actions[bot] Sep 24, 2024
55024f6
🫥 remove use navigate (#589)
petar-cvit Sep 24, 2024
5d57a20
⚙️ update cyclops to v0.13.1
github-actions[bot] Sep 24, 2024
ccc0318
⚙️ docs to v0.13.1 (#590)
KaradzaJuraj Sep 26, 2024
ff8e34f
Merge branch 'main' into support-common-git-template-source
petar-cvit Sep 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 70 additions & 51 deletions cyclops-ctrl/internal/template/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,87 +69,106 @@ func (r Repo) LoadTemplate(repoURL, path, commit, resolvedVersion string) (*mode
return nil, err
}

// load helm chart metadata
chartMetadata, err := fs.Open(path2.Join(path, "Chart.yaml"))
// region read files
filesFs, err := fs.Chroot(path)
if err != nil {
return nil, errors.Wrap(err, "could not read 'Chart.yaml' file; it should be placed in the repo/path you provided; make sure you provided the correct path")
return nil, errors.Wrap(err, "could not find 'templates' dir; it should be placed in the repo/path you provided; make sure 'templates' directory exists")
}

var chartMetadataBuffer bytes.Buffer
_, err = io.Copy(bufio.NewWriter(&chartMetadataBuffer), chartMetadata)
files, err := readFiles("", filesFs)
if err != nil {
return nil, err
}

var metadata *helm.Metadata
if err := yaml.Unmarshal(chartMetadataBuffer.Bytes(), &metadata); err != nil {
return nil, err
return nil, errors.Wrap(err, "failed to read template files")
}
// endregion

// region read templates
templatesPath := path2.Join(path, "templates")
// region map files to template
metadataBytes := []byte{}
schemaBytes := []byte{}
chartFiles := make([]*chart.File, 0)

_, err = fs.ReadDir(templatesPath)
if err != nil {
return nil, errors.Wrap(err, "could not find 'templates' dir; it should be placed in the repo/path you provided; make sure 'templates' directory exists")
}
templateFiles := make([]*chart.File, 0)
crdFiles := make([]*chart.File, 0)

manifests, err := concatenateTemplates(templatesPath, fs)
if err != nil {
return nil, errors.Wrap(err, "failed to load template files")
}
// endregion
dependenciesFromChartsDir := make(map[string]map[string][]byte, 0)

// region read files
filesFs, err := fs.Chroot(path)
if err != nil {
return nil, errors.Wrap(err, "could not find 'templates' dir; it should be placed in the repo/path you provided; make sure 'templates' directory exists")
}
for _, f := range files {
parts := strings.Split(f.Name, "/")

chartFiles, err := readFiles("", filesFs)
if err != nil {
return nil, errors.Wrap(err, "failed to read template files")
}
// endregion
if len(parts) == 1 && parts[0] == "Chart.yaml" {
metadataBytes = f.Data
continue
}

// region read schema
schemaFile, err := fs.Open(path2.Join(path, "values.schema.json"))
if err != nil {
return nil, errors.Wrap(err, "could not read 'values.schema.json' file; it should be placed in the repo/path you provided; make sure 'templates' directory exists")
}
if len(parts) == 1 && parts[0] == "values.schema.json" {
schemaBytes = f.Data
continue
}

if len(parts) > 1 && parts[0] == "templates" &&
(parts[1] != "Notes.txt" && parts[1] != "NOTES.txt" && parts[1] != "tests") {
templateFiles = append(templateFiles, f)
continue
}

if len(parts) > 1 && parts[0] == "crds" &&
(parts[1] != "Notes.txt" && parts[1] != "NOTES.txt") {
crdFiles = append(crdFiles, f)
continue
}

chartFiles = append(chartFiles, f)

var schemaChartBuffer bytes.Buffer
_, err = io.Copy(bufio.NewWriter(&schemaChartBuffer), schemaFile)
if err != nil {
return nil, err
}

var schema helm.Property
if err := json.Unmarshal(schemaChartBuffer.Bytes(), &schema); err != nil {
return nil, err
// unmarshal values schema only if present
if len(schemaBytes) > 0 {
if err := json.Unmarshal(schemaBytes, &schema); err != nil {
fmt.Println("error on schema bytes", repoURL, path)
return &models.Template{}, err
}
}

var metadata *helm.Metadata
if err := yaml.Unmarshal(metadataBytes, &metadata); err != nil {
fmt.Println("error on meta unm", repoURL, path)
return &models.Template{}, err
}
// endregion

// region load dependencies
dependencies, err := r.loadDependencies(metadata)
if err != nil {
return nil, err
return &models.Template{}, err
}

for depName, files := range dependenciesFromChartsDir {
if dependencyExists(depName, dependencies) {
continue
}

dep, err := r.mapHelmChart(depName, files)
if err != nil {
return nil, err
}

dependencies = append(dependencies, dep)
}
// endregion

template := &models.Template{
Name: "",
Manifest: strings.Join(manifests, "---\n"),
RootField: mapper.HelmSchemaToFields("", schema, schema.Definitions, dependencies),
Created: "",
Edited: "",
Version: commit,
Name: path,
ResolvedVersion: commitSHA,
Version: commit,
RootField: mapper.HelmSchemaToFields("", schema, schema.Definitions, dependencies),
Files: chartFiles,
Templates: templateFiles,
CRDs: crdFiles,
Dependencies: dependencies,
HelmChartMetadata: metadata,
RawSchema: schemaBytes,
IconURL: metadata.Icon,
}
// endregion

r.cache.SetTemplate(repoURL, path, commitSHA, template)

Expand Down
Loading