Skip to content

Commit

Permalink
Merge pull request #187 from kubefirst/logformat
Browse files Browse the repository at this point in the history
add logging formatter
  • Loading branch information
johndietz authored Oct 9, 2023
2 parents 4eadc45 + 23d9837 commit 59fde1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions internal/db/mongo.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (mdbcl *MongoDBClient) TestDatabaseConnection(silent bool) error {
// ImportClusterIfEmpty
func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool, cloudProvider string) error {

log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
TimestampFormat: "",
})
log.SetReportCaller(false)

// find the secret in mgmt cluster's kubefirst namespace and read import payload and clustername
var kcfg *k8s.KubernetesClient

Expand All @@ -109,12 +115,12 @@ func (mdbcl *MongoDBClient) ImportClusterIfEmpty(silent bool, cloudProvider stri
log.Infof("reading secret mongo-state to determine if import is needed")
secData, err := k8s.ReadSecretV2(kcfg.Clientset, "kubefirst", "mongodb-state")
if err != nil {
log.Infof("error reading secret mongodb-state. %s", err)
return err
}
clusterName := secData["cluster-name"]
importPayload := secData["cluster-0"]

log.Infof("import secret discovered for cluster %s", clusterName)
log.Infof("import cluster secret discovered for cluster %s", clusterName)

// if you find a record bail
// otherwise read the payload, import to db, bail
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ func main() {
Tries: 20,
Silent: false,
})

if err != nil {
log.Fatal(err)
}

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

0 comments on commit 59fde1e

Please sign in to comment.