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

Order the release of application parent chart #238

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
13 changes: 13 additions & 0 deletions api/v1alpha1/appgroup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,25 @@ 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
nitishm marked this conversation as resolved.
Show resolved Hide resolved
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:default:="parallel"
nitishm marked this conversation as resolved.
Show resolved Hide resolved
// +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 @@ -62,6 +62,12 @@ spec:
name:
description: Name of the application
type: string
order:
nitishm marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,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
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
6 changes: 4 additions & 2 deletions controllers/appgroup_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (r *ApplicationGroupReconciler) reconcileApplications(l logr.Logger, appGro
scc.Templates = append(scc.Templates, t)
}
}
scc.Files = append(scc.Files, appCh.Files...)
// scc.Files = append(scc.Files, appCh.Files...)
nitishm marked this conversation as resolved.
Show resolved Hide resolved

scc.Metadata.Name = pkg.ConvertToDNS1123(pkg.ToInitials(appCh.Metadata.Name) + "-" + scc.Metadata.Name)
path, err := registry.SaveChartPackage(scc, stagingDir)
Expand Down Expand Up @@ -194,6 +194,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 All @@ -210,7 +212,7 @@ func (r *ApplicationGroupReconciler) reconcileApplications(l logr.Logger, appGro
}

// Replace existing chart with modified chart
path := stagingDir + "/" + application.Spec.Chart.Name + "-" + appCh.Metadata.Version + ".tgz"
path := stagingDir + "/" + pkg.ConvertToDNS1123(application.Spec.Chart.Name) + "-" + appCh.Metadata.Version + ".tgz"
err = r.RegistryClient.PushChart(ll, r.StagingRepoName, path, appCh)
defer func() {
if r.CleanupDownloadedCharts {
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
24 changes: 18 additions & 6 deletions pkg/workflow/argo.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ func (a *argo) generateAppDAGTemplates(ctx context.Context, g *v1alpha1.Applicat
Spec: fluxhelmv2beta1.HelmReleaseSpec{
Chart: fluxhelmv2beta1.HelmChartTemplate{
Spec: fluxhelmv2beta1.HelmChartTemplateSpec{
Chart: app.Spec.Chart.Name,
Chart: pkg.ConvertToDNS1123(app.Spec.Chart.Name),
Version: app.Spec.Chart.Version,
SourceRef: fluxhelmv2beta1.CrossNamespaceObjectReference{
Kind: "HelmRepository",
Expand Down Expand Up @@ -543,7 +543,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 All @@ -561,7 +569,7 @@ func (a *argo) generateSubchartAndAppDAGTasks(ctx context.Context, g *v1alpha1.A
Spec: fluxhelmv2beta1.HelmReleaseSpec{
Chart: fluxhelmv2beta1.HelmChartTemplate{
Spec: fluxhelmv2beta1.HelmChartTemplateSpec{
Chart: app.Spec.Chart.Name,
Chart: pkg.ConvertToDNS1123(app.Spec.Chart.Name),
Version: app.Spec.Chart.Version,
SourceRef: fluxhelmv2beta1.CrossNamespaceObjectReference{
Kind: "HelmRepository",
Expand Down Expand Up @@ -630,12 +638,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