1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-21 03:38:43 +00:00

client: introduce v1 client

This commit is contained in:
Frederic Branczyk 2017-08-22 12:53:35 +02:00
parent c4b5ce649a
commit c6d98a2a97
No known key found for this signature in database
GPG key ID: 7741A52782A90069
10 changed files with 1113 additions and 3 deletions

View file

@ -0,0 +1,56 @@
package monitoring
import (
"k8s.io/client-go/rest"
"k8s.io/client-go/util/flowcontrol"
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1"
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
)
var _ Interface = &Clientset{}
type Interface interface {
MonitoringV1alpha1() v1alpha1.MonitoringV1alpha1Interface
MonitoringV1() v1.MonitoringV1Interface
}
type Clientset struct {
*v1alpha1.MonitoringV1alpha1Client
*v1.MonitoringV1Client
}
func (c *Clientset) MonitoringV1alpha1() v1alpha1.MonitoringV1alpha1Interface {
if c == nil {
return nil
}
return c.MonitoringV1alpha1Client
}
func (c *Clientset) MonitoringV1() v1.MonitoringV1Interface {
if c == nil {
return nil
}
return c.MonitoringV1Client
}
func NewForConfig(c *rest.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.MonitoringV1alpha1Client, err = v1alpha1.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.MonitoringV1Client, err = v1.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
return &cs, nil
}

View file

@ -0,0 +1,203 @@
// Copyright 2016 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
"encoding/json"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
)
const (
AlertmanagersKind = "Alertmanager"
AlertmanagerName = "alertmanagers"
)
type AlertmanagersGetter interface {
Alertmanagers(namespace string) AlertmanagerInterface
}
var _ AlertmanagerInterface = &alertmanagers{}
type AlertmanagerInterface interface {
Create(*Alertmanager) (*Alertmanager, error)
Get(name string, opts metav1.GetOptions) (*Alertmanager, error)
Update(*Alertmanager) (*Alertmanager, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error
}
type alertmanagers struct {
restClient rest.Interface
client *dynamic.ResourceClient
ns string
}
func newAlertmanagers(r rest.Interface, c *dynamic.Client, namespace string) *alertmanagers {
return &alertmanagers{
r,
c.Resource(
&metav1.APIResource{
Kind: AlertmanagersKind,
Name: AlertmanagerName,
Namespaced: true,
},
namespace,
),
namespace,
}
}
func (a *alertmanagers) Create(o *Alertmanager) (*Alertmanager, error) {
ua, err := UnstructuredFromAlertmanager(o)
if err != nil {
return nil, err
}
ua, err = a.client.Create(ua)
if err != nil {
return nil, err
}
return AlertmanagerFromUnstructured(ua)
}
func (a *alertmanagers) Get(name string, opts metav1.GetOptions) (*Alertmanager, error) {
obj, err := a.client.Get(name, opts)
if err != nil {
return nil, err
}
return AlertmanagerFromUnstructured(obj)
}
func (a *alertmanagers) Update(o *Alertmanager) (*Alertmanager, error) {
ua, err := UnstructuredFromAlertmanager(o)
if err != nil {
return nil, err
}
cura, err := a.Get(o.Name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, "unable to get current version for update")
}
ua.SetResourceVersion(cura.ObjectMeta.ResourceVersion)
ua, err = a.client.Update(ua)
if err != nil {
return nil, err
}
return AlertmanagerFromUnstructured(ua)
}
func (a *alertmanagers) Delete(name string, options *metav1.DeleteOptions) error {
return a.client.Delete(name, options)
}
func (a *alertmanagers) List(opts metav1.ListOptions) (runtime.Object, error) {
req := a.restClient.Get().
Namespace(a.ns).
Resource("alertmanagers").
// VersionedParams(&options, api.ParameterCodec)
FieldsSelectorParam(nil)
b, err := req.DoRaw()
if err != nil {
return nil, err
}
var p AlertmanagerList
return &p, json.Unmarshal(b, &p)
}
func (a *alertmanagers) Watch(opts metav1.ListOptions) (watch.Interface, error) {
r, err := a.restClient.Get().
Prefix("watch").
Namespace(a.ns).
Resource("alertmanagers").
// VersionedParams(&options, api.ParameterCodec).
FieldsSelectorParam(nil).
Stream()
if err != nil {
return nil, err
}
return watch.NewStreamWatcher(&alertmanagerDecoder{
dec: json.NewDecoder(r),
close: r.Close,
}), nil
}
func (a *alertmanagers) DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error {
return a.client.DeleteCollection(dopts, lopts)
}
// AlertmanagerFromUnstructured unmarshals an Alertmanager object from dynamic client's unstructured
func AlertmanagerFromUnstructured(r *unstructured.Unstructured) (*Alertmanager, error) {
b, err := json.Marshal(r.Object)
if err != nil {
return nil, err
}
var a Alertmanager
if err := json.Unmarshal(b, &a); err != nil {
return nil, err
}
a.TypeMeta.Kind = AlertmanagersKind
a.TypeMeta.APIVersion = Group + "/" + Version
return &a, nil
}
// UnstructuredFromAlertmanager marshals an Alertmanager object into dynamic client's unstructured
func UnstructuredFromAlertmanager(a *Alertmanager) (*unstructured.Unstructured, error) {
a.TypeMeta.Kind = AlertmanagersKind
a.TypeMeta.APIVersion = Group + "/" + Version
b, err := json.Marshal(a)
if err != nil {
return nil, err
}
var r unstructured.Unstructured
if err := json.Unmarshal(b, &r.Object); err != nil {
return nil, err
}
return &r, nil
}
type alertmanagerDecoder struct {
dec *json.Decoder
close func() error
}
func (d *alertmanagerDecoder) Close() {
d.close()
}
func (d *alertmanagerDecoder) Decode() (action watch.EventType, object runtime.Object, err error) {
var e struct {
Type watch.EventType
Object Alertmanager
}
if err := d.dec.Decode(&e); err != nil {
return watch.Error, nil, err
}
return e.Type, &e.Object, nil
}

