diff --git a/api/v1alpha1/appgroup_types.go b/api/v1alpha1/appgroup_types.go index c2d07b48..9984a3c7 100644 --- a/api/v1alpha1/appgroup_types.go +++ b/api/v1alpha1/appgroup_types.go @@ -141,12 +141,26 @@ type ApplicationGroupSpec struct { Interval *metav1.Duration `json:"interval,omitempty"` } +type ParentChartOrder string + +const ( + Parallel ParentChartOrder = "parallel" + First ParentChartOrder = "first" + Last ParentChartOrder = "last" +) + // Application spec and dependency on other applications type Application struct { // DAG contains the dependency information DAG `json:",inline"` // Spec contains the application spec including the chart info and overlay values Spec ApplicationSpec `json:"spec,omitempty"` + // Order specifies the order in which the application + // parent chart is deployed in comparison to it's subcharts (if any) + // +kubebuilder:validation:Enum:="parallel";"first";"last" + // +kubebuilder:default:="last" + // +optional + Order ParentChartOrder `json:"order,omitempty"` } // DAG contains the dependency information diff --git a/chart/orkestra/crds/orkestra.azure.microsoft.com_applicationgroups.yaml b/chart/orkestra/crds/orkestra.azure.microsoft.com_applicationgroups.yaml index 5fbc0f64..5d5679fe 100644 --- a/chart/orkestra/crds/orkestra.azure.microsoft.com_applicationgroups.yaml +++ b/chart/orkestra/crds/orkestra.azure.microsoft.com_applicationgroups.yaml @@ -58,6 +58,16 @@ spec: name: description: Name of the application type: string + order: + default: last + description: Order specifies the order in which the application + parent chart is deployed in comparison to it's subcharts (if + any) + enum: + - parallel + - first + - last + type: string spec: description: Spec contains the application spec including the chart info and overlay values properties: diff --git a/config/crd/bases/orkestra.azure.microsoft.com_applicationgroups.yaml b/config/crd/bases/orkestra.azure.microsoft.com_applicationgroups.yaml index 5fbc0f64..5d5679fe 100644 --- a/config/crd/bases/orkestra.azure.microsoft.com_applicationgroups.yaml +++ b/config/crd/bases/orkestra.azure.microsoft.com_applicationgroups.yaml @@ -58,6 +58,16 @@ spec: name: description: Name of the application type: string + order: + default: last + description: Order specifies the order in which the application + parent chart is deployed in comparison to it's subcharts (if + any) + enum: + - parallel + - first + - last + type: string spec: description: Spec contains the application spec including the chart info and overlay values properties: diff --git a/config/samples/bookinfo.yaml b/config/samples/bookinfo.yaml index 1dfb3b88..d12136b4 100644 --- a/config/samples/bookinfo.yaml +++ b/config/samples/bookinfo.yaml @@ -22,12 +22,14 @@ spec: # name: # namespace: release: + interval: 1m targetNamespace: ambassador values: service: type: ClusterIP - name: bookinfo dependencies: [ambassador] + order: last spec: chart: url: "https://nitishm.github.io/charts" @@ -43,6 +45,7 @@ spec: - name: details dependencies: [] release: + interval: 1m targetNamespace: bookinfo values: productpage: diff --git a/controllers/appgroup_reconciler.go b/controllers/appgroup_reconciler.go index 1e41a07f..f513540f 100644 --- a/controllers/appgroup_reconciler.go +++ b/controllers/appgroup_reconciler.go @@ -197,6 +197,8 @@ func (r *ApplicationGroupReconciler) reconcileApplications(l logr.Logger, appGro appCh.Templates = append(appCh.Templates, dummy) } + appCh.Metadata.Name = pkg.ConvertToDNS1123(appCh.Metadata.Name) + if err := appCh.Validate(); err != nil { ll.Error(err, "failed to validate application chart for staging registry") err = fmt.Errorf("failed to validate application chart for staging registry : %w", err) diff --git a/examples/simple/bookinfo.yaml b/examples/simple/bookinfo.yaml index 6bda06fc..d12136b4 100644 --- a/examples/simple/bookinfo.yaml +++ b/examples/simple/bookinfo.yaml @@ -3,6 +3,7 @@ kind: ApplicationGroup metadata: name: bookinfo spec: + interval: 1m applications: - name: ambassador dependencies: [] @@ -21,13 +22,14 @@ spec: # name: # namespace: release: - timeout: 10m + interval: 1m targetNamespace: ambassador values: service: type: ClusterIP - name: bookinfo dependencies: [ambassador] + order: last spec: chart: url: "https://nitishm.github.io/charts" @@ -43,6 +45,7 @@ spec: - name: details dependencies: [] release: + interval: 1m targetNamespace: bookinfo values: productpage: diff --git a/pkg/workflow/argo.go b/pkg/workflow/argo.go index df5dbf10..d65c9fba 100644 --- a/pkg/workflow/argo.go +++ b/pkg/workflow/argo.go @@ -508,7 +508,15 @@ func (a *argo) generateSubchartAndAppDAGTasks(ctx context.Context, g *v1alpha1.A }, }, }, - Dependencies: utils.ConvertSliceToDNS1123(sc.Dependencies), + Dependencies: func() (out []string) { + out = utils.convertSliceToDNS1123(sc.Dependencies) + // If parent chart must be deployed first then add it + // as a dependency for every subchart + if app.Order == v1alpha1.First { + out = append(out, utils.ConvertToDNS1123(app.Name)) + } + return out + }(), } tasks = append(tasks, task) @@ -583,12 +591,14 @@ func (a *argo) generateSubchartAndAppDAGTasks(ctx context.Context, g *v1alpha1.A }, }, Dependencies: func() (out []string) { + if app.Order == v1alpha1.Last { for _, t := range tasks { out = append(out, utils.ConvertToDNS1123(t.Name)) } - return out + return }(), } + tasks = append(tasks, task) return tasks, nil