Skip to content
Open
14 changes: 14 additions & 0 deletions api/v1alpha1/appgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ spec:
name:
description: Name of the application
type: string
order:
default: parallel
description: Order specifies the order in which the application
parent chart is deployed in comparison to it's subcharts (if
any)
type: string
spec:
description: Spec contains the application spec including the chart info and overlay values
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions config/samples/bookinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ spec:
# name: <secret-name>
# namespace: <secret-namespace>
release:
interval: 1m
targetNamespace: ambassador
values:
service:
type: ClusterIP
- name: bookinfo
dependencies: [ambassador]
order: first
spec:
chart:
url: "https://nitishm.github.io/charts"
Expand All @@ -43,6 +45,7 @@ spec:
- name: details
dependencies: []
release:
interval: 1m
targetNamespace: bookinfo
values:
productpage:
Expand Down
2 changes: 2 additions & 0 deletions controllers/appgroup_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion examples/simple/bookinfo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ kind: ApplicationGroup
metadata:
name: bookinfo
spec:
interval: 1m
applications:
- name: ambassador
dependencies: []
Expand All @@ -21,13 +22,14 @@ spec:
# name: <secret-name>
# namespace: <secret-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"
Expand All @@ -43,6 +45,7 @@ spec:
- name: details
dependencies: []
release:
interval: 1m
targetNamespace: bookinfo
values:
productpage:
Expand Down
20 changes: 16 additions & 4 deletions pkg/workflow/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,15 @@ func (a *argo) generateSubchartAndAppDAGTasks(ctx context.Context, g *v1alpha1.A
},
},
},
Dependencies: convertSliceToDNS1123(sc.Dependencies),
Dependencies: func() (out []string) {
out = 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, pkg.ConvertToDNS1123(app.Name))
}
return out
}(),
}

tasks = append(tasks, task)
Expand Down Expand Up @@ -606,12 +614,16 @@ func (a *argo) generateSubchartAndAppDAGTasks(ctx context.Context, g *v1alpha1.A
},
},
Dependencies: func() (out []string) {
for _, t := range tasks {
out = append(out, pkg.ConvertToDNS1123(t.Name))
if app.Order == v1alpha1.Last {
for _, t := range tasks {
out = append(out, pkg.ConvertToDNS1123(t.Name))
}
return
}
return out
return
}(),
}

tasks = append(tasks, task)

return tasks, nil
Expand Down