Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
greetings
Browse files Browse the repository at this point in the history
  • Loading branch information
jnewland committed Aug 4, 2018
0 parents commit 5c2a7ea
Show file tree
Hide file tree
Showing 118 changed files with 31,353 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config/kubernetes/*/secrets/*.yaml
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM golang:alpine AS build

WORKDIR /go/src/github.com/urcomputeringpal/kubevalidator
COPY ./vendor ./vendor
RUN go install -v ./vendor/...
COPY . .
RUN go install -v github.com/urcomputeringpal/kubevalidator


FROM alpine
COPY --from=build /go/bin/kubevalidator /go/bin/kubevalidator
ENTRYPOINT ["/go/bin/kubevalidator"]
33 changes: 33 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"

[prune]
go-tests = true
non-go = true
unused-packages = true

[[override]]
name = "k8s.io/client-go"
version = "~7.0"

[[override]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.10.0"

[[constraint]]
branch = "master"
name = "github.com/google/go-github"

[[constraint]]
name = "github.com/bradleyfalzon/ghinstallation"
version = "0.1.2"
11 changes: 11 additions & 0 deletions config/kubernetes/default/configmaps/kubevalidator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: kubevalidator
namespace: kubevalidator
data:
# See https://github.com/milesp20/intel_nuc_led#usage
NUC_LED_READY: ring,09,none,green
NUC_LED_UNSCHEDULABLE: ring,50,fade_slow,yellow
NUC_LED_NOT_READY: ring,100,fade_slow,red
NUC_LED_ERROR: ring,100,blink_fast,red
23 changes: 23 additions & 0 deletions config/kubernetes/default/deployments/kubevalidator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kubevalidator
namespace: kubevalidator
spec:
replicas: 2
selector:
matchLabels:
app: kubevalidator
template:
metadata:
labels:
app: kubevalidator
spec:
containers:
- name: kubevalidator
image: gcr.io/rancho-de-newland/kubevalidator
envFrom:
- configMapRef:
name: kubevalidator
- secretRef:
name: kubevalidator
23 changes: 23 additions & 0 deletions config/kubernetes/default/ingresses/kubevalidator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/enable-cors: "true"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/ingress.class: nginx
kubernetes.io/tls-acme: "true"
name: kubevalidator
namespace: kubevalidator
spec:
rules:
- host: kubevalidator.k.jnewland.com
http:
paths:
- backend:
serviceName: kubevalidator
servicePort: 8080
path: /
tls:
- hosts:
- kubevalidator.k.jnewland.com
secretName: kubevalidator-tls
11 changes: 11 additions & 0 deletions config/kubernetes/default/services/kubevalidator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: kubevalidator
namespace: kubevalidator
spec:
ports:
- name: ui
port: 8080
selector:
app: kubevalidator
111 changes: 111 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package main

import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"

"github.com/bradleyfalzon/ghinstallation"
"github.com/google/go-github/github"
)

type kubevalidator struct {
Port int
WebhookSecretKey string
GitHubAppKeyFile string
GitHubAppID int
GitHubAppClient *github.Client
tr http.RoundTripper
ctx *context.Context
}

func (kv *kubevalidator) handle(w http.ResponseWriter, r *http.Request) {
payload, err := github.ValidatePayload(r, []byte(kv.WebhookSecretKey))
if err != nil {
log.Println(err)
return
}
defer r.Body.Close()

event, err := github.ParseWebHook(github.WebHookType(r), payload)
if err != nil {
log.Println(err)
return
}

switch e := event.(type) {
case *github.CheckSuiteEvent:
log.Printf("received %s\n", event)
return
default:
log.Printf("ignoring %s\n", e)
return
}
}

func (kv *kubevalidator) health(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "cool")
}

func runWithContext(ctx context.Context) error {
kv := kubevalidator{}
flag.IntVar(&kv.Port, "port", 8080, "port to listen on")
flag.StringVar(&kv.WebhookSecretKey, "webhook-secret", "", "webhook secret")
flag.StringVar(&kv.GitHubAppKeyFile, "github-app-key-file", "", "path to key file")
flag.IntVar(&kv.GitHubAppID, "github-app-id", -1, "app ID")
flag.Parse()
if len(flag.Args()) > 0 {
fmt.Printf("Unparsed arguments provided:\n\n%+v\n\n", flag.Args())
flag.Usage()
os.Exit(2)
}

itr, err := ghinstallation.NewAppsTransportKeyFromFile(kv.tr, kv.GitHubAppID, kv.GitHubAppKeyFile)
if err != nil {
return err
}

kv.ctx = &ctx
kv.tr = http.DefaultTransport
kv.GitHubAppClient = github.NewClient(&http.Client{Transport: itr})

http.HandleFunc("/webhook", kv.handle)
http.HandleFunc("/health", kv.health)
log.Println("hi")
return http.ListenAndServe(fmt.Sprintf(":%d", kv.Port), nil)
}

func cancelOnInterrupt(ctx context.Context, f context.CancelFunc) {
term := make(chan os.Signal)
signal.Notify(term, os.Interrupt, syscall.SIGTERM)

for {
select {
case <-term:
log.Println("Received SIGTERM, exiting gracefully...")
f()
os.Exit(0)
case <-ctx.Done():
os.Exit(0)
}
}
}

func run() error {
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
go cancelOnInterrupt(ctx, cancelFunc)

return runWithContext(ctx)
}

func main() {
if err := run(); err != nil && err != context.Canceled && err != context.DeadlineExceeded {
panic(err)
}
}
9 changes: 9 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: skaffold/v1alpha2
kind: Config
build:
artifacts:
- imageName: gcr.io/rancho-de-newland/kubevalidator
deploy:
kubectl:
manifests:
- config/kubernetes/default/**/*.yaml
24 changes: 24 additions & 0 deletions vendor/github.com/bradleyfalzon/ghinstallation/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c2a7ea

Please sign in to comment.