Skip to content

Commit

Permalink
optionalize ports, add README
Browse files Browse the repository at this point in the history
  • Loading branch information
rbren committed Mar 13, 2019
1 parent a3e5d60 commit b979380
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 7 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Build locally

```bash
git clone https://github.com/reactiveops/fairwinds $GOPATH/src/github.com/reactiveops/fairwinds
go build -a -o fairwinds *.go
./fairwinds -h
```

## Run on-cluster

On GKE, you'll need to run the following command first:
```
kubectl create clusterrolebinding cluster-admin-binding \
--clusterrole cluster-admin \
--user $(gcloud config get-value account)
```

Then apply the config:
```
kubectl apply -f deploy/all.yaml
```

## Options

* `dashboard` Runs the webserver for Fairwinds dashboard.
* `dashboard-port`: Port for the dashboard webserver (default 8080)
* `webhook`: Runs the webhook webserver.
* `webhook-port`: Port for the webhook webserver (default 9876)
* `disable-webhook-config-installer`: disable the installer in the webhook server, so it won't install webhook configuration resources during bootstrapping
* `kubeconfig`: Paths to a kubeconfig. Only required if out-of-cluster.
* `master`: The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.
25 changes: 18 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
glog "log"
"net/http"
"os"
"strconv"

conf "github.com/reactiveops/fairwinds/pkg/config"
"github.com/reactiveops/fairwinds/pkg/dashboard"
Expand All @@ -42,6 +43,8 @@ var log = logf.Log.WithName(FairwindsName)
func main() {
dashboard := flag.Bool("dashboard", false, "Runs the webserver for Fairwinds dashboard.")
webhook := flag.Bool("webhook", false, "Runs the webhook webserver.")
dashboardPort := flag.Int("dashboard-port", 8080, "Port for the dashboard webserver")
webhookPort := flag.Int("webhook-port", 9876, "Port for the webhook webserver")

var disableWebhookConfigInstaller bool
flag.BoolVar(&disableWebhookConfigInstaller, "disable-webhook-config-installer", false,
Expand All @@ -56,15 +59,20 @@ func main() {
}

if *webhook {
startWebhookServer(c, disableWebhookConfigInstaller)
startWebhookServer(c, disableWebhookConfigInstaller, *webhookPort)
}

if *dashboard {
startDashboardServer(c)
startDashboardServer(c, *dashboardPort)
}

if !*dashboard && !*webhook {
glog.Println("Must specify either -webhook, -dashboard, or both")
os.Exit(1)
}
}

func startDashboardServer(c conf.Configuration) {
func startDashboardServer(c conf.Configuration, port int) {
k, _ := kube.CreateKubeAPI()
http.HandleFunc("/results.json", func(w http.ResponseWriter, r *http.Request) {
dashboard.EndpointHandler(w, r, c, k)
Expand All @@ -77,11 +85,12 @@ func startDashboardServer(c conf.Configuration) {
}
dashboard.MainHandler(w, r, c, k)
})
glog.Println("Starting Fairwinds dashboard server on port 8080.")
glog.Fatal(http.ListenAndServe(":8080", nil))
portStr := strconv.Itoa(port)
glog.Println("Starting Fairwinds dashboard server on port " + portStr)
glog.Fatal(http.ListenAndServe(":" + portStr, nil))
}

func startWebhookServer(c conf.Configuration, disableWebhookConfigInstaller bool) {
func startWebhookServer(c conf.Configuration, disableWebhookConfigInstaller bool, port int) {
logf.SetLogger(logf.ZapLogger(false))
entryLog := log.WithName("entrypoint")

Expand All @@ -95,7 +104,7 @@ func startWebhookServer(c conf.Configuration, disableWebhookConfigInstaller bool

entryLog.Info("setting up webhook server")
as, err := webhook.NewServer(FairwindsName, mgr, webhook.ServerOptions{
Port: 9876,
Port: int32(port),
CertDir: "/tmp/cert",
DisableWebhookConfigInstaller: &disableWebhookConfigInstaller,
BootstrapOptions: &webhook.BootstrapOptions{
Expand All @@ -119,6 +128,8 @@ func startWebhookServer(c conf.Configuration, disableWebhookConfigInstaller bool
if err != nil {
entryLog.Error(err, "unable to create a new webhook server")
os.Exit(1)
} else {
glog.Println("Fairwinds webhook server listening on port " + strconv.Itoa(port))
}

p := validator.NewWebhook("pod", mgr, validator.Validator{Config: c}, &corev1.Pod{})
Expand Down

0 comments on commit b979380

Please sign in to comment.