Skip to content

Commit

Permalink
Merge pull request #204 from kubefirst/k3d-import-tolerance
Browse files Browse the repository at this point in the history
fix: allow continued start when import secret doesn't exist (k3d)
  • Loading branch information
johndietz authored Oct 18, 2023
2 parents c46c088 + 337c2b8 commit f4e943e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion internal/db/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (mdbcl *MongoDBClient) TestDatabaseConnection(silent bool) error {
}

// ImportClusterIfEmpty
func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool) (pkgtypes.Cluster, error) {
func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool, cloudProvider string) (pkgtypes.Cluster, error) {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: "",
Expand All @@ -106,6 +106,10 @@ func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool) (pkgtypes.Cluster,
if os.Getenv("IS_CLUSTER_ZERO") == "true" {
log.Info("IS_CLUSTER_ZERO is set to true, skipping import cluster logic.")
return pkgtypes.Cluster{}, nil
}
if os.Getenv("CLOUD_PROVIDER") == "k3d" {
log.Info("CLOUD_PROVIDER is set to k3d, skipping import cluster logic.")
return pkgtypes.Cluster{}, nil
}

homeDir, err := os.UserHomeDir()
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func main() {
if os.Getenv("MONGODB_HOST_TYPE") == "" {
log.Fatalf("the MONGODB_HOST_TYPE environment variable must be set to either: atlas, local")
}
for _, v := range []string{"MONGODB_HOST", "MONGODB_USERNAME", "MONGODB_PASSWORD"} {
for _, v := range []string{"MONGODB_HOST", "MONGODB_USERNAME", "MONGODB_PASSWORD", "CLOUD_PROVIDER"} {
if os.Getenv(v) == "" {
log.Fatalf("the %s environment variable must be set", v)
}
Expand All @@ -77,9 +77,9 @@ func main() {
log.Fatal(err)
}

log.Infof("checking for cluster import secret for %s management cluster", os.Getenv("CLOUD_PROVIDER"))
log.Infof("checking for cluster import secret for management cluster")
// Import if needed
importedCluster, err := db.Client.ImportClusterIfEmpty(false)
importedCluster, err := db.Client.ImportClusterIfEmpty(false, os.Getenv("CLOUD_PROVIDER"))
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit f4e943e

Please sign in to comment.