2018-06-27 07:45:32 -07:00
|
|
|
package kubernetes
|
|
|
|
|
|
|
|
|
|
import (
|
2020-03-30 11:10:41 -07:00
|
|
|
"context"
|
|
|
|
|
|
2018-10-09 21:56:09 +01:00
|
|
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2019-02-11 14:46:53 +00:00
|
|
|
"k8s.io/apimachinery/pkg/labels"
|
|
|
|
|
"k8s.io/apimachinery/pkg/watch"
|
|
|
|
|
"k8s.io/client-go/kubernetes"
|
2018-06-27 07:45:32 -07:00
|
|
|
)
|
|
|
|
|
|
2020-03-30 11:10:41 -07:00
|
|
|
func serviceWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
|
2019-02-11 14:46:53 +00:00
|
|
|
return func(options meta.ListOptions) (watch.Interface, error) {
|
|
|
|
|
if s != nil {
|
|
|
|
|
options.LabelSelector = s.String()
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
2020-03-30 11:10:41 -07:00
|
|
|
w, err := c.CoreV1().Services(ns).Watch(ctx, options)
|
2019-02-11 14:46:53 +00:00
|
|
|
return w, err
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 11:10:41 -07:00
|
|
|
func podWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
|
2019-02-11 14:46:53 +00:00
|
|
|
return func(options meta.ListOptions) (watch.Interface, error) {
|
|
|
|
|
if s != nil {
|
|
|
|
|
options.LabelSelector = s.String()
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
2019-05-29 08:06:46 +01:00
|
|
|
if len(options.FieldSelector) > 0 {
|
|
|
|
|
options.FieldSelector = options.FieldSelector + ","
|
|
|
|
|
}
|
|
|
|
|
options.FieldSelector = options.FieldSelector + "status.phase!=Succeeded,status.phase!=Failed,status.phase!=Unknown"
|
2020-03-30 11:10:41 -07:00
|
|
|
w, err := c.CoreV1().Pods(ns).Watch(ctx, options)
|
2019-02-11 14:46:53 +00:00
|
|
|
return w, err
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 11:10:41 -07:00
|
|
|
func endpointsWatchFunc(ctx context.Context, c kubernetes.Interface, ns string, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
|
2019-02-11 14:46:53 +00:00
|
|
|
return func(options meta.ListOptions) (watch.Interface, error) {
|
|
|
|
|
if s != nil {
|
|
|
|
|
options.LabelSelector = s.String()
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
2020-03-30 11:10:41 -07:00
|
|
|
w, err := c.CoreV1().Endpoints(ns).Watch(ctx, options)
|
2019-02-11 14:46:53 +00:00
|
|
|
return w, err
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 11:10:41 -07:00
|
|
|
func namespaceWatchFunc(ctx context.Context, c kubernetes.Interface, s labels.Selector) func(options meta.ListOptions) (watch.Interface, error) {
|
2019-02-11 14:46:53 +00:00
|
|
|
return func(options meta.ListOptions) (watch.Interface, error) {
|
|
|
|
|
if s != nil {
|
|
|
|
|
options.LabelSelector = s.String()
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
2020-03-30 11:10:41 -07:00
|
|
|
w, err := c.CoreV1().Namespaces().Watch(ctx, options)
|
2019-02-11 14:46:53 +00:00
|
|
|
return w, err
|
2018-10-09 21:56:09 +01:00
|
|
|
}
|
|
|
|
|
}
|