mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 11:48:53 +00:00
StorageSpec: add extra field VolumeClaimTemplate.
this new field deprecated all the other StorageSpec fields with a v1.PersistentVolumeClaim. fixes #397
This commit is contained in:
parent
6e664fdd78
commit
af30df4cc0
5 changed files with 87 additions and 49 deletions
Documentation
pkg
|
@ -194,9 +194,10 @@ StorageSpec defines the configured storage for a group Prometheus servers.
|
|||
|
||||
| Field | Description | Scheme | Required |
|
||||
| ----- | ----------- | ------ | -------- |
|
||||
| class | Name of the StorageClass to use when requesting storage provisioning. More info: https://kubernetes.io/docs/user-guide/persistent-volumes/#storageclasses | string | true |
|
||||
| selector | A label query over volumes to consider for binding. | *[metav1.LabelSelector](https://kubernetes.io/docs/api-reference/v1.6/#labelselector-v1-meta) | true |
|
||||
| resources | Resources represents the minimum resources the volume should have. More info: http://kubernetes.io/docs/user-guide/persistent-volumes#resources | [v1.ResourceRequirements](https://kubernetes.io/docs/api-reference/v1.6/#resourcerequirements-v1-core) | true |
|
||||
| class | Name of the StorageClass to use when requesting storage provisioning. More info: https://kubernetes.io/docs/user-guide/persistent-volumes/#storageclasses DEPRECATED | string | true |
|
||||
| selector | A label query over volumes to consider for binding. DEPRECATED | *[metav1.LabelSelector](https://kubernetes.io/docs/api-reference/v1.6/#labelselector-v1-meta) | true |
|
||||
| resources | Resources represents the minimum resources the volume should have. More info: http://kubernetes.io/docs/user-guide/persistent-volumes#resources DEPRECATED | [v1.ResourceRequirements](https://kubernetes.io/docs/api-reference/v1.6/#resourcerequirements-v1-core) | true |
|
||||
| volumeClaimTemplate | Pvc A pvc spec to be used by the Prometheus statefulsets. | v1.PersistentVolumeClaim | false |
|
||||
|
||||
## TLSConfig
|
||||
|
||||
|
|
|
@ -28,16 +28,22 @@ It is recommended to use volumes that have high I/O throughput therefore we're u
|
|||
The `StorageClass` that was created can be specified in the `storage` section in the `Prometheus` resource.
|
||||
|
||||
```yaml
|
||||
apiVersion: "monitoring.coreos.com/v1alpha1"
|
||||
kind: "Prometheus"
|
||||
apiVersion: monitoring.coreos.com/v1alpha1
|
||||
kind: Prometheus
|
||||
metadata:
|
||||
name: "persisted"
|
||||
name: persisted
|
||||
spec:
|
||||
replicas: 1
|
||||
resources:
|
||||
storage:
|
||||
class: ssd
|
||||
resources:
|
||||
requests:
|
||||
storage: 40Gi
|
||||
volumeClaimTemplate:
|
||||
metadata:
|
||||
annotations:
|
||||
annotation1: foo
|
||||
spec:
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi
|
||||
```
|
||||
|
||||
> The full documentation of the `storage` field can be found in the [spec documentation](../api.md#storagespec).
|
||||
|
@ -47,7 +53,7 @@ When now creating the `Prometheus` object a `PersistentVolumeClaim` is used for
|
|||
|
||||
## Manual storage provisioning
|
||||
|
||||
The storage specification of the [Prometheus](../api.md#prometheus) kind is flexible enough to support arbitrary storage, not just those created via StorageClasses.
|
||||
The Prometheus TPR specification allows you to support arbitrary storage, via a PersistentVolumeClaim.
|
||||
|
||||
The easiest way to use a volume that cannot be automatically provisioned (for whatever reason) is to use a label selector alongside a manually created PersistentVolume.
|
||||
|
||||
|
@ -63,12 +69,13 @@ metadata:
|
|||
spec:
|
||||
...
|
||||
storage:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "my-example-prometheus"
|
||||
resources:
|
||||
requests:
|
||||
storage: 50Gi
|
||||
volumeClaimTemplate:
|
||||
selector:
|
||||
matchLabels:
|
||||
app: "my-example-prometheus"
|
||||
resources:
|
||||
requests:
|
||||
storage: 50Gi
|
||||
|
||||
---
|
||||
|
||||
|
@ -90,9 +97,9 @@ spec:
|
|||
|
||||
### Disabling Default StorageClasses
|
||||
|
||||
In order to manually provoision volumes, as of Kubernetes 1.6.0, you may need to disable the default `StorageClass` that is automatically created for certain Cloud Providers. Default StorageClasses are pre-installed on Azure, AWS, GCE, OpenStack, and vSphere.
|
||||
In order to manually provoision volumes, as of Kubernetes 1.6.0, you may need to disable the default `StorageClass` that is automatically created for certain Cloud Providers. Default StorageClasses are pre-installed on Azure, AWS, GCE, OpenStack, and vSphere.
|
||||
|
||||
The default `StorageClass`s behavior will override manual storage provisioning, causing `PerisistentVolumeClaim`s not to bind manually created `PersistentVolume`s automatically.
|
||||
The default `StorageClass`s behavior will override manual storage provisioning, causing `PerisistentVolumeClaim`s not to bind manually created `PersistentVolume`s automatically.
|
||||
|
||||
To override this behavior, you must explicitely create the same resource, but set it to *not* be default ([see changelog for details](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG.md#volumes)).
|
||||
|
||||
|
@ -102,7 +109,7 @@ To accomplish this on a Google Container Engine cluster, create the following `S
|
|||
kind: StorageClass
|
||||
apiVersion: storage.k8s.io/v1beta1
|
||||
metadata:
|
||||
name: standard
|
||||
name: standard
|
||||
annotations:
|
||||
# disable this default storage class by setting this annotation to false.
|
||||
storageclass.beta.kubernetes.io/is-default-class: "false"
|
||||
|
|
|
@ -135,12 +135,17 @@ type AlertingSpec struct {
|
|||
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"`
|
||||
// Pvc 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
|
||||
|
|
|
@ -18,16 +18,15 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/blang/semver"
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
|
||||
|
@ -96,8 +95,8 @@ func makeStatefulSet(p v1alpha1.Prometheus, old *v1beta1.StatefulSet, config *Co
|
|||
if p.Spec.ImagePullSecrets != nil && len(p.Spec.ImagePullSecrets) > 0 {
|
||||
statefulset.Spec.Template.Spec.ImagePullSecrets = p.Spec.ImagePullSecrets
|
||||
}
|
||||
|
||||
if vc := p.Spec.Storage; vc == nil {
|
||||
storageSpec := p.Spec.Storage
|
||||
if storageSpec == nil {
|
||||
statefulset.Spec.Template.Spec.Volumes = append(statefulset.Spec.Template.Spec.Volumes, v1.Volume{
|
||||
Name: volumeName(p.Name),
|
||||
VolumeSource: v1.VolumeSource{
|
||||
|
@ -105,22 +104,10 @@ func makeStatefulSet(p v1alpha1.Prometheus, old *v1beta1.StatefulSet, config *Co
|
|||
},
|
||||
})
|
||||
} else {
|
||||
pvc := v1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: volumeName(p.Name),
|
||||
},
|
||||
Spec: v1.PersistentVolumeClaimSpec{
|
||||
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
|
||||
Resources: vc.Resources,
|
||||
Selector: vc.Selector,
|
||||
},
|
||||
}
|
||||
if len(vc.Class) > 0 {
|
||||
pvc.ObjectMeta.Annotations = map[string]string{
|
||||
"volume.beta.kubernetes.io/storage-class": vc.Class,
|
||||
}
|
||||
}
|
||||
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, pvc)
|
||||
pvcTemplate := storageSpec.VolumeClaimTemplate
|
||||
pvcTemplate.Name = volumeName(p.Name)
|
||||
pvcTemplate.Spec.AccessModes = []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce}
|
||||
statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, pvcTemplate)
|
||||
}
|
||||
|
||||
if old != nil {
|
||||
|
|
|
@ -15,15 +15,13 @@
|
|||
package prometheus
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
|
||||
"github.com/stretchr/testify/require"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/pkg/api/v1"
|
||||
"k8s.io/client-go/pkg/apis/apps/v1beta1"
|
||||
|
||||
"github.com/coreos/prometheus-operator/pkg/client/monitoring/v1alpha1"
|
||||
"github.com/stretchr/testify/require"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -54,6 +52,46 @@ func TestStatefulSetLabelingAndAnnotations(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestStatefulSetPVC(t *testing.T) {
|
||||
labels := map[string]string{
|
||||
"testlabel": "testlabelvalue",
|
||||
}
|
||||
annotations := map[string]string{
|
||||
"testannotation": "testannotationvalue",
|
||||
}
|
||||
|
||||
storageClass := "storageclass"
|
||||
|
||||
pvc := v1.PersistentVolumeClaim{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Annotations: annotations,
|
||||
},
|
||||
Spec: v1.PersistentVolumeClaimSpec{
|
||||
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
|
||||
StorageClassName: &storageClass,
|
||||
},
|
||||
}
|
||||
|
||||
sset, err := makeStatefulSet(v1alpha1.Prometheus{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Labels: labels,
|
||||
Annotations: annotations,
|
||||
},
|
||||
Spec: v1alpha1.PrometheusSpec{
|
||||
Storage: &v1alpha1.StorageSpec{
|
||||
VolumeClaimTemplate: pvc,
|
||||
},
|
||||
},
|
||||
}, nil, defaultTestConfig, []*v1.ConfigMap{})
|
||||
|
||||
require.NoError(t, err)
|
||||
ssetPvc := sset.Spec.VolumeClaimTemplates[0]
|
||||
if !reflect.DeepEqual(*pvc.Spec.StorageClassName, *ssetPvc.Spec.StorageClassName) {
|
||||
t.Fatal("Error adding PVC Spec to StatefulSetSpec")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestStatefulSetVolumeInitial(t *testing.T) {
|
||||
expected := &v1beta1.StatefulSet{
|
||||
Spec: v1beta1.StatefulSetSpec{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue