From 26ce6d02a7ad513537f208a3f7237c0c3aa6c9d2 Mon Sep 17 00:00:00 2001 From: Prateek Gogia Date: Tue, 17 May 2022 17:21:10 -0500 Subject: [PATCH] Add path for cleaning up config when deleting env (#214) --- substrate/pkg/controller/substrate/cluster/config.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/substrate/pkg/controller/substrate/cluster/config.go b/substrate/pkg/controller/substrate/cluster/config.go index 5ab1197a..83a11070 100644 --- a/substrate/pkg/controller/substrate/cluster/config.go +++ b/substrate/pkg/controller/substrate/cluster/config.go @@ -48,6 +48,7 @@ import ( ) const ( + clusterConfigDir = ".kit/env" kubeconfigPath = "/etc/kubernetes" kubeconfigFile = "etc/kubernetes/admin.conf" certPKIPath = "/etc/kubernetes/pki" @@ -129,6 +130,13 @@ func (c *Config) Delete(ctx context.Context, substrate *v1alpha1.Substrate) (rec } else { logging.FromContext(ctx).Infof("Deleted S3 bucket %s", aws.StringValue(discovery.Name(substrate))) } + if c.clusterConfigPath == "" { + home, err := os.UserHomeDir() + if err != nil { + return reconcile.Result{}, fmt.Errorf("finding HOME dir %v", err) + } + c.clusterConfigPath = filepath.Join(home, clusterConfigDir) + } return reconcile.Result{}, os.RemoveAll(path.Join(c.clusterConfigPath, aws.StringValue(discovery.Name(substrate)))) } @@ -335,9 +343,9 @@ func (c *Config) ensureKitEnvDir() error { if err != nil { return fmt.Errorf("finding HOME dir %v", err) } - c.clusterConfigPath = filepath.Join(home, ".kit/env") + c.clusterConfigPath = filepath.Join(home, clusterConfigDir) if err := os.MkdirAll(c.clusterConfigPath, 0755); err != nil { - return fmt.Errorf("creating .kit/env dir %v", err) + return fmt.Errorf("creating cluster config dir %v", err) } return nil }