mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
cleanup structure
This commit is contained in:
parent
6e49d8f54f
commit
505ac1aa80
4 changed files with 92 additions and 89 deletions
pkg
|
@ -211,11 +211,12 @@ func (c *Controller) monitorPrometheusServers(client *http.Client, watchVersion
|
|||
return events, errc
|
||||
}
|
||||
|
||||
// PrometheusList is a list of Prometheus TPR objects.
|
||||
type PrometheusList struct {
|
||||
unversioned.TypeMeta `json:",inline"`
|
||||
// Standard list metadata
|
||||
// More info: http://releases.k8s.io/HEAD/docs/devel/api-conventions.md#metadata
|
||||
unversioned.ListMeta `json:"metadata,omitempty"`
|
||||
// Items is a list of third party objects
|
||||
Items []prometheus.Prometheus `json:"items"`
|
||||
Items []prometheus.Object `json:"items"`
|
||||
}
|
||||
|
|
1
pkg/prometheus/config.go
Normal file
1
pkg/prometheus/config.go
Normal file
|
@ -0,0 +1 @@
|
|||
package prometheus
|
82
pkg/prometheus/objects.go
Normal file
82
pkg/prometheus/objects.go
Normal file
|
@ -0,0 +1,82 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
apiUnversioned "k8s.io/client-go/1.4/pkg/api/unversioned"
|
||||
apiV1 "k8s.io/client-go/1.4/pkg/api/v1"
|
||||
apiExtensions "k8s.io/client-go/1.4/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/client-go/1.4/pkg/util/intstr"
|
||||
)
|
||||
|
||||
// Object represents an Prometheus TPR API object.
|
||||
type Object struct {
|
||||
apiUnversioned.TypeMeta `json:",inline"`
|
||||
apiV1.ObjectMeta `json:"metadata,omitempty"`
|
||||
Spec Spec `json:"spec"`
|
||||
}
|
||||
|
||||
// Spec defines a Prometheus server.
|
||||
type Spec struct {
|
||||
ServiceMonitors []SpecServiceMonitor `json:"serviceMonitors"`
|
||||
}
|
||||
|
||||
// SpecServiceMonitor references a service monitor belonging to a Prometheus server.
|
||||
type SpecServiceMonitor struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func makeService(name string) *apiV1.Service {
|
||||
svc := &apiV1.Service{
|
||||
ObjectMeta: apiV1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: apiV1.ServiceSpec{
|
||||
Ports: []apiV1.ServicePort{
|
||||
{
|
||||
Name: "web",
|
||||
Port: 9090,
|
||||
TargetPort: intstr.FromString("web"),
|
||||
Protocol: apiV1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{
|
||||
"prometheus.coreos.com": name,
|
||||
},
|
||||
},
|
||||
}
|
||||
return svc
|
||||
}
|
||||
|
||||
func makeReplicaSet(name string) *apiExtensions.ReplicaSet {
|
||||
replicas := int32(1)
|
||||
rs := &apiExtensions.ReplicaSet{
|
||||
ObjectMeta: apiV1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: apiExtensions.ReplicaSetSpec{
|
||||
Replicas: &replicas,
|
||||
Template: apiV1.PodTemplateSpec{
|
||||
ObjectMeta: apiV1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"prometheus.coreos.com": name,
|
||||
},
|
||||
},
|
||||
Spec: apiV1.PodSpec{
|
||||
Containers: []apiV1.Container{
|
||||
{
|
||||
Name: "prometheus",
|
||||
Image: "quay.io/prometheus/prometheus:latest",
|
||||
Ports: []apiV1.ContainerPort{
|
||||
{
|
||||
Name: "web",
|
||||
ContainerPort: 9090,
|
||||
Protocol: apiV1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return rs
|
||||
}
|
|
@ -2,32 +2,9 @@ package prometheus
|
|||
|
||||
import (
|
||||
"k8s.io/client-go/1.4/kubernetes"
|
||||
core "k8s.io/client-go/1.4/kubernetes/typed/core/v1"
|
||||
extensions "k8s.io/client-go/1.4/kubernetes/typed/extensions/v1beta1"
|
||||
apierrors "k8s.io/client-go/1.4/pkg/api/errors"
|
||||
unversionedapi "k8s.io/client-go/1.4/pkg/api/unversioned"
|
||||
apiv1 "k8s.io/client-go/1.4/pkg/api/v1"
|
||||
extensionsapi "k8s.io/client-go/1.4/pkg/apis/extensions/v1beta1"
|
||||
"k8s.io/client-go/1.4/pkg/util/intstr"
|
||||
)
|
||||
|
||||
// Object represents an Prometheus TPR API object.
|
||||
type Object struct {
|
||||
unversionedapi.TypeMeta `json:",inline"`
|
||||
apiv1.ObjectMeta `json:"metadata,omitempty"`
|
||||
Spec Spec `json:"spec"`
|
||||
}
|
||||
|
||||
// Spec defines a Prometheus server.
|
||||
type Spec struct {
|
||||
ServiceMonitors []SpecServiceMonitor `json:"serviceMonitors"`
|
||||
}
|
||||
|
||||
// SpecServiceMonitor references a service monitor belonging to a Prometheus server.
|
||||
type SpecServiceMonitor struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// Prometheus manages the life-cycle of a single Prometheus server
|
||||
// in the cluster.
|
||||
type Prometheus struct {
|
||||
|
@ -42,12 +19,17 @@ func New(kc *kubernetes.Clientset, o *Object) (*Prometheus, error) {
|
|||
Object: o,
|
||||
kclient: kc,
|
||||
}
|
||||
if err := createService(p.kclient.Core().Services(p.Namespace), p.Name); err != nil {
|
||||
|
||||
svcClient := p.kclient.Core().Services(p.Namespace)
|
||||
if _, err := svcClient.Create(makeService(p.Name)); err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
return nil, err
|
||||
}
|
||||
if err := createReplicaSet(p.kclient.ExtensionsClient.ReplicaSets(p.Namespace), p.Name); err != nil {
|
||||
|
||||
rsClient := p.kclient.ExtensionsClient.ReplicaSets(p.Namespace)
|
||||
if _, err := rsClient.Create(makeReplicaSet(p.Name)); err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
go p.run()
|
||||
return p, nil
|
||||
}
|
||||
|
@ -67,66 +49,3 @@ func (p *Prometheus) Delete() error {
|
|||
|
||||
func (p *Prometheus) run() {
|
||||
}
|
||||
|
||||
func createReplicaSet(client extensions.ReplicaSetInterface, name string) error {
|
||||
replicas := int32(1)
|
||||
rs := &extensionsapi.ReplicaSet{
|
||||
ObjectMeta: apiv1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: extensionsapi.ReplicaSetSpec{
|
||||
Replicas: &replicas,
|
||||
Template: apiv1.PodTemplateSpec{
|
||||
ObjectMeta: apiv1.ObjectMeta{
|
||||
Labels: map[string]string{
|
||||
"prometheus.coreos.com": name,
|
||||
},
|
||||
},
|
||||
Spec: apiv1.PodSpec{
|
||||
Containers: []apiv1.Container{
|
||||
{
|
||||
Name: "prometheus",
|
||||
Image: "quay.io/prometheus/prometheus:latest",
|
||||
Ports: []apiv1.ContainerPort{
|
||||
{
|
||||
Name: "web",
|
||||
ContainerPort: 9090,
|
||||
Protocol: apiv1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := client.Create(rs); err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func createService(client core.ServiceInterface, name string) error {
|
||||
svc := &apiv1.Service{
|
||||
ObjectMeta: apiv1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: apiv1.ServiceSpec{
|
||||
Ports: []apiv1.ServicePort{
|
||||
{
|
||||
Name: "web",
|
||||
Port: 9090,
|
||||
TargetPort: intstr.FromString("web"),
|
||||
Protocol: apiv1.ProtocolTCP,
|
||||
},
|
||||
},
|
||||
Selector: map[string]string{
|
||||
"prometheus.coreos.com": name,
|
||||
},
|
||||
},
|
||||
}
|
||||
if _, err := client.Create(svc); err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue