forked from rook/rook
Merge pull request #4110 from leseb/mrg-annotations
ceph: mgr do not override annotation
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"strings"
|
||||
|
||||
rookcephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
||||
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
|
||||
"github.com/rook/rook/pkg/daemon/ceph/client"
|
||||
"github.com/rook/rook/pkg/operator/ceph/cluster/mon"
|
||||
"github.com/rook/rook/pkg/operator/ceph/config"
|
||||
@@ -80,16 +81,11 @@ func (c *Cluster) makeDeployment(mgrConfig *mgrConfig) *apps.Deployment {
|
||||
podSpec.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
|
||||
}
|
||||
c.annotations.ApplyToObjectMeta(&podSpec.ObjectMeta)
|
||||
c.applyPrometheusAnnotations(&podSpec.ObjectMeta)
|
||||
c.placement.ApplyToPodSpec(&podSpec.Spec)
|
||||
|
||||
replicas := int32(1)
|
||||
if len(c.annotations) == 0 {
|
||||
prometheusAnnotations := map[string]string{
|
||||
"prometheus.io/scrape": "true",
|
||||
"prometheus.io/port": strconv.Itoa(metricsPort),
|
||||
}
|
||||
podSpec.ObjectMeta.Annotations = prometheusAnnotations
|
||||
}
|
||||
|
||||
d := &apps.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: mgrConfig.ResourceName,
|
||||
@@ -329,6 +325,19 @@ func (c *Cluster) getPodLabels(daemonName string) map[string]string {
|
||||
return labels
|
||||
}
|
||||
|
||||
func (c *Cluster) applyPrometheusAnnotations(objectMeta *metav1.ObjectMeta) error {
|
||||
if len(c.annotations) == 0 {
|
||||
t := rookalpha.Annotations{
|
||||
"prometheus.io/scrape": "true",
|
||||
"prometheus.io/port": strconv.Itoa(metricsPort),
|
||||
}
|
||||
|
||||
t.ApplyToObjectMeta(objectMeta)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cluster) cephMgrOrchestratorModuleEnvs() []v1.EnvVar {
|
||||
operatorNamespace := os.Getenv(k8sutil.PodNamespaceEnvVar)
|
||||
envVars := []v1.EnvVar{
|
||||
|
||||
@@ -210,3 +210,51 @@ func TestHttpBindFix(t *testing.T) {
|
||||
len(d.Spec.Template.Spec.InitContainers))
|
||||
}
|
||||
}
|
||||
|
||||
func TestApplyPrometheusAnnotations(t *testing.T) {
|
||||
c := New(
|
||||
&cephconfig.ClusterInfo{FSID: "myfsid"},
|
||||
&clusterd.Context{Clientset: optest.New(1)},
|
||||
"ns",
|
||||
"myversion",
|
||||
cephv1.CephVersionSpec{},
|
||||
rookalpha.Placement{},
|
||||
rookalpha.Annotations{},
|
||||
cephv1.NetworkSpec{},
|
||||
cephv1.DashboardSpec{},
|
||||
cephv1.MonitoringSpec{},
|
||||
cephv1.MgrSpec{},
|
||||
v1.ResourceRequirements{},
|
||||
metav1.OwnerReference{},
|
||||
"/var/lib/rook/",
|
||||
false,
|
||||
false,
|
||||
)
|
||||
|
||||
mgrTestConfig := mgrConfig{
|
||||
DaemonID: "a",
|
||||
ResourceName: "rook-ceph-mgr-a",
|
||||
DashboardPort: 1234,
|
||||
DataPathMap: config.NewStatelessDaemonDataPathMap(config.MgrType, "a", "rook-ceph", "/var/lib/rook/"),
|
||||
}
|
||||
|
||||
d := c.makeDeployment(&mgrTestConfig)
|
||||
|
||||
// Test without annotations
|
||||
c.applyPrometheusAnnotations(&d.ObjectMeta)
|
||||
assert.Equal(t, 2, len(d.ObjectMeta.Annotations))
|
||||
|
||||
// Test with existing annotations
|
||||
// applyPrometheusAnnotations() shouldn't do anything
|
||||
// re-initialize "d"
|
||||
d = c.makeDeployment(&mgrTestConfig)
|
||||
|
||||
fakeAnnotations := rookalpha.Annotations{
|
||||
"foo.io/bar": "foobar",
|
||||
}
|
||||
c.annotations = fakeAnnotations
|
||||
|
||||
c.applyPrometheusAnnotations(&d.ObjectMeta)
|
||||
assert.Equal(t, 1, len(c.annotations))
|
||||
assert.Equal(t, 0, len(d.ObjectMeta.Annotations))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user