-
Notifications
You must be signed in to change notification settings - Fork 445
Conversation
ngtuna
commented
Jul 13, 2017
- use client-go v3.0
- use apimachinery
- remove k8s/kubernetes
- refactor controller loop
@@ -44,39 +44,39 @@ var m = map[string]string{ | |||
// New create new KubewatchEvent | |||
func New(obj interface{}, action string) Event { | |||
var namespace, kind, component, host, reason, status, name string | |||
if apiService, ok := obj.(*api.Service); ok { | |||
if apiService, ok := obj.(*v1.Service); ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch.
import (
"fmt"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
)
func New(obj runtime.Object, action string) Event {
meta, err := meta.Accessor(obj)
if err != nil {
panic(fmt.Sprintf("Object has no meta? %s", err)
}
namespace := meta.GetNamespace()
name := meta.GetName()
kind := strings.ToLower(obj.GetObjectKind().GroupVersionKind().Kind)
reason := action
status := m[action]
// .. then do something like the current typeswitch that *just* sets host+component
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Gus. That duplicated codes have been there for a year since I had limited knowledge about k8s. Will update it!
} | ||
|
||
logrus.Fatal(http.ListenAndServe(":8081", nil)) | ||
//if conf.Resource.Services { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
left over debugging?
} | ||
|
||
// | ||
//func watchServices(client *client.Client, eventHandler handlers.Handler) cache.Store { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the plan for all this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There will be separate controller for each resource. I only use one for Pod in this PR mostly for showing use-case for the 2nd part of the blogpost. I will cover the rest in another PR