2018-09-24 11:43:34 -06:00
|
|
|
/*
|
|
|
|
|
Copyright 2016 The Rook Authors. All rights reserved.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-03-01 10:25:07 -07:00
|
|
|
package mds
|
2018-09-24 11:43:34 -06:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2019-02-14 09:16:21 -07:00
|
|
|
"github.com/rook/rook/pkg/operator/ceph/config"
|
2020-11-25 13:20:31 +05:30
|
|
|
"github.com/rook/rook/pkg/operator/ceph/controller"
|
2021-02-18 13:10:11 +00:00
|
|
|
"github.com/rook/rook/pkg/operator/ceph/test"
|
|
|
|
|
"github.com/rook/rook/pkg/operator/k8sutil"
|
2019-02-14 09:16:21 -07:00
|
|
|
|
2018-12-03 15:08:29 -07:00
|
|
|
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
|
2018-09-24 11:43:34 -06:00
|
|
|
"github.com/rook/rook/pkg/clusterd"
|
2020-07-01 22:46:39 -06:00
|
|
|
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
|
2019-03-15 14:22:09 -07:00
|
|
|
cephver "github.com/rook/rook/pkg/operator/ceph/version"
|
2018-09-24 11:43:34 -06:00
|
|
|
testop "github.com/rook/rook/pkg/operator/test"
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-02-04 19:35:45 +00:00
|
|
|
apps "k8s.io/api/apps/v1"
|
2019-01-24 14:58:46 +01:00
|
|
|
v1 "k8s.io/api/core/v1"
|
2018-09-24 11:43:34 -06:00
|
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
2023-09-06 18:59:52 +05:30
|
|
|
"k8s.io/apimachinery/pkg/types"
|
2018-09-24 11:43:34 -06:00
|
|
|
)
|
|
|
|
|
|
2020-01-07 18:51:19 +05:30
|
|
|
func testDeploymentObject(t *testing.T, network cephv1.NetworkSpec) (*apps.Deployment, error) {
|
2018-12-03 23:48:40 -07:00
|
|
|
fs := cephv1.CephFilesystem{
|
2018-09-24 11:43:34 -06:00
|
|
|
ObjectMeta: metav1.ObjectMeta{Name: "myfs", Namespace: "ns"},
|
2018-12-03 15:08:29 -07:00
|
|
|
Spec: cephv1.FilesystemSpec{
|
|
|
|
|
MetadataServer: cephv1.MetadataServerSpec{
|
2018-09-24 11:43:34 -06:00
|
|
|
ActiveCount: 1,
|
|
|
|
|
ActiveStandby: false,
|
|
|
|
|
Resources: v1.ResourceRequirements{
|
|
|
|
|
Limits: v1.ResourceList{
|
2019-03-05 15:51:20 +01:00
|
|
|
v1.ResourceCPU: *resource.NewQuantity(500.0, resource.BinarySI),
|
|
|
|
|
v1.ResourceMemory: *resource.NewQuantity(4337.0, resource.BinarySI),
|
2018-09-24 11:43:34 -06:00
|
|
|
},
|
2019-03-05 12:13:44 +01:00
|
|
|
Requests: v1.ResourceList{
|
2019-03-05 15:51:20 +01:00
|
|
|
v1.ResourceCPU: *resource.NewQuantity(250.0, resource.BinarySI),
|
|
|
|
|
v1.ResourceMemory: *resource.NewQuantity(2169.0, resource.BinarySI),
|
2019-03-05 12:13:44 +01:00
|
|
|
},
|
|
|
|
|
},
|
2019-08-04 15:40:29 -05:00
|
|
|
PriorityClassName: "my-priority-class",
|
2019-03-05 12:13:44 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2020-07-01 22:46:39 -06:00
|
|
|
clusterInfo := &cephclient.ClusterInfo{
|
2019-03-15 14:22:09 -07:00
|
|
|
FSID: "myfsid",
|
2022-07-01 10:38:15 -06:00
|
|
|
CephVersion: cephver.Quincy,
|
2019-03-15 14:22:09 -07:00
|
|
|
}
|
2020-01-07 18:51:19 +05:30
|
|
|
clientset := testop.New(t, 1)
|
2020-03-17 13:28:09 +01:00
|
|
|
|
2019-03-01 10:25:07 -07:00
|
|
|
c := NewCluster(
|
2019-02-14 09:16:21 -07:00
|
|
|
clusterInfo,
|
2020-01-07 18:51:19 +05:30
|
|
|
&clusterd.Context{Clientset: clientset},
|
2019-03-21 14:58:06 -10:00
|
|
|
&cephv1.ClusterSpec{
|
2023-01-09 15:47:51 +05:30
|
|
|
CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:testversion"},
|
|
|
|
|
Network: network,
|
|
|
|
|
DataDirHostPath: "/var/lib/rook/",
|
2019-03-21 14:58:06 -10:00
|
|
|
},
|
2018-09-24 11:43:34 -06:00
|
|
|
fs,
|
2021-02-18 13:10:11 +00:00
|
|
|
&k8sutil.OwnerInfo{},
|
2019-04-02 20:10:09 +02:00
|
|
|
"/var/lib/rook/",
|
2018-09-24 11:43:34 -06:00
|
|
|
)
|
|
|
|
|
mdsTestConfig := &mdsConfig{
|
2019-02-14 09:16:21 -07:00
|
|
|
DaemonID: "myfs-a",
|
2018-09-24 11:43:34 -06:00
|
|
|
ResourceName: "rook-ceph-mds-myfs-a",
|
2019-04-02 20:10:09 +02:00
|
|
|
DataPathMap: config.NewStatelessDaemonDataPathMap(config.MdsType, "myfs-a", "rook-ceph", "/var/lib/rook/"),
|
2018-09-24 11:43:34 -06:00
|
|
|
}
|
2023-09-06 18:59:52 +05:30
|
|
|
fsNamespacedname := types.NamespacedName{Name: "myfs-a", Namespace: "ns"}
|
|
|
|
|
|
2022-02-03 20:26:33 +05:30
|
|
|
t.Run(("check mds ConfigureProbe"), func(t *testing.T) {
|
|
|
|
|
c.fs.Spec.MetadataServer.LivenessProbe = &cephv1.ProbeSpec{Disabled: false, Probe: &v1.Probe{InitialDelaySeconds: 900}}
|
2023-09-06 18:59:52 +05:30
|
|
|
deployment, err := c.makeDeployment(mdsTestConfig, fsNamespacedname)
|
2022-02-03 20:26:33 +05:30
|
|
|
assert.Nil(t, err)
|
|
|
|
|
assert.NotNil(t, deployment)
|
|
|
|
|
assert.NotNil(t, c.fs.Spec.MetadataServer.LivenessProbe)
|
2023-09-06 18:59:52 +05:30
|
|
|
assert.Equal(t, "myfs-a", mdsTestConfig.DaemonID)
|
|
|
|
|
assert.Equal(t, "myfs-a", fsNamespacedname.Name)
|
2022-02-03 20:26:33 +05:30
|
|
|
assert.Equal(t, int32(900), deployment.Spec.Template.Spec.Containers[0].LivenessProbe.InitialDelaySeconds)
|
2023-09-06 18:59:52 +05:30
|
|
|
assert.NotNil(t, deployment.Spec.Template.Spec.Containers[0].LivenessProbe.ProbeHandler.Exec)
|
2022-02-03 20:26:33 +05:30
|
|
|
})
|
2023-09-06 18:59:52 +05:30
|
|
|
return c.makeDeployment(mdsTestConfig, fsNamespacedname)
|
2018-09-24 11:43:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPodSpecs(t *testing.T) {
|
2020-01-07 18:51:19 +05:30
|
|
|
d, err := testDeploymentObject(t, cephv1.NetworkSpec{HostNetwork: false}) // no host network
|
|
|
|
|
assert.Nil(t, err)
|
2018-09-24 11:43:34 -06:00
|
|
|
|
|
|
|
|
assert.NotNil(t, d)
|
|
|
|
|
assert.Equal(t, v1.RestartPolicyAlways, d.Spec.Template.Spec.RestartPolicy)
|
2023-12-14 18:30:11 +05:30
|
|
|
assert.Equal(t, k8sutil.DefaultServiceAccount, d.Spec.Template.Spec.ServiceAccountName)
|
2018-09-24 11:43:34 -06:00
|
|
|
|
2019-02-14 09:16:21 -07:00
|
|
|
// Deployment should have Ceph labels
|
2021-02-18 13:10:11 +00:00
|
|
|
test.AssertLabelsContainCephRequirements(t, d.ObjectMeta.Labels,
|
2021-12-06 12:52:11 +05:30
|
|
|
config.MdsType, "myfs-a", "rook-ceph-mds", "ns", "myfs", "cephfilesystems.ceph.rook.io", "ceph-mds")
|
2018-09-24 11:43:34 -06:00
|
|
|
|
2021-02-18 13:10:11 +00:00
|
|
|
podTemplate := test.NewPodTemplateSpecTester(t, &d.Spec.Template)
|
2021-07-22 10:33:30 +02:00
|
|
|
podTemplate.RunFullSuite(config.MdsType, "myfs-a", "rook-ceph-mds", "ns", "quay.io/ceph/ceph:testversion",
|
2019-08-04 15:40:29 -05:00
|
|
|
"500", "250", "4337", "2169", /* resources */
|
2021-12-06 12:52:11 +05:30
|
|
|
"my-priority-class", "myfs", "cephfilesystems.ceph.rook.io", "ceph-mds")
|
2020-11-25 13:20:31 +05:30
|
|
|
|
|
|
|
|
// assert --public-addr is appended to args
|
|
|
|
|
assert.Contains(t, d.Spec.Template.Spec.Containers[0].Args,
|
|
|
|
|
config.NewFlag("public-addr", controller.ContainerEnvVarReference(podIPEnvVar)))
|
2018-09-24 11:43:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestHostNetwork(t *testing.T) {
|
2020-01-07 18:51:19 +05:30
|
|
|
d, err := testDeploymentObject(t, cephv1.NetworkSpec{HostNetwork: true}) // host network
|
|
|
|
|
assert.Nil(t, err)
|
2018-09-24 11:43:34 -06:00
|
|
|
|
|
|
|
|
assert.Equal(t, true, d.Spec.Template.Spec.HostNetwork)
|
|
|
|
|
assert.Equal(t, v1.DNSClusterFirstWithHostNet, d.Spec.Template.Spec.DNSPolicy)
|
2020-11-25 13:20:31 +05:30
|
|
|
|
|
|
|
|
// assert --public-addr is not appended to args
|
|
|
|
|
assert.NotContains(t, d.Spec.Template.Spec.Containers[0].Args,
|
|
|
|
|
config.NewFlag("public-addr", controller.ContainerEnvVarReference(podIPEnvVar)))
|
2018-09-24 11:43:34 -06:00
|
|
|
}
|