View file

@ -0,0 +1,83 @@
// Copyright 2016 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/pkg/api"
"k8s.io/client-go/rest"
)
const (
Group = "monitoring.coreos.com"
)
var Version = "v1"
type MonitoringV1Interface interface {
RESTClient() rest.Interface
PrometheusesGetter
AlertmanagersGetter
ServiceMonitorsGetter
}
type MonitoringV1Client struct {
restClient rest.Interface
dynamicClient *dynamic.Client
}
func (c *MonitoringV1Client) Prometheuses(namespace string) PrometheusInterface {
return newPrometheuses(c.restClient, c.dynamicClient, namespace)
}
func (c *MonitoringV1Client) Alertmanagers(namespace string) AlertmanagerInterface {
return newAlertmanagers(c.restClient, c.dynamicClient, namespace)
}
func (c *MonitoringV1Client) ServiceMonitors(namespace string) ServiceMonitorInterface {
return newServiceMonitors(c.restClient, c.dynamicClient, namespace)
}
func (c *MonitoringV1Client) RESTClient() rest.Interface {
return c.restClient
}
func NewForConfig(c *rest.Config) (*MonitoringV1Client, error) {
config := *c
SetConfigDefaults(&config)
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, err
}
dynamicClient, err := dynamic.NewClient(&config)
if err != nil {
return nil, err
}
return &MonitoringV1Client{client, dynamicClient}, nil
}
func SetConfigDefaults(config *rest.Config) {
config.GroupVersion = &schema.GroupVersion{
Group: Group,
Version: Version,
}
config.APIPath = "/apis"
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: api.Codecs}
return
}

View file

