Skip to content

Commit

Permalink
* depend on ApplicationSet from master branch (#100)
Browse files Browse the repository at this point in the history
* added PreserveResourcesOnDeletion option to appset
* fix appset->project delete order
  • Loading branch information
ATGardner authored Jun 15, 2021
1 parent 7dc340a commit 80ac723
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 48 deletions.
48 changes: 26 additions & 22 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,9 @@ func createApp(opts *createAppOptions) ([]byte, error) {
},
SyncPolicy: &argocdv1alpha1.SyncPolicy{
Automated: &argocdv1alpha1.SyncPolicyAutomated{
SelfHeal: true,
Prune: true,
SelfHeal: true,
Prune: true,
AllowEmpty: true,
},
SyncOptions: []string{
"allowEmpty=true",
Expand All @@ -146,20 +147,20 @@ func createApp(opts *createAppOptions) ([]byte, error) {
}

type createAppSetOptions struct {
name string
namespace string
appName string
appNamespace string
appProject string
repoURL string
revision string
srcPath string
destServer string
destNamespace string
noFinalizer bool
prune bool
appLabels map[string]string
generators []appset.ApplicationSetGenerator
name string
namespace string
appName string
appNamespace string
appProject string
repoURL string
revision string
srcPath string
destServer string
destNamespace string
prune bool
preserveResourcesOnDeletion bool
appLabels map[string]string
generators []appset.ApplicationSetGenerator
}

func createAppSet(o *createAppSetOptions) ([]byte, error) {
Expand All @@ -175,6 +176,9 @@ func createAppSet(o *createAppSetOptions) ([]byte, error) {
ObjectMeta: metav1.ObjectMeta{
Name: o.name,
Namespace: o.namespace,
Annotations: map[string]string{
"argocd.argoproj.io/sync-wave": "0",
},
},
Spec: appset.ApplicationSetSpec{
Generators: o.generators,
Expand All @@ -196,12 +200,16 @@ func createAppSet(o *createAppSetOptions) ([]byte, error) {
},
SyncPolicy: &appsetv1alpha1.SyncPolicy{
Automated: &appsetv1alpha1.SyncPolicyAutomated{
SelfHeal: true,
Prune: o.prune,
SelfHeal: true,
Prune: o.prune,
AllowEmpty: true,
},
},
},
},
SyncPolicy: &appset.ApplicationSetSyncPolicy{
PreserveResourcesOnDeletion: o.preserveResourcesOnDeletion,
},
},
}

Expand All @@ -217,9 +225,5 @@ func createAppSet(o *createAppSetOptions) ([]byte, error) {
appSet.Spec.Template.Spec.Project = o.appProject
}

if o.noFinalizer {
appSet.ObjectMeta.Finalizers = []string{}
}

return yaml.Marshal(appSet)
}
24 changes: 13 additions & 11 deletions cmd/commands/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func generateProjectManifests(o *GenerateProjectOptions) (projectYAML, appSetYAM
Name: o.Name,
Namespace: o.Namespace,
Annotations: map[string]string{
"argocd.argoproj.io/sync-wave": "-2",
"argocd.argoproj.io/sync-options": "PruneLast=true",
store.Default.DestServerAnnotation: o.DefaultDestServer,
},
Expand Down Expand Up @@ -264,17 +265,18 @@ func generateProjectManifests(o *GenerateProjectOptions) (projectYAML, appSetYAM
}

appSetYAML, err = createAppSet(&createAppSetOptions{
name: o.Name,
namespace: o.Namespace,
appName: fmt.Sprintf("%s-{{ userGivenName }}", o.Name),
appNamespace: o.Namespace,
appProject: o.Name,
repoURL: "{{ srcRepoURL }}",
srcPath: "{{ srcPath }}",
revision: "{{ srcTargetRevision }}",
destServer: "{{ destServer }}",
destNamespace: "{{ destNamespace }}",
prune: true,
name: o.Name,
namespace: o.Namespace,
appName: fmt.Sprintf("%s-{{ userGivenName }}", o.Name),
appNamespace: o.Namespace,
appProject: o.Name,
repoURL: "{{ srcRepoURL }}",
srcPath: "{{ srcPath }}",
revision: "{{ srcTargetRevision }}",
destServer: "{{ destServer }}",
destNamespace: "{{ destNamespace }}",
prune: true,
preserveResourcesOnDeletion: false,
appLabels: map[string]string{
"app.kubernetes.io/managed-by": store.Default.ManagedBy,
"app.kubernetes.io/name": "{{ appName }}",
Expand Down
20 changes: 10 additions & 10 deletions cmd/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,16 @@ func buildBootstrapManifests(namespace, appSpecifier string, cloneOpts *git.Clon
}

manifests.clusterResAppSet, err = createAppSet(&createAppSetOptions{
name: store.Default.ClusterResourcesDir,
namespace: namespace,
repoURL: cloneOpts.URL(),
revision: cloneOpts.Revision(),
appName: store.Default.ClusterResourcesDir + "-{{name}}",
appNamespace: namespace,
destServer: "{{server}}",
noFinalizer: true,
prune: false,
srcPath: filepath.Join(cloneOpts.Path(), store.Default.BootsrtrapDir, store.Default.ClusterResourcesDir, "{{name}}"),
name: store.Default.ClusterResourcesDir,
namespace: namespace,
repoURL: cloneOpts.URL(),
revision: cloneOpts.Revision(),
appName: store.Default.ClusterResourcesDir + "-{{name}}",
appNamespace: namespace,
destServer: "{{server}}",
prune: false,
preserveResourcesOnDeletion: true,
srcPath: filepath.Join(cloneOpts.Path(), store.Default.BootsrtrapDir, store.Default.ClusterResourcesDir, "{{name}}"),
generators: []appset.ApplicationSetGenerator{
{
Git: &appset.GitGenerator{
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
)

replace (
github.com/argoproj-labs/applicationset => github.com/argoproj-labs/applicationset v0.0.0-20210614145856-2c62537a8e5a
k8s.io/api => k8s.io/api v0.21.1
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.21.1
k8s.io/apimachinery => k8s.io/apimachinery v0.21.1
Expand Down
Loading

0 comments on commit 80ac723

Please sign in to comment.