mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
*: ensure using crdgroup flag in monitoring client
This commit is contained in:
parent
ee32a18080
commit
2f582be7c4
11 changed files with 27 additions and 27 deletions
Documentation/user-guides
contrib/kube-prometheus/manifests/node-exporter
pkg
alertmanager
api
client/monitoring
migrator
prometheus
test/framework
|
@ -138,7 +138,7 @@ spec:
|
|||
hostNetwork: true
|
||||
hostPID: true
|
||||
containers:
|
||||
- image: quay.io/prometheus/node-exporter:v0.15.0
|
||||
- image: quay.io/prometheus/node-exporter:v0.15.0
|
||||
args:
|
||||
- "--path.procfs=/host/proc"
|
||||
- "--path.sysfs=/host/sys"
|
||||
|
|
|
@ -12,7 +12,7 @@ spec:
|
|||
hostNetwork: true
|
||||
hostPID: true
|
||||
containers:
|
||||
- image: quay.io/prometheus/node-exporter:v0.15.0
|
||||
- image: quay.io/prometheus/node-exporter:v0.15.0
|
||||
args:
|
||||
- "--path.procfs=/host/proc"
|
||||
- "--path.sysfs=/host/sys"
|
||||
|
|
|
@ -84,7 +84,7 @@ func New(c prometheusoperator.Config, logger log.Logger) (*Operator, error) {
|
|||
return nil, errors.Wrap(err, "instantiating kubernetes client failed")
|
||||
}
|
||||
|
||||
mclient, err := monitoring.NewForConfig(cfg)
|
||||
mclient, err := monitoring.NewForConfig(c.CrdGroup, cfg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "instantiating monitoring client failed")
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func New(conf prometheus.Config, l log.Logger) (*API, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
mclient, err := v1.NewForConfig(cfg)
|
||||
mclient, err := v1.NewForConfig(conf.CrdGroup, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func (c *Clientset) MonitoringV1() v1.MonitoringV1Interface {
|
|||
return c.MonitoringV1Client
|
||||
}
|
||||
|
||||
func NewForConfig(c *rest.Config) (*Clientset, error) {
|
||||
func NewForConfig(apiGroup string, c *rest.Config) (*Clientset, error) {
|
||||
configShallowCopy := *c
|
||||
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
|
||||
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
|
||||
|
@ -61,7 +61,7 @@ func NewForConfig(c *rest.Config) (*Clientset, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cs.MonitoringV1Client, err = v1.NewForConfig(&configShallowCopy)
|
||||
cs.MonitoringV1Client, err = v1.NewForConfig(apiGroup, &configShallowCopy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -56,9 +56,9 @@ func (c *MonitoringV1Client) RESTClient() rest.Interface {
|
|||
return c.restClient
|
||||
}
|
||||
|
||||
func NewForConfig(c *rest.Config) (*MonitoringV1Client, error) {
|
||||
func NewForConfig(apiGroup string, c *rest.Config) (*MonitoringV1Client, error) {
|
||||
config := *c
|
||||
SetConfigDefaults(&config)
|
||||
SetConfigDefaults(apiGroup, &config)
|
||||
client, err := rest.RESTClientFor(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -72,9 +72,9 @@ func NewForConfig(c *rest.Config) (*MonitoringV1Client, error) {
|
|||
return &MonitoringV1Client{client, dynamicClient}, nil
|
||||
}
|
||||
|
||||
func SetConfigDefaults(config *rest.Config) {
|
||||
func SetConfigDefaults(apiGroup string, config *rest.Config) {
|
||||
config.GroupVersion = &schema.GroupVersion{
|
||||
Group: Group,
|
||||
Group: apiGroup,
|
||||
Version: Version,
|
||||
}
|
||||
config.APIPath = "/apis"
|
||||
|
|
|
@ -118,7 +118,7 @@ func NewMigrator(cfg *rest.Config, logger log.Logger) (*Migrator, error) {
|
|||
return nil, errors.Wrap(err, "creating kubernetes client")
|
||||
}
|
||||
|
||||
mclient, err := monitoring.NewForConfig(cfg)
|
||||
mclient, err := monitoring.NewForConfig(monitoringv1.Group, cfg)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating monitoring client")
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ func New(conf Config, logger log.Logger) (*Operator, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
mclient, err := monitoring.NewForConfig(cfg)
|
||||
mclient, err := monitoring.NewForConfig(conf.CrdGroup, cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
rbacv1alpha1 "k8s.io/client-go/pkg/apis/rbac/v1alpha1"
|
||||
rbacv1beta1 "k8s.io/client-go/pkg/apis/rbac/v1beta1"
|
||||
)
|
||||
|
||||
func CreateClusterRole(kubeClient kubernetes.Interface, relativePath string) error {
|
||||
|
@ -27,18 +27,18 @@ func CreateClusterRole(kubeClient kubernetes.Interface, relativePath string) err
|
|||
return err
|
||||
}
|
||||
|
||||
_, err = kubeClient.RbacV1alpha1().ClusterRoles().Get(clusterRole.Name, metav1.GetOptions{})
|
||||
_, err = kubeClient.RbacV1beta1().ClusterRoles().Get(clusterRole.Name, metav1.GetOptions{})
|
||||
|
||||
if err == nil {
|
||||
// ClusterRole already exists -> Update
|
||||
_, err = kubeClient.RbacV1alpha1().ClusterRoles().Update(clusterRole)
|
||||
_, err = kubeClient.RbacV1beta1().ClusterRoles().Update(clusterRole)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
} else {
|
||||
// ClusterRole doesn't exists -> Create
|
||||
_, err = kubeClient.RbacV1alpha1().ClusterRoles().Create(clusterRole)
|
||||
_, err = kubeClient.RbacV1beta1().ClusterRoles().Create(clusterRole)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -53,20 +53,20 @@ func DeleteClusterRole(kubeClient kubernetes.Interface, relativePath string) err
|
|||
return err
|
||||
}
|
||||
|
||||
if err := kubeClient.RbacV1alpha1().ClusterRoles().Delete(clusterRole.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
if err := kubeClient.RbacV1beta1().ClusterRoles().Delete(clusterRole.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseClusterRoleYaml(relativePath string) (*rbacv1alpha1.ClusterRole, error) {
|
||||
func parseClusterRoleYaml(relativePath string) (*rbacv1beta1.ClusterRole, error) {
|
||||
manifest, err := PathToOSFile(relativePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clusterRole := rbacv1alpha1.ClusterRole{}
|
||||
clusterRole := rbacv1beta1.ClusterRole{}
|
||||
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&clusterRole); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/yaml"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
rbacv1alpha1 "k8s.io/client-go/pkg/apis/rbac/v1alpha1"
|
||||
rbacv1beta1 "k8s.io/client-go/pkg/apis/rbac/v1beta1"
|
||||
)
|
||||
|
||||
func CreateClusterRoleBinding(kubeClient kubernetes.Interface, ns string, relativePath string) (finalizerFn, error) {
|
||||
|
@ -30,17 +30,17 @@ func CreateClusterRoleBinding(kubeClient kubernetes.Interface, ns string, relati
|
|||
|
||||
clusterRoleBinding.Subjects[0].Namespace = ns
|
||||
|
||||
_, err = kubeClient.RbacV1alpha1().ClusterRoleBindings().Get(clusterRoleBinding.Name, metav1.GetOptions{})
|
||||
_, err = kubeClient.RbacV1beta1().ClusterRoleBindings().Get(clusterRoleBinding.Name, metav1.GetOptions{})
|
||||
|
||||
if err == nil {
|
||||
// ClusterRoleBinding already exists -> Update
|
||||
_, err = kubeClient.RbacV1alpha1().ClusterRoleBindings().Update(clusterRoleBinding)
|
||||
_, err = kubeClient.RbacV1beta1().ClusterRoleBindings().Update(clusterRoleBinding)
|
||||
if err != nil {
|
||||
return finalizerFn, err
|
||||
}
|
||||
} else {
|
||||
// ClusterRoleBinding doesn't exists -> Create
|
||||
_, err = kubeClient.RbacV1alpha1().ClusterRoleBindings().Create(clusterRoleBinding)
|
||||
_, err = kubeClient.RbacV1beta1().ClusterRoleBindings().Create(clusterRoleBinding)
|
||||
if err != nil {
|
||||
return finalizerFn, err
|
||||
}
|
||||
|
@ -55,20 +55,20 @@ func DeleteClusterRoleBinding(kubeClient kubernetes.Interface, relativePath stri
|
|||
return err
|
||||
}
|
||||
|
||||
if err := kubeClient.RbacV1alpha1().ClusterRoleBindings().Delete(clusterRoleBinding.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
if err := kubeClient.RbacV1beta1().ClusterRoleBindings().Delete(clusterRoleBinding.Name, &metav1.DeleteOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseClusterRoleBindingYaml(relativePath string) (*rbacv1alpha1.ClusterRoleBinding, error) {
|
||||
func parseClusterRoleBindingYaml(relativePath string) (*rbacv1beta1.ClusterRoleBinding, error) {
|
||||
manifest, err := PathToOSFile(relativePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clusterRoleBinding := rbacv1alpha1.ClusterRoleBinding{}
|
||||
clusterRoleBinding := rbacv1beta1.ClusterRoleBinding{}
|
||||
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&clusterRoleBinding); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ func New(ns, kubeconfig, opImage string) (*Framework, error) {
|
|||
return nil, errors.Wrap(err, "creating http-client failed")
|
||||
}
|
||||
|
||||
mclient, err := monitoringv1.NewForConfig(config)
|
||||
mclient, err := monitoringv1.NewForConfig(monitoringv1.Group, config)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "creating monitoring client failed")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue