diff --git a/cyclops-ctrl/internal/models/templates.go b/cyclops-ctrl/internal/models/templates.go index 7d98adcc..24a3d221 100644 --- a/cyclops-ctrl/internal/models/templates.go +++ b/cyclops-ctrl/internal/models/templates.go @@ -25,6 +25,7 @@ type Template struct { CRDs []*chart.File `json:"crds"` Dependencies []*Template `json:"dependencies"` + Condition string `json:"condition"` } type Field struct { @@ -39,7 +40,7 @@ type Field struct { Enum []interface{} `json:"enum"` Required []string `json:"required"` FileExtension string `json:"fileExtension"` - Immutable bool `json:"immutable"` + Immutable bool `json:"immutable"` // number validation Minimum *float64 `json:"minimum"` diff --git a/cyclops-ctrl/internal/template/helm.go b/cyclops-ctrl/internal/template/helm.go index 8d81f649..88911f7f 100644 --- a/cyclops-ctrl/internal/template/helm.go +++ b/cyclops-ctrl/internal/template/helm.go @@ -179,7 +179,8 @@ func (r Repo) mapHelmChart(chartName string, files map[string][]byte) (*models.T continue } - if len(parts) > 2 && parts[1] == "templates" && (parts[2] != "Notes.txt" && parts[2] != "NOTES.txt") { + if len(parts) > 2 && parts[1] == "templates" && + (parts[2] != "Notes.txt" && parts[2] != "NOTES.txt" && parts[2] != "tests") { templateFiles = append(templateFiles, &helmchart.File{ Name: path.Join(parts[1:]...), Data: content, @@ -187,7 +188,8 @@ func (r Repo) mapHelmChart(chartName string, files map[string][]byte) (*models.T continue } - if len(parts) > 2 && parts[1] == "crds" && (parts[2] != "Notes.txt" && parts[2] != "NOTES.txt") { + if len(parts) > 2 && parts[1] == "crds" && + (parts[2] != "Notes.txt" && parts[2] != "NOTES.txt" && parts[2] != "tests") { crdFiles = append(crdFiles, &helmchart.File{ Name: path.Join(parts[1:]...), Data: content, diff --git a/cyclops-ctrl/internal/template/render/render.go b/cyclops-ctrl/internal/template/render/render.go index 4391e247..0633262c 100644 --- a/cyclops-ctrl/internal/template/render/render.go +++ b/cyclops-ctrl/internal/template/render/render.go @@ -10,9 +10,9 @@ import ( "helm.sh/helm/v3/pkg/engine" cyclopsv1alpha1 "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1" - "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/models" "github.com/cyclops-ui/cyclops/cyclops-ctrl/internal/models/helm" + "github.com/cyclops-ui/cyclops/cyclops-ctrl/pkg/cluster/k8sclient" ) type Renderer struct { @@ -40,7 +40,16 @@ func (r *Renderer) HelmTemplate(module cyclopsv1alpha1.Module, moduleTemplate *m Templates: moduleTemplate.Templates, } + values := make(chartutil.Values) + if err := json.Unmarshal(module.Spec.Values.Raw, &values); err != nil { + return "", err + } + for _, dependency := range moduleTemplate.Dependencies { + if !evaluateDependencyCondition(dependency.Condition, values) { + continue + } + chart.AddDependency(&helmchart.Chart{ Raw: []*helmchart.File{}, Metadata: mapMetadata(dependency.HelmChartMetadata), @@ -52,11 +61,6 @@ func (r *Renderer) HelmTemplate(module cyclopsv1alpha1.Module, moduleTemplate *m }) } - values := make(chartutil.Values) - if err := json.Unmarshal(module.Spec.Values.Raw, &values); err != nil { - return "", err - } - top := make(chartutil.Values) top["Values"] = values top["Release"] = map[string]interface{}{ @@ -150,6 +154,33 @@ func mapMetadata(metadata *helm.Metadata) *helmchart.Metadata { } } +func evaluateDependencyCondition(condition string, values map[string]interface{}) bool { + if len(condition) == 0 { + return true + } + + keys := strings.Split(condition, ".") + var current interface{} = values + + for _, key := range keys { + if m, ok := current.(map[string]interface{}); ok { + if val, exists := m[key]; exists { + current = val + } else { + return false + } + } else { + return false + } + } + + if result, ok := current.(bool); ok { + return result + } + + return false +} + func mapTargetNamespace(namespace string) string { if len(namespace) == 0 { return "default" diff --git a/cyclops-ctrl/internal/template/template.go b/cyclops-ctrl/internal/template/template.go index bf63edb4..b6171172 100644 --- a/cyclops-ctrl/internal/template/template.go +++ b/cyclops-ctrl/internal/template/template.go @@ -85,6 +85,8 @@ func (r Repo) loadDependencies(metadata *helm.Metadata) ([]*models.Template, err return nil, err } + dep.Condition = dependency.Condition + deps = append(deps, dep) } diff --git a/cyclops-ui/src/components/pages/ModuleDetails.tsx b/cyclops-ui/src/components/pages/ModuleDetails.tsx index 79691bbd..40043d9d 100644 --- a/cyclops-ui/src/components/pages/ModuleDetails.tsx +++ b/cyclops-ui/src/components/pages/ModuleDetails.tsx @@ -1019,7 +1019,7 @@ const ModuleDetails = () => { onOk={handleCancelManifest} onCancel={handleCancelManifest} cancelButtonProps={{ style: { display: "none" } }} - width={"40%"} + width={"70%"} > Include Managed Fields