-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* support versioning * update comments * update alert config
- Loading branch information
Showing
13 changed files
with
114 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
FROM golang:alpine AS builder | ||
ARG RELEASE_VERSION="nothing" | ||
LABEL maintainer="Abdelrahman Ahmed <[email protected]" | ||
|
||
RUN apk update && \ | ||
|
@@ -11,6 +12,7 @@ COPY go.mod go.sum /build/ | |
RUN go mod download | ||
|
||
COPY . /build/ | ||
RUN sed -i '' -e 's/dev/'"${RELEASE_VERSION}"'/g' constant/constant.go | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a --installsuffix cgo --ldflags="-s" | ||
|
||
FROM alpine:latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
maxRecentLogLines: 0 | ||
providers: | ||
alert: | ||
slack: | ||
webhook: "" | ||
pagerduty: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package controller | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/abahmed/kwatch/client" | ||
"github.com/abahmed/kwatch/constant" | ||
"github.com/abahmed/kwatch/util" | ||
"github.com/sirupsen/logrus" | ||
v1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/watch" | ||
"k8s.io/client-go/tools/cache" | ||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
// Start creates an instance of controller after initialization and runs it | ||
func Start() { | ||
// create kubernetes client | ||
kclient := client.Create() | ||
|
||
// create rate limiting queue | ||
queue := | ||
workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()) | ||
|
||
indexer, informer := cache.NewIndexerInformer( | ||
&cache.ListWatch{ | ||
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) { | ||
return kclient.CoreV1(). | ||
Pods(v1.NamespaceAll). | ||
List(context.TODO(), opts) | ||
}, | ||
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) { | ||
return kclient.CoreV1(). | ||
Pods(v1.NamespaceAll). | ||
Watch(context.TODO(), opts) | ||
}, | ||
}, | ||
&v1.Pod{}, | ||
0, | ||
cache.ResourceEventHandlerFuncs{ | ||
AddFunc: func(obj interface{}) { | ||
key, err := cache.MetaNamespaceKeyFunc(obj) | ||
if err == nil { | ||
logrus.Debugf("received create for Pod %s\n", key) | ||
queue.Add(key) | ||
} | ||
}, | ||
UpdateFunc: func(old interface{}, new interface{}) { | ||
key, err := cache.MetaNamespaceKeyFunc(new) | ||
if err == nil { | ||
logrus.Debugf("received update for Pod %s\n", key) | ||
queue.Add(key) | ||
} | ||
}, | ||
DeleteFunc: func(obj interface{}) { | ||
// IndexerInformer uses a delta queue, therefore for deletes | ||
// we have to use this key function. | ||
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj) | ||
if err == nil { | ||
logrus.Debugf("received delete for Pod %s\n", key) | ||
queue.Add(key) | ||
} | ||
}, | ||
}, cache.Indexers{}) | ||
|
||
controller := Controller{ | ||
name: "pod-crash", | ||
informer: informer, | ||
indexer: indexer, | ||
queue: queue, | ||
kclient: kclient, | ||
providers: util.GetProviders(), | ||
} | ||
|
||
stopCh := make(chan struct{}) | ||
defer close(stopCh) | ||
|
||
controller.run(constant.NumWorkers, stopCh) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters