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

Commit

Permalink
Merge pull request #108 from nabadger/feat-watch-ingress
Browse files Browse the repository at this point in the history
Add support for monitoring ingress events.
  • Loading branch information
tylerauerbeck committed May 19, 2018
2 parents 1ed4de8 + ac404a2 commit f121575
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ resource:
services: true
pod: true
secret: false
ingress: false
```

### Working with RBAC
Expand Down
9 changes: 9 additions & 0 deletions cmd/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ var resourceConfigCmd = &cobra.Command{
logrus.Fatal("secret", err)
}

b, err = cmd.Flags().GetBool("ing")
if err == nil {
conf.Resource.Ingress = b
} else {
logrus.Fatal("ing", err)
}


if err = conf.Write(); err != nil {
logrus.Fatal(err)
}
Expand All @@ -121,4 +129,5 @@ func init() {
resourceConfigCmd.Flags().Bool("jobs", false, "watch for jobs")
resourceConfigCmd.Flags().Bool("ds", false, "watch for daemonsets")
resourceConfigCmd.Flags().Bool("secret", false, "watch for plain secrets")
resourceConfigCmd.Flags().Bool("ing", false, "watch for ingresses")
}
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Resource struct {
PersistentVolume bool `json:"pv"`
Namespace bool `json:"ns"`
Secret bool `json:"secret"`
Ingress bool `json:"ing"`
}

// Config struct contains kubewatch configuration
Expand Down Expand Up @@ -168,6 +169,9 @@ func (c *Config) CheckMissingResourceEnvvars() {
if !c.Resource.Secret && os.Getenv("KW_SECRET") == "true" {
c.Resource.Secret = true
}
if !c.Resource.Ingress && os.Getenv("KW_INGRESS") == "true" {
c.Resource.Ingress = true
}
if (c.Handler.Slack.Channel == "") && (os.Getenv("SLACK_CHANNEL") != "") {
c.Handler.Slack.Channel = os.Getenv("SLACK_CHANNEL")
}
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var configStr = `
"services": "false",
"pod": "false",
"secret": "true",
"ingress": "false",
},
}
`
Expand Down
1 change: 1 addition & 0 deletions examples/conf/kubewatch.conf.flock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ resource:
pod: false
job: false
persistentvolume: false
ingress: false
1 change: 1 addition & 0 deletions examples/conf/kubewatch.conf.hipchat.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ resource:
pod: false
job: false
persistentvolume: false
ingress: false
1 change: 1 addition & 0 deletions examples/conf/kubewatch.conf.mattermost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ resource:
pod: false
job: false
persistentvolume: false
ingress: false
1 change: 1 addition & 0 deletions examples/conf/kubewatch.conf.webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ resource:
persistentvolume: false
namespace: true
secret: false
ingress: false
23 changes: 23 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,29 @@ func Start(conf *config.Config, eventHandler handlers.Handler) {
go c.Run(stopCh)
}

if conf.Resource.Ingress {
informer := cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options meta_v1.ListOptions) (runtime.Object, error) {
return kubeClient.ExtensionsV1beta1().Ingresses(meta_v1.NamespaceAll).List(options)
},
WatchFunc: func(options meta_v1.ListOptions) (watch.Interface, error) {
return kubeClient.ExtensionsV1beta1().Ingresses(meta_v1.NamespaceAll).Watch(options)
},
},
&ext_v1beta1.Ingress{},
0, //Skip resync
cache.Indexers{},
)

c := newResourceController(kubeClient, eventHandler, informer, "ingress")
stopCh := make(chan struct{})
defer close(stopCh)

go c.Run(stopCh)
}


sigterm := make(chan os.Signal, 1)
signal.Notify(sigterm, syscall.SIGTERM)
signal.Notify(sigterm, syscall.SIGINT)
Expand Down
2 changes: 2 additions & 0 deletions pkg/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ func New(obj interface{}, action string) Event {
kind = "job"
case *api_v1.Namespace:
kind = "namespace"
case *ext_v1beta1.Ingress:
kind = "ingress"
case *api_v1.PersistentVolume:
kind = "persistent volume"
case *api_v1.Pod:
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
apps_v1 "k8s.io/api/apps/v1"
batch_v1 "k8s.io/api/batch/v1"
api_v1 "k8s.io/api/core/v1"
ext_v1beta1 "k8s.io/api/extensions/v1beta1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -74,6 +75,8 @@ func GetObjectMetaData(obj interface{}) meta_v1.ObjectMeta {
objectMeta = object.ObjectMeta
case *api_v1.Secret:
objectMeta = object.ObjectMeta
case *ext_v1beta1.Ingress:
objectMeta = object.ObjectMeta
}
return objectMeta
}

0 comments on commit f121575

Please sign in to comment.