Browse Source

Merge pull request #2238 from porter-dev/belanger/hotfix-default-clusters

Add hotfix for duplicated default clusters
abelanger5 3 years ago
parent
commit
d1177e9a6a
1 changed files with 17 additions and 0 deletions
  1. 17 0
      cmd/app/main.go

+ 17 - 0
cmd/app/main.go

@@ -93,6 +93,23 @@ func initData(conf *config.Config) error {
 			return err
 		}
 
+		// determine if there are any clusters in the project already
+		clusters, err := conf.Repo.Cluster().ListClustersByProjectID(1)
+
+		if err != nil {
+			return err
+		}
+
+		// if there are already clusters in the project, determine if any of the clusters are using an
+		// in-cluster auth mechanism
+		if len(clusters) > 0 {
+			for _, cluster := range clusters {
+				if cluster.AuthMechanism == models.InCluster {
+					return nil
+				}
+			}
+		}
+
 		_, err = conf.Repo.Cluster().ReadCluster(1, 1)
 
 		if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {