This repository has been archived by the owner on Apr 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kubeconfig can be passed via flag Closes #9
- Loading branch information
Showing
8 changed files
with
182 additions
and
46 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,59 @@ | ||
package kube | ||
|
||
import ( | ||
"log" | ||
|
||
"k8s.io/api/core/v1" | ||
log "github.com/inconshreveable/log15" | ||
"k8s.io/client-go/pkg/api/v1" | ||
) | ||
|
||
type Event int | ||
|
||
const ( | ||
NewPodEvent Event = iota | ||
UpdatePodEvent | ||
DeletePodEvent | ||
) | ||
|
||
func emitEvent(eChan chan Event, e Event) func(obj interface{}) { | ||
func onAdd(events chan Event) func(obj interface{}) { | ||
funclog := log.New("func", "onAdd") | ||
return func(obj interface{}) { | ||
pod, ok := obj.(*v1.Pod) | ||
if !ok { | ||
funclog.Error("unable to assert type") | ||
return | ||
} | ||
events <- NewPodEvent | ||
funclog.Info(pod.ObjectMeta.SelfLink) | ||
} | ||
} | ||
|
||
func onUpdate(events chan Event) func(oldObj, newObj interface{}) { | ||
// funclog := log.New("func", "onUpdate") | ||
return func(oldObj, newObj interface{}) { | ||
// do nothing | ||
return | ||
// oldPod, ok := oldObj.(*v1.Pod) | ||
// if !ok { | ||
// funclog.Error("unable to assert type") | ||
// return | ||
// } | ||
// newPod, ok := newObj.(*v1.Pod) | ||
// if !ok { | ||
// funclog.Error("unable to assert type") | ||
// return | ||
// } | ||
// funclog.Info(fmt.Sprintf("old: %s, new: %s", oldPod.ObjectMeta.SelfLink, newPod.ObjectMeta.SelfLink)) | ||
} | ||
} | ||
|
||
func onDelete(events chan Event) func(obj interface{}) { | ||
funclog := log.New("func", "onDelete") | ||
return func(obj interface{}) { | ||
_, ok := obj.(*v1.Pod) | ||
pod, ok := obj.(*v1.Pod) | ||
if !ok { | ||
log.Printf("unexpected object type: %#v\n", obj) | ||
funclog.Error("unable to assert type") | ||
return | ||
} | ||
eChan <- e | ||
events <- DeletePodEvent | ||
funclog.Info(pod.ObjectMeta.SelfLink) | ||
} | ||
} |
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