Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Refactor watcher #61

Merged
merged 2 commits into from
Jul 13, 2017
Merged

Refactor watcher #61

merged 2 commits into from
Jul 13, 2017

Conversation

ngtuna
Copy link
Contributor

@ngtuna ngtuna commented Jul 13, 2017

  • use client-go v3.0
  • use apimachinery
  • remove k8s/kubernetes
  • refactor controller loop

@ngtuna ngtuna merged commit 4ac16d6 into vmware-archive:master Jul 13, 2017
@@ -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 {

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
}

Copy link
Contributor Author

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 {

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 {

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?

Copy link
Contributor Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants