mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-20 19:29:10 +00:00
pkg,test,cmd: refactor operator code to generated client
This commit is contained in:
parent
bb048115a3
commit
3fdfcc7536
24 changed files with 121 additions and 117 deletions
cmd
pkg
alertmanager
api
k8sutil
prometheus
test
|
@ -29,7 +29,8 @@ import (
|
|||
|
||||
alertmanagercontroller "github.com/coreos/prometheus-operator/pkg/alertmanager"
|
||||
"github.com/coreos/prometheus-operator/pkg/api"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoring "github.com/coreos/prometheus-operator/pkg/apis/monitoring"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
prometheuscontroller "github.com/coreos/prometheus-operator/pkg/prometheus"
|
||||
"github.com/coreos/prometheus-operator/pkg/version"
|
||||
|
||||
|
@ -125,7 +126,7 @@ func init() {
|
|||
flagset.StringVar(&cfg.ThanosDefaultBaseImage, "thanos-default-base-image", "improbable/thanos", "Thanos default base image")
|
||||
flagset.Var(ns, "namespaces", "Namespaces to scope the interaction of the Prometheus Operator and the apiserver.")
|
||||
flagset.Var(&cfg.Labels, "labels", "Labels to be add to all resources created by the operator")
|
||||
flagset.StringVar(&cfg.CrdGroup, "crd-apigroup", monitoringv1.Group, "prometheus CRD API group name")
|
||||
flagset.StringVar(&cfg.CrdGroup, "crd-apigroup", monitoring.GroupName, "prometheus CRD API group name")
|
||||
flagset.Var(&cfg.CrdKinds, "crd-kinds", " - EXPERIMENTAL (could be removed in future releases) - customize CRD kind names")
|
||||
flagset.BoolVar(&cfg.EnableValidation, "with-validation", true, "Include the validation spec in the CRD")
|
||||
flagset.StringVar(&cfg.LocalHost, "localhost", "localhost", "EXPERIMENTAL (could be removed in future releases) - Host used to communicate between local services on a pod. Fixes issues where localhost resolves incorrectly.")
|
||||
|
|
|
@ -19,9 +19,11 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
crdutils "github.com/ant31/crd-validation/pkg"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoring "github.com/coreos/prometheus-operator/pkg/apis/monitoring"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
k8sutil "github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
|
||||
crdutils "github.com/ant31/crd-validation/pkg"
|
||||
extensionsobj "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
|
||||
)
|
||||
|
||||
|
@ -33,7 +35,7 @@ func initFlags(crdkind monitoringv1.CrdKind, flagset *flag.FlagSet) *flag.FlagSe
|
|||
flagset.Var(&cfg.Labels, "labels", "Labels")
|
||||
flagset.Var(&cfg.Annotations, "annotations", "Annotations")
|
||||
flagset.BoolVar(&cfg.EnableValidation, "with-validation", true, "Add CRD validation field, default: true")
|
||||
flagset.StringVar(&cfg.Group, "apigroup", monitoringv1.Group, "CRD api group")
|
||||
flagset.StringVar(&cfg.Group, "apigroup", monitoring.GroupName, "CRD api group")
|
||||
flagset.StringVar(&cfg.SpecDefinitionName, "spec-name", crdkind.SpecName, "CRD spec definition name")
|
||||
flagset.StringVar(&cfg.OutputFormat, "output", "yaml", "output format: json|yaml")
|
||||
flagset.StringVar(&cfg.Kind, "kind", crdkind.Kind, "CRD Kind")
|
||||
|
|
|
@ -23,7 +23,8 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoring "github.com/coreos/prometheus-operator/pkg/apis/monitoring"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
@ -106,7 +107,7 @@ func CMToRule(cm *v1.ConfigMap) ([]monitoringv1.PrometheusRule, error) {
|
|||
rule := monitoringv1.PrometheusRule{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: monitoringv1.PrometheusRuleKind,
|
||||
APIVersion: monitoringv1.Group + "/" + monitoringv1.Version,
|
||||
APIVersion: monitoring.GroupName + "/" + monitoringv1.Version,
|
||||
},
|
||||
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package alertmanager
|
||||
|
||||
import (
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
|
|
@ -20,8 +20,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
monitoringclient "github.com/coreos/prometheus-operator/pkg/client/versioned"
|
||||
"github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/coreos/prometheus-operator/pkg/listwatch"
|
||||
prometheusoperator "github.com/coreos/prometheus-operator/pkg/prometheus"
|
||||
|
@ -54,7 +54,7 @@ const (
|
|||
// monitoring configurations.
|
||||
type Operator struct {
|
||||
kclient kubernetes.Interface
|
||||
mclient monitoring.Interface
|
||||
mclient monitoringclient.Interface
|
||||
crdclient apiextensionsclient.Interface
|
||||
logger log.Logger
|
||||
|
||||
|
@ -94,7 +94,7 @@ func New(c prometheusoperator.Config, logger log.Logger) (*Operator, error) {
|
|||
return nil, errors.Wrap(err, "instantiating kubernetes client failed")
|
||||
}
|
||||
|
||||
mclient, err := monitoring.NewForConfig(&c.CrdKinds, c.CrdGroup, cfg)
|
||||
mclient, err := monitoringclient.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "instantiating monitoring client failed")
|
||||
}
|
||||
|
@ -127,7 +127,9 @@ func New(c prometheusoperator.Config, logger log.Logger) (*Operator, error) {
|
|||
o.alrtInf = cache.NewSharedIndexInformer(
|
||||
listwatch.MultiNamespaceListerWatcher(o.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{
|
||||
ListFunc: o.mclient.MonitoringV1().Alertmanagers(namespace).List,
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return o.mclient.MonitoringV1().Alertmanagers(namespace).List(options)
|
||||
},
|
||||
WatchFunc: o.mclient.MonitoringV1().Alertmanagers(namespace).Watch,
|
||||
}
|
||||
}),
|
||||
|
@ -439,6 +441,10 @@ func (c *Operator) sync(key string) error {
|
|||
}
|
||||
|
||||
am := obj.(*monitoringv1.Alertmanager)
|
||||
am = am.DeepCopy()
|
||||
am.APIVersion = monitoringv1.SchemeGroupVersion.String()
|
||||
am.Kind = monitoringv1.AlertmanagersKind
|
||||
|
||||
if am.Spec.Paused {
|
||||
return nil
|
||||
}
|
||||
|
@ -633,7 +639,11 @@ func (c *Operator) createCRDs() error {
|
|||
{
|
||||
"Alertmanager",
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{ListFunc: c.mclient.MonitoringV1().Alertmanagers(namespace).List}
|
||||
return &cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return c.mclient.MonitoringV1().Alertmanagers(namespace).List(options)
|
||||
},
|
||||
}
|
||||
}).List,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
"github.com/blang/semver"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
|
@ -20,34 +20,36 @@ import (
|
|||
"regexp"
|
||||
|
||||
"github.com/go-kit/kit/log"
|
||||
"github.com/pkg/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
monitoringclient "github.com/coreos/prometheus-operator/pkg/client/versioned"
|
||||
"github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/coreos/prometheus-operator/pkg/prometheus"
|
||||
)
|
||||
|
||||
type API struct {
|
||||
kclient *kubernetes.Clientset
|
||||
mclient *v1.MonitoringV1Client
|
||||
mclient monitoringclient.Interface
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func New(conf prometheus.Config, l log.Logger) (*API, error) {
|
||||
cfg, err := k8sutil.NewClusterConfig(conf.Host, conf.TLSInsecure, &conf.TLSConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "instantiating cluster config failed")
|
||||
}
|
||||
|
||||
kclient, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "instantiating kubernetes client failed")
|
||||
}
|
||||
|
||||
mclient, err := v1.NewForConfig(&conf.CrdKinds, conf.CrdGroup, cfg)
|
||||
mclient, err := monitoringclient.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "instantiating monitoring client failed")
|
||||
}
|
||||
|
||||
return &API{
|
||||
|
@ -96,7 +98,7 @@ func parsePrometheusStatusUrl(path string) objectReference {
|
|||
func (api *API) prometheusStatus(w http.ResponseWriter, req *http.Request) {
|
||||
or := parsePrometheusStatusUrl(req.URL.Path)
|
||||
|
||||
p, err := api.mclient.Prometheuses(or.namespace).Get(or.name, metav1.GetOptions{})
|
||||
p, err := api.mclient.MonitoringV1().Prometheuses(or.namespace).Get(or.name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
if k8sutil.IsResourceNotFoundError(err) {
|
||||
w.WriteHeader(404)
|
||||
|
|
|
@ -23,7 +23,7 @@ import (
|
|||
"time"
|
||||
|
||||
crdutils "github.com/ant31/crd-validation/pkg"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
version "github.com/hashicorp/go-version"
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/api/core/v1"
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
|
|
@ -21,8 +21,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
monitoringclient "github.com/coreos/prometheus-operator/pkg/client/versioned"
|
||||
"github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/coreos/prometheus-operator/pkg/listwatch"
|
||||
|
||||
|
@ -56,7 +56,7 @@ const (
|
|||
// monitoring configurations.
|
||||
type Operator struct {
|
||||
kclient kubernetes.Interface
|
||||
mclient monitoring.Interface
|
||||
mclient monitoringclient.Interface
|
||||
crdclient apiextensionsclient.Interface
|
||||
logger log.Logger
|
||||
|
||||
|
@ -158,16 +158,12 @@ type BasicAuthCredentials struct {
|
|||
func New(conf Config, logger log.Logger) (*Operator, error) {
|
||||
cfg, err := k8sutil.NewClusterConfig(conf.Host, conf.TLSInsecure, &conf.TLSConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "instantiating cluster config failed")
|
||||
}
|
||||
|
||||
mclient, err := monitoring.NewForConfig(&conf.CrdKinds, conf.CrdGroup, cfg)
|
||||
client, err := kubernetes.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "instantiating kubernetes client failed")
|
||||
}
|
||||
|
||||
crdclient, err := apiextensionsclient.NewForConfig(cfg)
|
||||
|
@ -175,6 +171,11 @@ func New(conf Config, logger log.Logger) (*Operator, error) {
|
|||
return nil, errors.Wrap(err, "instantiating apiextensions client failed")
|
||||
}
|
||||
|
||||
mclient, err := monitoringclient.NewForConfig(cfg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "instantiating monitoring client failed")
|
||||
}
|
||||
|
||||
kubeletObjectName := ""
|
||||
kubeletObjectNamespace := ""
|
||||
kubeletSyncEnabled := false
|
||||
|
@ -206,7 +207,9 @@ func New(conf Config, logger log.Logger) (*Operator, error) {
|
|||
c.promInf = cache.NewSharedIndexInformer(
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{
|
||||
ListFunc: mclient.MonitoringV1().Prometheuses(namespace).List,
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return mclient.MonitoringV1().Prometheuses(namespace).List(options)
|
||||
},
|
||||
WatchFunc: mclient.MonitoringV1().Prometheuses(namespace).Watch,
|
||||
}
|
||||
}),
|
||||
|
@ -216,7 +219,9 @@ func New(conf Config, logger log.Logger) (*Operator, error) {
|
|||
c.smonInf = cache.NewSharedIndexInformer(
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{
|
||||
ListFunc: mclient.MonitoringV1().ServiceMonitors(namespace).List,
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return mclient.MonitoringV1().ServiceMonitors(namespace).List(options)
|
||||
},
|
||||
WatchFunc: mclient.MonitoringV1().ServiceMonitors(namespace).Watch,
|
||||
}
|
||||
}),
|
||||
|
@ -226,7 +231,9 @@ func New(conf Config, logger log.Logger) (*Operator, error) {
|
|||
c.ruleInf = cache.NewSharedIndexInformer(
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{
|
||||
ListFunc: mclient.MonitoringV1().PrometheusRules(namespace).List,
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return mclient.MonitoringV1().PrometheusRules(namespace).List(options)
|
||||
},
|
||||
WatchFunc: mclient.MonitoringV1().PrometheusRules(namespace).Watch,
|
||||
}
|
||||
}),
|
||||
|
@ -948,6 +955,10 @@ func (c *Operator) sync(key string) error {
|
|||
}
|
||||
|
||||
p := obj.(*monitoringv1.Prometheus)
|
||||
p = p.DeepCopy()
|
||||
p.APIVersion = monitoringv1.SchemeGroupVersion.String()
|
||||
p.Kind = monitoringv1.PrometheusesKind
|
||||
|
||||
if p.Spec.Paused {
|
||||
return nil
|
||||
}
|
||||
|
@ -1422,21 +1433,33 @@ func (c *Operator) createCRDs() error {
|
|||
listFunc func(opts metav1.ListOptions) (runtime.Object, error)
|
||||
}{
|
||||
{
|
||||
"Prometheus",
|
||||
monitoringv1.PrometheusesKind,
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{ListFunc: c.mclient.MonitoringV1().Prometheuses(namespace).List}
|
||||
return &cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return c.mclient.MonitoringV1().Prometheuses(namespace).List(options)
|
||||
},
|
||||
}
|
||||
}).List,
|
||||
},
|
||||
{
|
||||
"ServiceMonitor",
|
||||
monitoringv1.ServiceMonitorsKind,
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{ListFunc: c.mclient.MonitoringV1().ServiceMonitors(namespace).List}
|
||||
return &cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return c.mclient.MonitoringV1().ServiceMonitors(namespace).List(options)
|
||||
},
|
||||
}
|
||||
}).List,
|
||||
},
|
||||
{
|
||||
"PrometheusRule",
|
||||
monitoringv1.PrometheusRuleKind,
|
||||
listwatch.MultiNamespaceListerWatcher(c.config.Namespaces, func(namespace string) cache.ListerWatcher {
|
||||
return &cache.ListWatch{ListFunc: c.mclient.MonitoringV1().PrometheusRules(namespace).List}
|
||||
return &cache.ListWatch{
|
||||
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
|
||||
return c.mclient.MonitoringV1().PrometheusRules(namespace).List(options)
|
||||
},
|
||||
}
|
||||
}).List,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"gopkg.in/yaml.v2"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
)
|
||||
|
|
|
@ -21,7 +21,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
)
|
||||
|
|
|
@ -27,7 +27,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
||||
"github.com/blang/semver"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
|
@ -19,7 +19,7 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/stretchr/testify/require"
|
||||
appsv1 "k8s.io/api/apps/v1beta2"
|
||||
"k8s.io/api/core/v1"
|
||||
|
|
|
@ -31,7 +31,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/alertmanager"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
testFramework "github.com/coreos/prometheus-operator/test/framework"
|
||||
)
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/alertmanager"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/prometheus"
|
||||
testFramework "github.com/coreos/prometheus-operator/test/framework"
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/alertmanager"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -59,17 +58,6 @@ func (f *Framework) MakeBasicAlertmanager(name string, replicas int32) *monitori
|
|||
}
|
||||
}
|
||||
|
||||
func (f *Framework) MakeBasicAlertmanagerV1alpha1(name string, replicas int32) *v1alpha1.Alertmanager {
|
||||
return &v1alpha1.Alertmanager{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: v1alpha1.AlertmanagerSpec{
|
||||
Replicas: &replicas,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Framework) MakeAlertmanagerService(name, group string, serviceType v1.ServiceType) *v1.Service {
|
||||
service := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
@ -25,23 +25,23 @@ import (
|
|||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/tools/clientcmd"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1alpha1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
|
||||
monitoringclient "github.com/coreos/prometheus-operator/pkg/client/versioned/typed/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/k8sutil"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Framework struct {
|
||||
KubeClient kubernetes.Interface
|
||||
MonClientV1 monitoringv1.MonitoringV1Interface
|
||||
MonClientV1alpha1 monitoringv1alpha1.MonitoringV1alpha1Interface
|
||||
HTTPClient *http.Client
|
||||
MasterHost string
|
||||
DefaultTimeout time.Duration
|
||||
KubeClient kubernetes.Interface
|
||||
MonClientV1 monitoringclient.MonitoringV1Interface
|
||||
HTTPClient *http.Client
|
||||
MasterHost string
|
||||
DefaultTimeout time.Duration
|
||||
}
|
||||
|
||||
// New setups a test framework and returns it.
|
||||
|
@ -61,23 +61,17 @@ func New(kubeconfig, opImage string) (*Framework, error) {
|
|||
return nil, errors.Wrap(err, "creating http-client failed")
|
||||
}
|
||||
|
||||
mClientV1, err := monitoringv1.NewForConfig(&monitoringv1.DefaultCrdKinds, monitoringv1.Group, config)
|
||||
mClientV1, err := monitoringclient.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating v1 monitoring client failed")
|
||||
}
|
||||
|
||||
mClientV1alpha1, err := monitoringv1alpha1.NewForConfig(config)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating v1alpha1 monitoring client failed")
|
||||
}
|
||||
|
||||
f := &Framework{
|
||||
MasterHost: config.Host,
|
||||
KubeClient: cli,
|
||||
MonClientV1: mClientV1,
|
||||
MonClientV1alpha1: mClientV1alpha1,
|
||||
HTTPClient: httpc,
|
||||
DefaultTimeout: time.Minute,
|
||||
MasterHost: config.Host,
|
||||
KubeClient: cli,
|
||||
MonClientV1: mClientV1,
|
||||
HTTPClient: httpc,
|
||||
DefaultTimeout: time.Minute,
|
||||
}
|
||||
|
||||
return f, nil
|
||||
|
@ -150,22 +144,30 @@ func (f *Framework) CreatePrometheusOperator(ns, opImage string, namespacesToWat
|
|||
return errors.Wrap(err, "failed to wait for prometheus operator to become ready")
|
||||
}
|
||||
|
||||
err = k8sutil.WaitForCRDReady(f.MonClientV1.Prometheuses(v1.NamespaceAll).List)
|
||||
err = k8sutil.WaitForCRDReady(func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return f.MonClientV1.Prometheuses(v1.NamespaceAll).List(opts)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Prometheus CRD not ready: %v\n")
|
||||
}
|
||||
|
||||
err = k8sutil.WaitForCRDReady(f.MonClientV1.ServiceMonitors(v1.NamespaceAll).List)
|
||||
err = k8sutil.WaitForCRDReady(func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return f.MonClientV1.ServiceMonitors(v1.NamespaceAll).List(opts)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "ServiceMonitor CRD not ready: %v\n")
|
||||
}
|
||||
|
||||
err = k8sutil.WaitForCRDReady(f.MonClientV1.PrometheusRules(v1.NamespaceAll).List)
|
||||
err = k8sutil.WaitForCRDReady(func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return f.MonClientV1.PrometheusRules(v1.NamespaceAll).List(opts)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "PrometheusRule CRD not ready: %v\n")
|
||||
}
|
||||
|
||||
err = k8sutil.WaitForCRDReady(f.MonClientV1.Alertmanagers(v1.NamespaceAll).List)
|
||||
err = k8sutil.WaitForCRDReady(func(opts metav1.ListOptions) (runtime.Object, error) {
|
||||
return f.MonClientV1.Alertmanagers(v1.NamespaceAll).List(opts)
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Alertmanager CRD not ready: %v\n")
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@ import (
|
|||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/prometheus"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -98,30 +97,6 @@ func (f *Framework) MakeBasicServiceMonitor(name string) *monitoringv1.ServiceMo
|
|||
}
|
||||
}
|
||||
|
||||
func (f *Framework) MakeBasicServiceMonitorV1alpha1(name string) *v1alpha1.ServiceMonitor {
|
||||
return &v1alpha1.ServiceMonitor{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
Labels: map[string]string{
|
||||
"group": name,
|
||||
},
|
||||
},
|
||||
Spec: v1alpha1.ServiceMonitorSpec{
|
||||
Selector: metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{
|
||||
"group": name,
|
||||
},
|
||||
},
|
||||
Endpoints: []v1alpha1.Endpoint{
|
||||
{
|
||||
Port: "web",
|
||||
Interval: "30s",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Framework) MakePrometheusService(name, group string, serviceType v1.ServiceType) *v1.Service {
|
||||
service := &v1.Service{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
"fmt"
|
||||
"time"
|
||||
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
|
||||
monitoringv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue