mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-16 09:16:38 +00:00
Add option to customize CRD Kinds
This commit is contained in:
parent
f11e1b9fe4
commit
d9e94acdb4
13 changed files with 116 additions and 46 deletions
|
@ -59,6 +59,7 @@ func init() {
|
||||||
flagset.StringVar(&cfg.Namespace, "namespace", kapi.NamespaceAll, "Namespace to scope the interaction of the Prometheus Operator and the apiserver.")
|
flagset.StringVar(&cfg.Namespace, "namespace", kapi.NamespaceAll, "Namespace 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.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", monitoringv1.Group, "prometheus CRD API group name")
|
||||||
|
flagset.Var(&cfg.CrdKinds, "crd-kinds", " - EXPERIMENTAL (could be removed in future releases) - customize CRD kind names")
|
||||||
flagset.Parse(os.Args[1:])
|
flagset.Parse(os.Args[1:])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,7 @@ type Config struct {
|
||||||
AlertmanagerDefaultBaseImage string
|
AlertmanagerDefaultBaseImage string
|
||||||
Namespace string
|
Namespace string
|
||||||
Labels prometheusoperator.Labels
|
Labels prometheusoperator.Labels
|
||||||
|
CrdKinds monitoringv1.CrdKinds
|
||||||
CrdGroup string
|
CrdGroup string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +85,7 @@ func New(c prometheusoperator.Config, logger log.Logger) (*Operator, error) {
|
||||||
return nil, errors.Wrap(err, "instantiating kubernetes client failed")
|
return nil, errors.Wrap(err, "instantiating kubernetes client failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
mclient, err := monitoring.NewForConfig(c.CrdGroup, cfg)
|
mclient, err := monitoring.NewForConfig(&c.CrdKinds, c.CrdGroup, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "instantiating monitoring client failed")
|
return nil, errors.Wrap(err, "instantiating monitoring client failed")
|
||||||
}
|
}
|
||||||
|
@ -106,6 +107,7 @@ func New(c prometheusoperator.Config, logger log.Logger) (*Operator, error) {
|
||||||
AlertmanagerDefaultBaseImage: c.AlertmanagerDefaultBaseImage,
|
AlertmanagerDefaultBaseImage: c.AlertmanagerDefaultBaseImage,
|
||||||
Namespace: c.Namespace,
|
Namespace: c.Namespace,
|
||||||
CrdGroup: c.CrdGroup,
|
CrdGroup: c.CrdGroup,
|
||||||
|
CrdKinds: c.CrdKinds,
|
||||||
Labels: c.Labels,
|
Labels: c.Labels,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -524,7 +526,7 @@ func (c *Operator) createCRDs() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
crds := []*extensionsobj.CustomResourceDefinition{
|
crds := []*extensionsobj.CustomResourceDefinition{
|
||||||
k8sutil.NewAlertmanagerCustomResourceDefinition(c.config.CrdGroup, c.config.Labels.LabelsMap),
|
k8sutil.NewAlertmanagerCustomResourceDefinition(c.config.CrdKinds.Alertmanager, c.config.CrdGroup, c.config.Labels.LabelsMap),
|
||||||
}
|
}
|
||||||
|
|
||||||
crdClient := c.crdclient.ApiextensionsV1beta1().CustomResourceDefinitions()
|
crdClient := c.crdclient.ApiextensionsV1beta1().CustomResourceDefinitions()
|
||||||
|
|
|
@ -45,7 +45,7 @@ func New(conf prometheus.Config, l log.Logger) (*API, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mclient, err := v1.NewForConfig(conf.CrdGroup, cfg)
|
mclient, err := v1.NewForConfig(&conf.CrdKinds, conf.CrdGroup, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (c *Clientset) MonitoringV1() v1.MonitoringV1Interface {
|
||||||
return c.MonitoringV1Client
|
return c.MonitoringV1Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewForConfig(apiGroup string, c *rest.Config) (*Clientset, error) {
|
func NewForConfig(crdKinds *v1.CrdKinds, apiGroup string, c *rest.Config) (*Clientset, error) {
|
||||||
configShallowCopy := *c
|
configShallowCopy := *c
|
||||||
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
|
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
|
||||||
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
|
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
|
||||||
|
@ -61,7 +61,7 @@ func NewForConfig(apiGroup string, c *rest.Config) (*Clientset, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.MonitoringV1Client, err = v1.NewForConfig(apiGroup, &configShallowCopy)
|
cs.MonitoringV1Client, err = v1.NewForConfig(crdKinds, apiGroup, &configShallowCopy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,13 +54,13 @@ type alertmanagers struct {
|
||||||
ns string
|
ns string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAlertmanagers(r rest.Interface, c *dynamic.Client, namespace string) *alertmanagers {
|
func newAlertmanagers(r rest.Interface, c *dynamic.Client, crdKind CrdKind, namespace string) *alertmanagers {
|
||||||
return &alertmanagers{
|
return &alertmanagers{
|
||||||
r,
|
r,
|
||||||
c.Resource(
|
c.Resource(
|
||||||
&metav1.APIResource{
|
&metav1.APIResource{
|
||||||
Kind: AlertmanagersKind,
|
Kind: crdKind.Kind,
|
||||||
Name: AlertmanagerName,
|
Name: crdKind.Plural,
|
||||||
Namespaced: true,
|
Namespaced: true,
|
||||||
},
|
},
|
||||||
namespace,
|
namespace,
|
||||||
|
|
|
@ -15,17 +15,75 @@
|
||||||
package v1
|
package v1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/runtime/serializer"
|
"k8s.io/apimachinery/pkg/runtime/serializer"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
"k8s.io/client-go/pkg/api"
|
"k8s.io/client-go/pkg/api"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Group = "monitoring.coreos.com"
|
Group = "monitoring.coreos.com"
|
||||||
|
PrometheusKindKey = "prometheus"
|
||||||
|
AlertManagerKindKey = "alermanager"
|
||||||
|
ServiceMonitorKindKey = "servicemonitor"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CrdKind struct {
|
||||||
|
Kind string
|
||||||
|
Plural string
|
||||||
|
}
|
||||||
|
|
||||||
|
type CrdKinds struct {
|
||||||
|
KindsString string
|
||||||
|
Prometheus CrdKind
|
||||||
|
Alertmanager CrdKind
|
||||||
|
ServiceMonitor CrdKind
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement the flag.Value interface
|
||||||
|
func (crdkinds *CrdKinds) String() string {
|
||||||
|
return crdkinds.KindsString
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Implement the flag.Set interface
|
||||||
|
func (crdkinds *CrdKinds) Set(value string) error {
|
||||||
|
if value == "" {
|
||||||
|
value = fmt.Sprintf("%s=%s:%s,%s=%s:%s,%s=%s:%s",
|
||||||
|
PrometheusKindKey, PrometheusesKind, PrometheusName,
|
||||||
|
AlertManagerKindKey, AlertmanagersKind, AlertmanagerName,
|
||||||
|
ServiceMonitorKindKey, ServiceMonitorsKind, ServiceMonitorName)
|
||||||
|
}
|
||||||
|
splited := strings.Split(value, ",")
|
||||||
|
for _, pair := range splited {
|
||||||
|
sp := strings.Split(pair, "=")
|
||||||
|
kind := strings.Split(sp[1], ":")
|
||||||
|
crdKind := CrdKind{Plural: kind[1], Kind: kind[0]}
|
||||||
|
switch kindKey := sp[0]; kindKey {
|
||||||
|
case PrometheusKindKey:
|
||||||
|
(*crdkinds).Prometheus = crdKind
|
||||||
|
case ServiceMonitorKindKey:
|
||||||
|
(*crdkinds).ServiceMonitor = crdKind
|
||||||
|
case AlertManagerKindKey:
|
||||||
|
(*crdkinds).Alertmanager = crdKind
|
||||||
|
default:
|
||||||
|
fmt.Printf("Warning: unknown kind: %s... ignoring", kindKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
(*crdkinds).KindsString = value
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var DefaultCrdKinds CrdKinds = CrdKinds{
|
||||||
|
KindsString: "",
|
||||||
|
Prometheus: CrdKind{Plural: PrometheusName, Kind: PrometheusesKind},
|
||||||
|
ServiceMonitor: CrdKind{Plural: ServiceMonitorName, Kind: ServiceMonitorsKind},
|
||||||
|
Alertmanager: CrdKind{Plural: AlertmanagerName, Kind: AlertmanagersKind},
|
||||||
|
}
|
||||||
|
|
||||||
var Version = "v1"
|
var Version = "v1"
|
||||||
|
|
||||||
type MonitoringV1Interface interface {
|
type MonitoringV1Interface interface {
|
||||||
|
@ -38,25 +96,26 @@ type MonitoringV1Interface interface {
|
||||||
type MonitoringV1Client struct {
|
type MonitoringV1Client struct {
|
||||||
restClient rest.Interface
|
restClient rest.Interface
|
||||||
dynamicClient *dynamic.Client
|
dynamicClient *dynamic.Client
|
||||||
|
crdKinds *CrdKinds
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MonitoringV1Client) Prometheuses(namespace string) PrometheusInterface {
|
func (c *MonitoringV1Client) Prometheuses(namespace string) PrometheusInterface {
|
||||||
return newPrometheuses(c.restClient, c.dynamicClient, namespace)
|
return newPrometheuses(c.restClient, c.dynamicClient, c.crdKinds.Prometheus, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MonitoringV1Client) Alertmanagers(namespace string) AlertmanagerInterface {
|
func (c *MonitoringV1Client) Alertmanagers(namespace string) AlertmanagerInterface {
|
||||||
return newAlertmanagers(c.restClient, c.dynamicClient, namespace)
|
return newAlertmanagers(c.restClient, c.dynamicClient, c.crdKinds.Alertmanager, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MonitoringV1Client) ServiceMonitors(namespace string) ServiceMonitorInterface {
|
func (c *MonitoringV1Client) ServiceMonitors(namespace string) ServiceMonitorInterface {
|
||||||
return newServiceMonitors(c.restClient, c.dynamicClient, namespace)
|
return newServiceMonitors(c.restClient, c.dynamicClient, c.crdKinds.ServiceMonitor, namespace)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MonitoringV1Client) RESTClient() rest.Interface {
|
func (c *MonitoringV1Client) RESTClient() rest.Interface {
|
||||||
return c.restClient
|
return c.restClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewForConfig(apiGroup string, c *rest.Config) (*MonitoringV1Client, error) {
|
func NewForConfig(crdKinds *CrdKinds, apiGroup string, c *rest.Config) (*MonitoringV1Client, error) {
|
||||||
config := *c
|
config := *c
|
||||||
SetConfigDefaults(apiGroup, &config)
|
SetConfigDefaults(apiGroup, &config)
|
||||||
client, err := rest.RESTClientFor(&config)
|
client, err := rest.RESTClientFor(&config)
|
||||||
|
@ -69,7 +128,7 @@ func NewForConfig(apiGroup string, c *rest.Config) (*MonitoringV1Client, error)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &MonitoringV1Client{client, dynamicClient}, nil
|
return &MonitoringV1Client{client, dynamicClient, crdKinds}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetConfigDefaults(apiGroup string, config *rest.Config) {
|
func SetConfigDefaults(apiGroup string, config *rest.Config) {
|
||||||
|
|
|
@ -54,13 +54,13 @@ type prometheuses struct {
|
||||||
ns string
|
ns string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPrometheuses(r rest.Interface, c *dynamic.Client, namespace string) *prometheuses {
|
func newPrometheuses(r rest.Interface, c *dynamic.Client, crdKind CrdKind, namespace string) *prometheuses {
|
||||||
return &prometheuses{
|
return &prometheuses{
|
||||||
r,
|
r,
|
||||||
c.Resource(
|
c.Resource(
|
||||||
&metav1.APIResource{
|
&metav1.APIResource{
|
||||||
Kind: PrometheusesKind,
|
Kind: crdKind.Kind,
|
||||||
Name: PrometheusName,
|
Name: crdKind.Plural,
|
||||||
Namespaced: true,
|
Namespaced: true,
|
||||||
},
|
},
|
||||||
namespace,
|
namespace,
|
||||||
|
|
|
@ -54,13 +54,13 @@ type servicemonitors struct {
|
||||||
ns string
|
ns string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newServiceMonitors(r rest.Interface, c *dynamic.Client, namespace string) *servicemonitors {
|
func newServiceMonitors(r rest.Interface, c *dynamic.Client, crdKind CrdKind, namespace string) *servicemonitors {
|
||||||
return &servicemonitors{
|
return &servicemonitors{
|
||||||
r,
|
r,
|
||||||
c.Resource(
|
c.Resource(
|
||||||
&metav1.APIResource{
|
&metav1.APIResource{
|
||||||
Kind: ServiceMonitorsKind,
|
Kind: crdKind.Kind,
|
||||||
Name: ServiceMonitorName,
|
Name: crdKind.Plural,
|
||||||
Namespaced: true,
|
Namespaced: true,
|
||||||
},
|
},
|
||||||
namespace,
|
namespace,
|
||||||
|
|
|
@ -205,10 +205,10 @@ func NewAlertmanagerTPRDefinition() *extensionsobjold.ThirdPartyResource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPrometheusCustomResourceDefinition(group string, labels map[string]string) *extensionsobj.CustomResourceDefinition {
|
func NewPrometheusCustomResourceDefinition(crdkind monitoringv1.CrdKind, group string, labels map[string]string) *extensionsobj.CustomResourceDefinition {
|
||||||
return &extensionsobj.CustomResourceDefinition{
|
return &extensionsobj.CustomResourceDefinition{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: monitoringv1.PrometheusName + "." + group,
|
Name: crdkind.Plural + "." + group,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: extensionsobj.CustomResourceDefinitionSpec{
|
Spec: extensionsobj.CustomResourceDefinitionSpec{
|
||||||
|
@ -216,35 +216,36 @@ func NewPrometheusCustomResourceDefinition(group string, labels map[string]strin
|
||||||
Version: monitoringv1.Version,
|
Version: monitoringv1.Version,
|
||||||
Scope: extensionsobj.NamespaceScoped,
|
Scope: extensionsobj.NamespaceScoped,
|
||||||
Names: extensionsobj.CustomResourceDefinitionNames{
|
Names: extensionsobj.CustomResourceDefinitionNames{
|
||||||
Plural: monitoringv1.PrometheusName,
|
Plural: crdkind.Plural,
|
||||||
Kind: monitoringv1.PrometheusesKind,
|
Kind: crdkind.Kind,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceMonitorCustomResourceDefinition(group string, labels map[string]string) *extensionsobj.CustomResourceDefinition {
|
func NewServiceMonitorCustomResourceDefinition(crdkind monitoringv1.CrdKind, group string, labels map[string]string) *extensionsobj.CustomResourceDefinition {
|
||||||
return &extensionsobj.CustomResourceDefinition{
|
return &extensionsobj.CustomResourceDefinition{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: monitoringv1.ServiceMonitorName + "." + group,
|
Name: crdkind.Plural + "." + group,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
|
|
||||||
Spec: extensionsobj.CustomResourceDefinitionSpec{
|
Spec: extensionsobj.CustomResourceDefinitionSpec{
|
||||||
Group: group,
|
Group: group,
|
||||||
Version: monitoringv1.Version,
|
Version: monitoringv1.Version,
|
||||||
Scope: extensionsobj.NamespaceScoped,
|
Scope: extensionsobj.NamespaceScoped,
|
||||||
Names: extensionsobj.CustomResourceDefinitionNames{
|
Names: extensionsobj.CustomResourceDefinitionNames{
|
||||||
Plural: monitoringv1.ServiceMonitorName,
|
Plural: crdkind.Plural,
|
||||||
Kind: monitoringv1.ServiceMonitorsKind,
|
Kind: crdkind.Kind,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAlertmanagerCustomResourceDefinition(group string, labels map[string]string) *extensionsobj.CustomResourceDefinition {
|
func NewAlertmanagerCustomResourceDefinition(crdkind monitoringv1.CrdKind, group string, labels map[string]string) *extensionsobj.CustomResourceDefinition {
|
||||||
return &extensionsobj.CustomResourceDefinition{
|
return &extensionsobj.CustomResourceDefinition{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: monitoringv1.AlertmanagerName + "." + group,
|
Name: crdkind.Plural + "." + group,
|
||||||
Labels: labels,
|
Labels: labels,
|
||||||
},
|
},
|
||||||
Spec: extensionsobj.CustomResourceDefinitionSpec{
|
Spec: extensionsobj.CustomResourceDefinitionSpec{
|
||||||
|
@ -252,8 +253,8 @@ func NewAlertmanagerCustomResourceDefinition(group string, labels map[string]str
|
||||||
Version: monitoringv1.Version,
|
Version: monitoringv1.Version,
|
||||||
Scope: extensionsobj.NamespaceScoped,
|
Scope: extensionsobj.NamespaceScoped,
|
||||||
Names: extensionsobj.CustomResourceDefinitionNames{
|
Names: extensionsobj.CustomResourceDefinitionNames{
|
||||||
Plural: monitoringv1.AlertmanagerName,
|
Plural: crdkind.Plural,
|
||||||
Kind: monitoringv1.AlertmanagersKind,
|
Kind: crdkind.Kind,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ func NewMigrator(cfg *rest.Config, logger log.Logger) (*Migrator, error) {
|
||||||
return nil, errors.Wrap(err, "creating kubernetes client")
|
return nil, errors.Wrap(err, "creating kubernetes client")
|
||||||
}
|
}
|
||||||
|
|
||||||
mclient, err := monitoring.NewForConfig(monitoringv1.Group, cfg)
|
mclient, err := monitoring.NewForConfig(&monitoringv1.DefaultCrdKinds, monitoringv1.Group, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "creating monitoring client")
|
return nil, errors.Wrap(err, "creating monitoring client")
|
||||||
}
|
}
|
||||||
|
@ -179,9 +179,15 @@ func (m *Migrator) migrateTPR2CRD() error {
|
||||||
|
|
||||||
m.logger.Log("msg", "Creating CRDs.")
|
m.logger.Log("msg", "Creating CRDs.")
|
||||||
err = m.createCRDs(
|
err = m.createCRDs(
|
||||||
k8sutil.NewPrometheusCustomResourceDefinition(monitoringv1.Group, map[string]string{}),
|
k8sutil.NewPrometheusCustomResourceDefinition(
|
||||||
k8sutil.NewServiceMonitorCustomResourceDefinition(monitoringv1.Group, map[string]string{}),
|
monitoringv1.DefaultCrdKinds.Prometheus,
|
||||||
k8sutil.NewAlertmanagerCustomResourceDefinition(monitoringv1.Group, map[string]string{}),
|
monitoringv1.Group, map[string]string{}),
|
||||||
|
k8sutil.NewServiceMonitorCustomResourceDefinition(
|
||||||
|
monitoringv1.DefaultCrdKinds.ServiceMonitor,
|
||||||
|
monitoringv1.Group, map[string]string{}),
|
||||||
|
k8sutil.NewAlertmanagerCustomResourceDefinition(
|
||||||
|
monitoringv1.DefaultCrdKinds.Alertmanager,
|
||||||
|
monitoringv1.Group, map[string]string{}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "creating CRDs failed")
|
return errors.Wrap(err, "creating CRDs failed")
|
||||||
|
@ -507,9 +513,9 @@ func (m *Migrator) rollback() error {
|
||||||
if ms.crdCreated {
|
if ms.crdCreated {
|
||||||
m.logger.Log("msg", "Deleting CRDs.")
|
m.logger.Log("msg", "Deleting CRDs.")
|
||||||
err := m.deleteCRDs(
|
err := m.deleteCRDs(
|
||||||
k8sutil.NewPrometheusCustomResourceDefinition(monitoringv1.Group, map[string]string{}),
|
k8sutil.NewPrometheusCustomResourceDefinition(monitoringv1.DefaultCrdKinds.Prometheus, monitoringv1.Group, map[string]string{}),
|
||||||
k8sutil.NewServiceMonitorCustomResourceDefinition(monitoringv1.Group, map[string]string{}),
|
k8sutil.NewServiceMonitorCustomResourceDefinition(monitoringv1.DefaultCrdKinds.ServiceMonitor, monitoringv1.Group, map[string]string{}),
|
||||||
k8sutil.NewAlertmanagerCustomResourceDefinition(monitoringv1.Group, map[string]string{}),
|
k8sutil.NewAlertmanagerCustomResourceDefinition(monitoringv1.DefaultCrdKinds.Alertmanager, monitoringv1.Group, map[string]string{}),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "deleting the CRDs failed")
|
return errors.Wrapf(err, "deleting the CRDs failed")
|
||||||
|
|
|
@ -125,6 +125,7 @@ type Config struct {
|
||||||
Namespace string
|
Namespace string
|
||||||
Labels Labels
|
Labels Labels
|
||||||
CrdGroup string
|
CrdGroup string
|
||||||
|
CrdKinds monitoringv1.CrdKinds
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicAuthCredentials struct {
|
type BasicAuthCredentials struct {
|
||||||
|
@ -143,7 +144,7 @@ func New(conf Config, logger log.Logger) (*Operator, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
mclient, err := monitoring.NewForConfig(conf.CrdGroup, cfg)
|
mclient, err := monitoring.NewForConfig(&conf.CrdKinds, conf.CrdGroup, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1021,8 +1022,8 @@ func (c *Operator) createCRDs() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
crds := []*extensionsobj.CustomResourceDefinition{
|
crds := []*extensionsobj.CustomResourceDefinition{
|
||||||
k8sutil.NewPrometheusCustomResourceDefinition(c.config.CrdGroup, c.config.Labels.LabelsMap),
|
k8sutil.NewPrometheusCustomResourceDefinition(c.config.CrdKinds.Prometheus, c.config.CrdGroup, c.config.Labels.LabelsMap),
|
||||||
k8sutil.NewServiceMonitorCustomResourceDefinition(c.config.CrdGroup, c.config.Labels.LabelsMap),
|
k8sutil.NewServiceMonitorCustomResourceDefinition(c.config.CrdKinds.ServiceMonitor, c.config.CrdGroup, c.config.Labels.LabelsMap),
|
||||||
}
|
}
|
||||||
|
|
||||||
crdClient := c.crdclient.ApiextensionsV1beta1().CustomResourceDefinitions()
|
crdClient := c.crdclient.ApiextensionsV1beta1().CustomResourceDefinitions()
|
||||||
|
|
|
@ -59,7 +59,7 @@ func New(ns, kubeconfig, opImage string) (*Framework, error) {
|
||||||
return nil, errors.Wrap(err, "creating http-client failed")
|
return nil, errors.Wrap(err, "creating http-client failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
mclient, err := monitoringv1.NewForConfig(monitoringv1.Group, config)
|
mclient, err := monitoringv1.NewForConfig(&monitoringv1.DefaultCrdKinds, monitoringv1.Group, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "creating monitoring client failed")
|
return nil, errors.Wrap(err, "creating monitoring client failed")
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,7 +238,7 @@ func checkMigrationDone(ns2 string, framework *operatorFramework.Framework, tprC
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if CRDs are created.
|
// Check if CRDs are created.
|
||||||
_, err = crdClient.Get(k8sutil.NewPrometheusCustomResourceDefinition(monitoringv1.Group, map[string]string{}).Name, metav1.GetOptions{})
|
_, err = crdClient.Get(k8sutil.NewPrometheusCustomResourceDefinition(monitoringv1.DefaultCrdKinds.Prometheus, monitoringv1.Group, map[string]string{}).Name, metav1.GetOptions{})
|
||||||
if err != nil && apierrors.IsNotFound(err) {
|
if err != nil && apierrors.IsNotFound(err) {
|
||||||
fmt.Println("Expected Prometheus CRD definition to be created, but it does not exists.")
|
fmt.Println("Expected Prometheus CRD definition to be created, but it does not exists.")
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -247,7 +247,7 @@ func checkMigrationDone(ns2 string, framework *operatorFramework.Framework, tprC
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = crdClient.Get(k8sutil.NewAlertmanagerCustomResourceDefinition(monitoringv1.Group, map[string]string{}).Name, metav1.GetOptions{})
|
_, err = crdClient.Get(k8sutil.NewAlertmanagerCustomResourceDefinition(monitoringv1.DefaultCrdKinds.Alertmanager, monitoringv1.Group, map[string]string{}).Name, metav1.GetOptions{})
|
||||||
if err != nil && apierrors.IsNotFound(err) {
|
if err != nil && apierrors.IsNotFound(err) {
|
||||||
fmt.Println("Expected Alertmanager CRD definition to be created, but it does not exists.")
|
fmt.Println("Expected Alertmanager CRD definition to be created, but it does not exists.")
|
||||||
return false, nil
|
return false, nil
|
||||||
|
@ -256,7 +256,7 @@ func checkMigrationDone(ns2 string, framework *operatorFramework.Framework, tprC
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = crdClient.Get(k8sutil.NewServiceMonitorCustomResourceDefinition(monitoringv1.Group, map[string]string{}).Name, metav1.GetOptions{})
|
_, err = crdClient.Get(k8sutil.NewServiceMonitorCustomResourceDefinition(monitoringv1.DefaultCrdKinds.ServiceMonitor, monitoringv1.Group, map[string]string{}).Name, metav1.GetOptions{})
|
||||||
if err != nil && apierrors.IsNotFound(err) {
|
if err != nil && apierrors.IsNotFound(err) {
|
||||||
fmt.Println("Expected ServiceMonitor CRD definition to be created, but it does not exists.")
|
fmt.Println("Expected ServiceMonitor CRD definition to be created, but it does not exists.")
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
Loading…
Add table
Reference in a new issue