Skip to content

Commit

Permalink
fix entrypoint typo and add prom web server
Browse files Browse the repository at this point in the history
  • Loading branch information
gerrowadat committed Apr 12, 2024
1 parent bb499e0 commit f220b67
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ do
--cloud-dns-zone=$GCLOUD_DNS_ZONE \
--json-keyfile=$JSON_KEYFILE \
--nomad-server-uri=$NOMAD_SERVER_URI \
--nomad-token_file=$NOMAD_TOKEN_FILE \
--nomad-token-file=$NOMAD_TOKEN_FILE \
$GCLOUD_VERB
;;
getzonefile | putzonefile)
Expand Down
17 changes: 7 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"context"
"flag"
"fmt"
"io"
"log"
"net"
"net/http"
"os"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -68,6 +68,7 @@ func main() {
var nomadServerURI = flag.String("nomad-server-uri", "http://localhost:4646", "URI for a nomad server to talk to.")
var nomadTokenFile = flag.String("nomad-token-file", "", "file to read ou rnomad token from")
var nomadSyncInterval = flag.Int("nomad-sync-interval-secs", 300, "seconds between nomad updates. set to -1 to sync once only.")
var httpPort = flag.Int("http-port", 8080, "Port to listen on for /metrics")

// for dynrecord
var cloudDnsDynRecordName = flag.String("cloud-dns-dyn-record-name", "", "Cloud DNS record to update with our IP")
Expand Down Expand Up @@ -177,7 +178,6 @@ func main() {
log.Fatalf("Error Updating GCloud: %s", err)
}
case "nomad_sync":
http.Handle("/metrics", promhttp.Handler())
nomadSpec := &NomadSpec{
uri: *nomadServerURI,
}
Expand All @@ -191,15 +191,12 @@ func main() {
nomadSpec.token = ""
}

syncNomad(dns_spec, nomadSpec, pruneMissing)
http.Handle("/metrics", promhttp.Handler())

go periodicallySyncNomad(dns_spec, nomadSpec, *nomadSyncInterval, pruneMissing)

log.Fatal(http.ListenAndServe(":"+fmt.Sprintf("%v", *httpPort), nil))

if *nomadSyncInterval >= 0 {
for {
log.Printf("Waiting %d seconds.", *nomadSyncInterval)
time.Sleep(time.Duration(*nomadSyncInterval) * time.Second)
syncNomad(dns_spec, nomadSpec, pruneMissing)
}
}
default:
log.Fatal("Unknown verb: ", verb)
}
Expand Down
13 changes: 13 additions & 0 deletions nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"log"
"time"

nomad "github.com/hashicorp/nomad/api"
)
Expand All @@ -18,6 +19,18 @@ type NomadSpec struct {
token string
}

func periodicallySyncNomad(dns_spec *CloudDNSSpec, nomadSpec *NomadSpec, interval int, pruneMissing *bool) {
syncNomad(dns_spec, nomadSpec, pruneMissing)

if interval >= 0 {
for {
log.Printf("Waiting %d seconds.", interval)
time.Sleep(time.Duration(interval) * time.Second)
syncNomad(dns_spec, nomadSpec, pruneMissing)
}
}
}

func syncNomad(dnsSpec *CloudDNSSpec, nomadSpec *NomadSpec, pruneMissing *bool) {
//c := make(<-chan *dns.Change)
jobLocs := getNomadTaskLocations(nomadSpec)
Expand Down

0 comments on commit f220b67

Please sign in to comment.