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

fix bootstrap delete #100

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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