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

CR-9435 #235

Merged
merged 7 commits into from
Feb 24, 2022
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
31 changes: 18 additions & 13 deletions cmd/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ var (

type (
RepoBootstrapOptions struct {
AppSpecifier string
InstallationMode string
Namespace string
KubeConfig string
KubeContextName string
DryRun bool
HidePassword bool
Insecure bool
Timeout time.Duration
KubeFactory kube.Factory
CloneOptions *git.CloneOptions
ArgoCDLabels map[string]string
AppSpecifier string
InstallationMode string
Namespace string
KubeConfig string
KubeContextName string
DryRun bool
HidePassword bool
Insecure bool
Timeout time.Duration
KubeFactory kube.Factory
CloneOptions *git.CloneOptions
ArgoCDLabels map[string]string
BootstrapAppsLabels map[string]string
}

RepoUninstallOptions struct {
Expand Down Expand Up @@ -194,6 +195,7 @@ func RunRepoBootstrap(ctx context.Context, opts *RepoBootstrapOptions) error {
opts.AppSpecifier,
opts.CloneOptions,
opts.ArgoCDLabels,
opts.BootstrapAppsLabels,
)
if err != nil {
return fmt.Errorf("failed to build bootstrap manifests: %w", err)
Expand Down Expand Up @@ -507,7 +509,7 @@ func getBootstrapAppSpecifier(insecure bool) string {
return store.Get().InstallationManifestsURL
}

func buildBootstrapManifests(namespace, appSpecifier string, cloneOpts *git.CloneOptions, argocdLabels map[string]string) (*bootstrapManifests, error) {
func buildBootstrapManifests(namespace, appSpecifier string, cloneOpts *git.CloneOptions, argocdLabels map[string]string, bootstrapAppsLabels map[string]string) (*bootstrapManifests, error) {
var err error
manifests := &bootstrapManifests{}

Expand All @@ -517,6 +519,7 @@ func buildBootstrapManifests(namespace, appSpecifier string, cloneOpts *git.Clon
repoURL: cloneOpts.URL(),
revision: cloneOpts.Revision(),
srcPath: filepath.Join(cloneOpts.Path(), store.Default.BootsrtrapDir),
labels: bootstrapAppsLabels,
})
if err != nil {
return nil, err
Expand All @@ -528,6 +531,7 @@ func buildBootstrapManifests(namespace, appSpecifier string, cloneOpts *git.Clon
repoURL: cloneOpts.URL(),
revision: cloneOpts.Revision(),
srcPath: filepath.Join(cloneOpts.Path(), store.Default.ProjectsDir),
labels: bootstrapAppsLabels,
})
if err != nil {
return nil, err
Expand All @@ -553,6 +557,7 @@ func buildBootstrapManifests(namespace, appSpecifier string, cloneOpts *git.Clon
revision: cloneOpts.Revision(),
appName: store.Default.ClusterResourcesDir + "-{{name}}",
appNamespace: namespace,
appLabels: bootstrapAppsLabels,
destServer: "{{server}}",
prune: false,
preserveResourcesOnDeletion: true,
Expand Down
15 changes: 11 additions & 4 deletions cmd/commands/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ func Test_validateRepo(t *testing.T) {

func Test_buildBootstrapManifests(t *testing.T) {
type args struct {
namespace string
appSpecifier string
cloneOpts *git.CloneOptions
argoCDLabels map[string]string
namespace string
appSpecifier string
cloneOpts *git.CloneOptions
argoCDLabels map[string]string
bootstrapAppsLabels map[string]string
}
tests := map[string]struct {
args args
Expand All @@ -163,6 +164,9 @@ func Test_buildBootstrapManifests(t *testing.T) {
argoCDLabels: map[string]string{
"name": "value",
},
bootstrapAppsLabels: map[string]string{
"name": "value2",
},
},
assertFn: func(t *testing.T, b *bootstrapManifests, ret error) {
assert.NoError(t, ret)
Expand All @@ -186,6 +190,7 @@ func Test_buildBootstrapManifests(t *testing.T) {
assert.NotEqual(t, 0, len(bootstrapApp.ObjectMeta.Finalizers))
assert.Equal(t, "foo", bootstrapApp.Spec.Destination.Namespace)
assert.Equal(t, store.Default.DestServer, bootstrapApp.Spec.Destination.Server)
assert.Equal(t, "value2", bootstrapApp.ObjectMeta.Labels["name"])

rootApp := &argocdv1alpha1.Application{}
assert.NoError(t, yaml.Unmarshal(b.rootApp, rootApp))
Expand All @@ -195,6 +200,7 @@ func Test_buildBootstrapManifests(t *testing.T) {
assert.NotEqual(t, 0, len(rootApp.ObjectMeta.Finalizers))
assert.Equal(t, "foo", rootApp.Spec.Destination.Namespace)
assert.Equal(t, store.Default.DestServer, rootApp.Spec.Destination.Server)
assert.Equal(t, "value2", rootApp.ObjectMeta.Labels["name"])

ns := &v1.Namespace{}
assert.NoError(t, yaml.Unmarshal(b.namespace, ns))
Expand Down Expand Up @@ -226,6 +232,7 @@ func Test_buildBootstrapManifests(t *testing.T) {
tt.args.appSpecifier,
tt.args.cloneOpts,
tt.args.argoCDLabels,
tt.args.bootstrapAppsLabels,
)

tt.assertFn(t, b, ret)
Expand Down
3 changes: 2 additions & 1 deletion pkg/kube/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ func (f *factory) Delete(ctx context.Context, opts *DeleteOptions) error {
IOStreams: DefaultIOStreams(),
CascadingStrategy: metav1.DeletePropagationForeground,
DeleteAllNamespaces: true,
IgnoreNotFound: true,
LabelSelector: opts.LabelSelector,
Timeout: timeout,
WaitForDeletion: opts.WaitForDeletion,
Expand All @@ -257,7 +258,7 @@ func (f *factory) Delete(ctx context.Context, opts *DeleteOptions) error {

cmdutil.AddDryRunFlag(cmd)

cmd.SetArgs([]string{"--ignore-not-found"})
cmd.SetArgs([]string{})

return cmd.ExecuteContext(ctx)
}
Expand Down