@ -0,0 +1,202 @@
// Copyright 2016 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
"encoding/json"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
)
const (
PrometheusesKind = "Prometheus"
PrometheusName = "prometheuses"
)
type PrometheusesGetter interface {
Prometheuses(namespace string) PrometheusInterface
}
var _ PrometheusInterface = &prometheuses{}
type PrometheusInterface interface {
Create(*Prometheus) (*Prometheus, error)
Get(name string, opts metav1.GetOptions) (*Prometheus, error)
Update(*Prometheus) (*Prometheus, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error
}
type prometheuses struct {
restClient rest.Interface
client *dynamic.ResourceClient
ns string
}
func newPrometheuses(r rest.Interface, c *dynamic.Client, namespace string) *prometheuses {
return &prometheuses{
r,
c.Resource(
&metav1.APIResource{
Kind: PrometheusesKind,
Name: PrometheusName,
Namespaced: true,
},
namespace,
),
namespace,
}
}
func (p *prometheuses) Create(o *Prometheus) (*Prometheus, error) {
up, err := UnstructuredFromPrometheus(o)
if err != nil {
return nil, err
}
up, err = p.client.Create(up)
if err != nil {
return nil, err
}
return PrometheusFromUnstructured(up)
}
func (p *prometheuses) Get(name string, opts metav1.GetOptions) (*Prometheus, error) {
obj, err := p.client.Get(name, opts)
if err != nil {
return nil, err
}
return PrometheusFromUnstructured(obj)
}
func (p *prometheuses) Update(o *Prometheus) (*Prometheus, error) {
up, err := UnstructuredFromPrometheus(o)
if err != nil {
return nil, err
}
curp, err := p.Get(o.Name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, "unable to get current version for update")
}
up.SetResourceVersion(curp.ObjectMeta.ResourceVersion)
up, err = p.client.Update(up)
if err != nil {
return nil, err
}
return PrometheusFromUnstructured(up)
}
func (p *prometheuses) Delete(name string, options *metav1.DeleteOptions) error {
return p.client.Delete(name, options)
}
func (p *prometheuses) List(opts metav1.ListOptions) (runtime.Object, error) {
req := p.restClient.Get().
Namespace(p.ns).
Resource("prometheuses").
// VersionedParams(&options, v1.ParameterCodec)
FieldsSelectorParam(nil)
b, err := req.DoRaw()
if err != nil {
return nil, err
}
var prom PrometheusList
return &prom, json.Unmarshal(b, &prom)
}
func (p *prometheuses) Watch(opts metav1.ListOptions) (watch.Interface, error) {
r, err := p.restClient.Get().
Prefix("watch").
Namespace(p.ns).
Resource("prometheuses").
// VersionedParams(&options, v1.ParameterCodec).
FieldsSelectorParam(nil).
Stream()
if err != nil {
return nil, err
}
return watch.NewStreamWatcher(&prometheusDecoder{
dec: json.NewDecoder(r),
close: r.Close,
}), nil
}
func (p *prometheuses) DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error {
return p.client.DeleteCollection(dopts, lopts)
}
// PrometheusFromUnstructured unmarshals a Prometheus object from dynamic client's unstructured
func PrometheusFromUnstructured(r *unstructured.Unstructured) (*Prometheus, error) {
b, err := json.Marshal(r.Object)
if err != nil {
return nil, err
}
var p Prometheus
if err := json.Unmarshal(b, &p); err != nil {
return nil, err
}
p.TypeMeta.Kind = PrometheusesKind
p.TypeMeta.APIVersion = Group + "/" + Version
return &p, nil
}
// UnstructuredFromPrometheus marshals a Prometheus object into dynamic client's unstructured
func UnstructuredFromPrometheus(p *Prometheus) (*unstructured.Unstructured, error) {
p.TypeMeta.Kind = PrometheusesKind
p.TypeMeta.APIVersion = Group + "/" + Version
b, err := json.Marshal(p)
if err != nil {
return nil, err
}
var r unstructured.Unstructured
if err := json.Unmarshal(b, &r.Object); err != nil {
return nil, err
}
return &r, nil
}
type prometheusDecoder struct {
dec *json.Decoder
close func() error
}
func (d *prometheusDecoder) Close() {
d.close()
}
func (d *prometheusDecoder) Decode() (action watch.EventType, object runtime.Object, err error) {
var e struct {
Type watch.EventType
Object Prometheus
}
if err := d.dec.Decode(&e); err != nil {
return watch.Error, nil, err
}
return e.Type, &e.Object, nil
}

View file

@ -0,0 +1,202 @@
// Copyright 2016 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
"encoding/json"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/rest"
)
const (
ServiceMonitorsKind = "ServiceMonitor"
ServiceMonitorName = "servicemonitors"
)
type ServiceMonitorsGetter interface {
ServiceMonitors(namespace string) ServiceMonitorInterface
}
var _ ServiceMonitorInterface = &servicemonitors{}
type ServiceMonitorInterface interface {
Create(*ServiceMonitor) (*ServiceMonitor, error)
Get(name string, opts metav1.GetOptions) (*ServiceMonitor, error)
Update(*ServiceMonitor) (*ServiceMonitor, error)
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error
}
type servicemonitors struct {
restClient rest.Interface
client *dynamic.ResourceClient
ns string
}
func newServiceMonitors(r rest.Interface, c *dynamic.Client, namespace string) *servicemonitors {
return &servicemonitors{
r,
c.Resource(
&metav1.APIResource{
Kind: ServiceMonitorsKind,
Name: ServiceMonitorName,
Namespaced: true,
},
namespace,
),
namespace,
}
}
func (s *servicemonitors) Create(o *ServiceMonitor) (*ServiceMonitor, error) {
us, err := UnstructuredFromServiceMonitor(o)
if err != nil {
return nil, err
}
us, err = s.client.Create(us)
if err != nil {
return nil, err
}
return ServiceMonitorFromUnstructured(us)
}
func (s *servicemonitors) Get(name string, opts metav1.GetOptions) (*ServiceMonitor, error) {
obj, err := s.client.Get(name, opts)
if err != nil {
return nil, err
}
return ServiceMonitorFromUnstructured(obj)
}
func (s *servicemonitors) Update(o *ServiceMonitor) (*ServiceMonitor, error) {
us, err := UnstructuredFromServiceMonitor(o)
if err != nil {
return nil, err
}
curs, err := s.Get(o.Name, metav1.GetOptions{})
if err != nil {
return nil, errors.Wrap(err, "unable to get current version for update")
}
us.SetResourceVersion(curs.ObjectMeta.ResourceVersion)
us, err = s.client.Update(us)
if err != nil {
return nil, err
}
return ServiceMonitorFromUnstructured(us)
}
func (s *servicemonitors) Delete(name string, options *metav1.DeleteOptions) error {
return s.client.Delete(name, options)
}
func (s *servicemonitors) List(opts metav1.ListOptions) (runtime.Object, error) {
req := s.restClient.Get().
Namespace(s.ns).
Resource("servicemonitors").
// VersionedParams(&options, v1.ParameterCodec)
FieldsSelectorParam(nil)
b, err := req.DoRaw()
if err != nil {
return nil, err
}
var sm ServiceMonitorList
return &sm, json.Unmarshal(b, &sm)
}
func (s *servicemonitors) Watch(opts metav1.ListOptions) (watch.Interface, error) {
r, err := s.restClient.Get().
Prefix("watch").
Namespace(s.ns).
Resource("servicemonitors").
// VersionedParams(&options, v1.ParameterCodec).
FieldsSelectorParam(nil).
Stream()
if err != nil {
return nil, err
}
return watch.NewStreamWatcher(&serviceMonitorDecoder{
dec: json.NewDecoder(r),
close: r.Close,
}), nil
}
func (s *servicemonitors) DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error {
return s.client.DeleteCollection(dopts, lopts)
}
// ServiceMonitorFromUnstructured unmarshals a ServiceMonitor object from dynamic client's unstructured
func ServiceMonitorFromUnstructured(r *unstructured.Unstructured) (*ServiceMonitor, error) {
b, err := json.Marshal(r.Object)
if err != nil {
return nil, err
}
var s ServiceMonitor
if err := json.Unmarshal(b, &s); err != nil {
return nil, err
}
s.TypeMeta.Kind = ServiceMonitorsKind
s.TypeMeta.APIVersion = Group + "/" + Version
return &s, nil
}
// UnstructuredFromServiceMonitor marshals a ServiceMonitor object into dynamic client's unstructured
func UnstructuredFromServiceMonitor(s *ServiceMonitor) (*unstructured.Unstructured, error) {
s.TypeMeta.Kind = ServiceMonitorsKind
s.TypeMeta.APIVersion = Group + "/" + Version
b, err := json.Marshal(s)
if err != nil {
return nil, err
}
var r unstructured.Unstructured
if err := json.Unmarshal(b, &r.Object); err != nil {
return nil, err
}
return &r, nil
}
type serviceMonitorDecoder struct {
dec *json.Decoder
close func() error
}
func (d *serviceMonitorDecoder) Close() {
d.close()
}
func (d *serviceMonitorDecoder) Decode() (action watch.EventType, object runtime.Object, err error) {
var e struct {
Type watch.EventType
Object ServiceMonitor
}
if err := d.dec.Decode(&e); err != nil {
return watch.Error, nil, err
}
return e.Type, &e.Object, nil
}

View file

@ -0,0 +1,344 @@
// Copyright 2016 The prometheus-operator Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/pkg/api/v1"
)
// Prometheus defines a Prometheus deployment.
type Prometheus struct {
metav1.TypeMeta `json:",inline"`
// Standard objects metadata. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of the Prometheus cluster. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
Spec PrometheusSpec `json:"spec"`
// Most recent observed status of the Prometheus cluster. Read-only. Not
// included when requesting from the apiserver, only from the Prometheus
// Operator API itself. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
Status *PrometheusStatus `json:"status,omitempty"`
}
// PrometheusList is a list of Prometheuses.
type PrometheusList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ListMeta `json:"metadata,omitempty"`
// List of Prometheuses
Items []*Prometheus `json:"items"`
}
// Specification of the desired behavior of the Prometheus cluster. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
type PrometheusSpec struct {
// ServiceMonitors to be selected for target discovery.
ServiceMonitorSelector *metav1.LabelSelector `json:"serviceMonitorSelector,omitempty"`
// Version of Prometheus to be deployed.
Version string `json:"version,omitempty"`
// When a Prometheus deployment is paused, no actions except for deletion
// will be performed on the underlying objects.
Paused bool `json:"paused,omitempty"`
// Base image to use for a Prometheus deployment.
BaseImage string `json:"baseImage,omitempty"`
// An optional list of references to secrets in the same namespace
// to use for pulling prometheus and alertmanager images from registries
// see http://kubernetes.io/docs/user-guide/images#specifying-imagepullsecrets-on-a-pod
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// Number of instances to deploy for a Prometheus deployment.
Replicas *int32 `json:"replicas,omitempty"`
// Time duration Prometheus shall retain data for.
Retention string `json:"retention,omitempty"`
// Interval between consecutive evaluations.
EvaluationInterval string `json:"evaluationInterval,omitempty"`
// The labels to add to any time series or alerts when communicating with
// external systems (federation, remote storage, Alertmanager).
ExternalLabels map[string]string `json:"externalLabels,omitempty"`
// The external URL the Prometheus instances will be available under. This is
// necessary to generate correct URLs. This is necessary if Prometheus is not
// served from root of a DNS name.
ExternalURL string `json:"externalUrl,omitempty"`
// The route prefix Prometheus registers HTTP handlers for. This is useful,
// if using ExternalURL and a proxy is rewriting HTTP routes of a request,
// and the actual ExternalURL is still true, but the server serves requests
// under a different route prefix. For example for use with `kubectl proxy`.
RoutePrefix string `json:"routePrefix,omitempty"`
// Storage spec to specify how storage shall be used.
Storage *StorageSpec `json:"storage,omitempty"`
// A selector to select which ConfigMaps to mount for loading rule files from.
RuleSelector *metav1.LabelSelector `json:"ruleSelector,omitempty"`
// Define details regarding alerting.
Alerting AlertingSpec `json:"alerting,omitempty"`
// Define resources requests and limits for single Pods.
Resources v1.ResourceRequirements `json:"resources,omitempty"`
// Define which Nodes the Pods are scheduled on.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// ServiceAccountName is the name of the ServiceAccount to use to run the
// Prometheus Pods.
ServiceAccountName string `json:"serviceAccountName,omitempty"`
// Secrets is a list of Secrets in the same namespace as the Prometheus
// object, which shall be mounted into the Prometheus Pods.
// The Secrets are mounted into /etc/prometheus/secrets/<secret-name>.
// Secrets changes after initial creation of a Prometheus object are not
// reflected in the running Pods. To change the secrets mounted into the
// Prometheus Pods, the object must be deleted and recreated with the new list
// of secrets.
Secrets []string `json:"secrets,omitempty"`
// EvaluationInterval string `json:"evaluationInterval"`
// Remote RemoteSpec `json:"remote"`
// Sharding...
}
// Most recent observed status of the Prometheus cluster. Read-only. Not
// included when requesting from the apiserver, only from the Prometheus
// Operator API itself. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
type PrometheusStatus struct {
// Represents whether any actions on the underlaying managed objects are
// being performed. Only delete actions will be performed.
Paused bool `json:"paused"`
// Total number of non-terminated pods targeted by this Prometheus deployment
// (their labels match the selector).
Replicas int32 `json:"replicas"`
// Total number of non-terminated pods targeted by this Prometheus deployment
// that have the desired version spec.
UpdatedReplicas int32 `json:"updatedReplicas"`
// Total number of available pods (ready for at least minReadySeconds)
// targeted by this Prometheus deployment.
AvailableReplicas int32 `json:"availableReplicas"`
// Total number of unavailable pods targeted by this Prometheus deployment.
UnavailableReplicas int32 `json:"unavailableReplicas"`
}
// AlertingSpec defines parameters for alerting configuration of Prometheus servers.
type AlertingSpec struct {
// AlertmanagerEndpoints Prometheus should fire alerts against.
Alertmanagers []AlertmanagerEndpoints `json:"alertmanagers"`
}
// StorageSpec defines the configured storage for a group Prometheus servers.
type StorageSpec struct {
// Name of the StorageClass to use when requesting storage provisioning. More
// info: https://kubernetes.io/docs/user-guide/persistent-volumes/#storageclasses
// DEPRECATED
Class string `json:"class"`
// A label query over volumes to consider for binding.
// DEPRECATED
Selector *metav1.LabelSelector `json:"selector"`
// Resources represents the minimum resources the volume should have. More
// info: http://kubernetes.io/docs/user-guide/persistent-volumes#resources
// DEPRECATED
Resources v1.ResourceRequirements `json:"resources"`
// A PVC spec to be used by the Prometheus StatefulSets.
VolumeClaimTemplate v1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"`
}
// AlertmanagerEndpoints defines a selection of a single Endpoints object
// containing alertmanager IPs to fire alerts against.
type AlertmanagerEndpoints struct {
// Namespace of Endpoints object.
Namespace string `json:"namespace"`
// Name of Endpoints object in Namespace.
Name string `json:"name"`
// Port the Alertmanager API is exposed on.
Port intstr.IntOrString `json:"port"`
// Scheme to use when firing alerts.
Scheme string `json:"scheme"`
// Prefix for the HTTP path alerts are pushed to.
PathPrefix string `json:"pathPrefix"`
}
// ServiceMonitor defines monitoring for a set of services.
type ServiceMonitor struct {
metav1.TypeMeta `json:",inline"`
// Standard objects metadata. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of desired Service selection for target discrovery by
// Prometheus.
Spec ServiceMonitorSpec `json:"spec"`
}
// ServiceMonitorSpec contains specification parameters for a ServiceMonitor.
type ServiceMonitorSpec struct {
// The label to use to retrieve the job name from.
JobLabel string `json:"jobLabel,omitempty"`
// A list of endpoints allowed as part of this ServiceMonitor.
Endpoints []Endpoint `json:"endpoints"`
// Selector to select Endpoints objects.
Selector metav1.LabelSelector `json:"selector"`
// Selector to select which namespaces the Endpoints objects are discovered from.
NamespaceSelector NamespaceSelector `json:"namespaceSelector,omitempty"`
}
// Endpoint defines a scrapeable endpoint serving Prometheus metrics.
type Endpoint struct {
// Name of the service port this endpoint refers to. Mutually exclusive with targetPort.
Port string `json:"port,omitempty"`
// Name or number of the target port of the endpoint. Mutually exclusive with port.
TargetPort intstr.IntOrString `json:"targetPort,omitempty"`
// HTTP path to scrape for metrics.
Path string `json:"path,omitempty"`
// HTTP scheme to use for scraping.
Scheme string `json:"scheme,omitempty"`
// Interval at which metrics should be scraped
Interval string `json:"interval,omitempty"`
// Timeout after which the scrape is ended
ScrapeTimeout string `json:"scrapeTimeout,omitempty"`
// TLS configuration to use when scraping the endpoint
TLSConfig *TLSConfig `json:"tlsConfig,omitempty"`
// File to read bearer token for scraping targets.
BearerTokenFile string `json:"bearerTokenFile,omitempty"`
// HonorLabels chooses the metric's labels on collisions with target labels.
HonorLabels bool `json:"honorLabels,omitempty"`
// BasicAuth allow an endpoint to authenticate over basic authentication
// More info: https://prometheus.io/docs/operating/configuration/#endpoints
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
}
// BasicAuth allow an endpoint to authenticate over basic authentication
// More info: https://prometheus.io/docs/operating/configuration/#endpoints
type BasicAuth struct {
// The secret that contains the username for authenticate
Username v1.SecretKeySelector `json:"username,omitempty"`
// The secret that contains the password for authenticate
Password v1.SecretKeySelector `json:"password,omitempty"`
}
// TLSConfig specifies TLS configuration parameters.
type TLSConfig struct {
// The CA cert to use for the targets.
CAFile string `json:"caFile,omitempty"`
// The client cert file for the targets.
CertFile string `json:"certFile,omitempty"`
// The client key file for the targets.
KeyFile string `json:"keyFile,omitempty"`
// Used to verify the hostname for the targets.
ServerName string `json:"serverName,omitempty"`
// Disable target certificate validation.
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`
}
// A list of ServiceMonitors.
type ServiceMonitorList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ListMeta `json:"metadata,omitempty"`
// List of ServiceMonitors
Items []*ServiceMonitor `json:"items"`
}
// Describes an Alertmanager cluster.
type Alertmanager struct {
metav1.TypeMeta `json:",inline"`
// Standard objects metadata. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
// Specification of the desired behavior of the Alertmanager cluster. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
Spec AlertmanagerSpec `json:"spec"`
// Most recent observed status of the Alertmanager cluster. Read-only. Not
// included when requesting from the apiserver, only from the Prometheus
// Operator API itself. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
Status *AlertmanagerStatus `json:"status,omitempty"`
}
// Specification of the desired behavior of the Alertmanager cluster. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
type AlertmanagerSpec struct {
// Version the cluster should be on.
Version string `json:"version,omitempty"`
// Base image that is used to deploy pods.
BaseImage string `json:"baseImage,omitempty"`
// An optional list of references to secrets in the same namespace
// to use for pulling prometheus and alertmanager images from registries
// see http://kubernetes.io/docs/user-guide/images#specifying-imagepullsecrets-on-a-pod
ImagePullSecrets []v1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
// Size is the expected size of the alertmanager cluster. The controller will
// eventually make the size of the running cluster equal to the expected
// size.
Replicas *int32 `json:"replicas,omitempty"`
// Storage is the definition of how storage will be used by the Alertmanager
// instances.
Storage *StorageSpec `json:"storage,omitempty"`
// The external URL the Alertmanager instances will be available under. This is
// necessary to generate correct URLs. This is necessary if Alertmanager is not
// served from root of a DNS name.
ExternalURL string `json:"externalUrl,omitempty"`
// The route prefix Alertmanager registers HTTP handlers for. This is useful,
// if using ExternalURL and a proxy is rewriting HTTP routes of a request,
// and the actual ExternalURL is still true, but the server serves requests
// under a different route prefix. For example for use with `kubectl proxy`.
RoutePrefix string `json:"routePrefix,omitempty"`
// If set to true all actions on the underlaying managed objects are not
// goint to be performed, except for delete actions.
Paused bool `json:"paused,omitempty"`
// Define which Nodes the Pods are scheduled on.
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Define resources requests and limits for single Pods.
Resources v1.ResourceRequirements `json:"resources,omitempty"`
}
// A list of Alertmanagers.
type AlertmanagerList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
metav1.ListMeta `json:"metadata,omitempty"`
// List of Alertmanagers
Items []Alertmanager `json:"items"`
}
// Most recent observed status of the Alertmanager cluster. Read-only. Not
// included when requesting from the apiserver, only from the Prometheus
// Operator API itself. More info:
// http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#spec-and-status
type AlertmanagerStatus struct {
// Represents whether any actions on the underlaying managed objects are
// being performed. Only delete actions will be performed.
Paused bool `json:"paused"`
// Total number of non-terminated pods targeted by this Alertmanager
// cluster (their labels match the selector).
Replicas int32 `json:"replicas"`
// Total number of non-terminated pods targeted by this Alertmanager
// cluster that have the desired version spec.
UpdatedReplicas int32 `json:"updatedReplicas"`
// Total number of available pods (ready for at least minReadySeconds)
// targeted by this Alertmanager cluster.
AvailableReplicas int32 `json:"availableReplicas"`
// Total number of unavailable pods targeted by this Alertmanager cluster.
UnavailableReplicas int32 `json:"unavailableReplicas"`
}
// A selector for selecting namespaces either selecting all namespaces or a
// list of namespaces.
type NamespaceSelector struct {
// Boolean describing whether all namespaces are selected in contrast to a
// list restricting them.
Any bool `json:"any,omitempty"`
// List of namespace names.
MatchNames []string `json:"matchNames,omitempty"`
// TODO(fabxc): this should embed metav1.LabelSelector eventually.
// Currently the selector is only used for namespaces which require more complex
// implementation to support label selections.
}

View file

@ -36,6 +36,8 @@ type AlertmanagersGetter interface {
Alertmanagers(namespace string) AlertmanagerInterface
}
var _ AlertmanagerInterface = &alertmanagers{}
type AlertmanagerInterface interface {
Create(*Alertmanager) (*Alertmanager, error)
Get(name string, opts metav1.GetOptions) (*Alertmanager, error)
@ -43,6 +45,7 @@ type AlertmanagerInterface interface {
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error
}
type alertmanagers struct {
@ -144,6 +147,10 @@ func (a *alertmanagers) Watch(opts metav1.ListOptions) (watch.Interface, error)
}), nil
}
func (a *alertmanagers) DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error {
return a.client.DeleteCollection(dopts, lopts)
}
// AlertmanagerFromUnstructured unmarshals an Alertmanager object from dynamic client's unstructured
func AlertmanagerFromUnstructured(r *unstructured.Unstructured) (*Alertmanager, error) {
b, err := json.Marshal(r.Object)

View file

@ -57,7 +57,7 @@ func (c *MonitoringV1alpha1Client) RESTClient() rest.Interface {
func NewForConfig(c *rest.Config) (*MonitoringV1alpha1Client, error) {
config := *c
setConfigDefaults(&config)
SetConfigDefaults(&config)
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, err
@ -71,7 +71,7 @@ func NewForConfig(c *rest.Config) (*MonitoringV1alpha1Client, error) {
return &MonitoringV1alpha1Client{client, dynamicClient}, nil
}
func setConfigDefaults(config *rest.Config) {
func SetConfigDefaults(config *rest.Config) {
config.GroupVersion = &schema.GroupVersion{
Group: Group,
Version: Version,

View file

@ -30,13 +30,14 @@ import (
const (
PrometheusesKind = "Prometheus"
PrometheusName = "prometheuses"
PrometheusShort = "prom"
)
type PrometheusesGetter interface {
Prometheuses(namespace string) PrometheusInterface
}
var _ PrometheusInterface = &prometheuses{}
type PrometheusInterface interface {
Create(*Prometheus) (*Prometheus, error)
Get(name string, opts metav1.GetOptions) (*Prometheus, error)
@ -44,6 +45,7 @@ type PrometheusInterface interface {
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error
}
type prometheuses struct {
@ -145,6 +147,10 @@ func (p *prometheuses) Watch(opts metav1.ListOptions) (watch.Interface, error) {
}), nil
}
func (p *prometheuses) DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error {
return p.client.DeleteCollection(dopts, lopts)
}
// PrometheusFromUnstructured unmarshals a Prometheus object from dynamic client's unstructured
func PrometheusFromUnstructured(r *unstructured.Unstructured) (*Prometheus, error) {
b, err := json.Marshal(r.Object)

View file

@ -36,6 +36,8 @@ type ServiceMonitorsGetter interface {
ServiceMonitors(namespace string) ServiceMonitorInterface
}
var _ ServiceMonitorInterface = &servicemonitors{}
type ServiceMonitorInterface interface {
Create(*ServiceMonitor) (*ServiceMonitor, error)
Get(name string, opts metav1.GetOptions) (*ServiceMonitor, error)
@ -43,6 +45,7 @@ type ServiceMonitorInterface interface {
Delete(name string, options *metav1.DeleteOptions) error
List(opts metav1.ListOptions) (runtime.Object, error)
Watch(opts metav1.ListOptions) (watch.Interface, error)
DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error
}
type servicemonitors struct {
@ -144,6 +147,10 @@ func (s *servicemonitors) Watch(opts metav1.ListOptions) (watch.Interface, error
}), nil
}
func (s *servicemonitors) DeleteCollection(dopts *metav1.DeleteOptions, lopts metav1.ListOptions) error {
return s.client.DeleteCollection(dopts, lopts)
}
// ServiceMonitorFromUnstructured unmarshals a ServiceMonitor object from dynamic client's unstructured
func ServiceMonitorFromUnstructured(r *unstructured.Unstructured) (*ServiceMonitor, error) {
b, err := json.Marshal(r.Object)