2017-12-21 19:41:50 -08: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.
*/
// Package osd for the Ceph OSDs.
package osd
import (
"testing"
2018-12-03 15:08:29 -07:00
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
2017-12-21 19:41:50 -08:00
"github.com/rook/rook/pkg/clusterd"
2020-07-01 22:46:39 -06:00
cephclient "github.com/rook/rook/pkg/daemon/ceph/client"
2018-05-18 14:32:20 -07:00
"github.com/rook/rook/pkg/operator/ceph/cluster/osd/config"
2020-08-05 13:34:06 +02:00
opconfig "github.com/rook/rook/pkg/operator/ceph/config"
2020-12-09 15:09:16 +09:00
operatortest "github.com/rook/rook/pkg/operator/ceph/test"
2019-04-08 16:37:25 +02:00
cephver "github.com/rook/rook/pkg/operator/ceph/version"
2021-02-18 13:10:11 +00:00
"github.com/rook/rook/pkg/operator/k8sutil"
2017-12-21 19:41:50 -08:00
exectest "github.com/rook/rook/pkg/util/exec/test"
2020-08-05 13:34:06 +02:00
"github.com/stretchr/testify/assert"
2021-03-02 16:06:34 -07:00
appsv1 "k8s.io/api/apps/v1"
2021-07-26 14:58:23 +05:30
corev1 "k8s.io/api/core/v1"
2017-12-21 19:41:50 -08:00
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/client-go/kubernetes/fake"
)
func TestPodContainer ( t * testing . T ) {
2021-11-18 15:22:56 -07:00
cluster := & Cluster { rookVersion : "23" , clusterInfo : cephclient . AdminTestClusterInfo ( "myosd" )}
2021-02-18 13:10:11 +00:00
cluster . clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
2019-07-02 10:42:58 +05:30
osdProps := osdProperties {
crushHostname : "node" ,
2021-05-14 18:03:38 -06:00
devices : [] cephv1 . Device {},
2022-04-24 17:29:47 +02:00
resources : corev1 . ResourceRequirements {},
2019-07-02 10:42:58 +05:30
storeConfig : config . StoreConfig {},
2020-06-04 15:49:40 +09:00
schedulerName : "custom-scheduler" ,
2019-07-02 10:42:58 +05:30
}
2019-06-14 15:07:06 +02:00
dataPathMap := & provisionConfig {
2020-07-10 16:40:16 -06:00
DataPathMap : opconfig . NewDatalessDaemonDataPathMap ( cluster . clusterInfo . Namespace , "/var/lib/rook" ),
2019-06-14 15:07:06 +02:00
}
2022-04-24 17:29:47 +02:00
c , err := cluster . provisionPodTemplateSpec ( osdProps , corev1 . RestartPolicyAlways , dataPathMap )
2017-12-21 19:41:50 -08:00
assert . NotNil ( t , c )
2018-05-01 09:01:29 -04:00
assert . Nil ( t , err )
2019-08-05 15:06:47 -06:00
assert . Equal ( t , 1 , len ( c . Spec . InitContainers ))
assert . Equal ( t , 1 , len ( c . Spec . Containers ))
2020-06-04 15:49:40 +09:00
assert . Equal ( t , "custom-scheduler" , c . Spec . SchedulerName )
2019-08-05 15:06:47 -06:00
container := c . Spec . InitContainers [ 0 ]
2018-11-01 11:47:11 -06:00
logger . Infof ( "container: %+v" , container )
2023-07-11 11:17:31 +05:30
assert . Equal ( t , "cp" , container . Command [ 0 ])
2019-08-05 15:06:47 -06:00
container = c . Spec . Containers [ 0 ]
2021-09-23 15:28:46 +02:00
assert . Equal ( t , "/rook/rook" , container . Command [ 0 ])
assert . Equal ( t , "ceph" , container . Args [ 0 ])
assert . Equal ( t , "osd" , container . Args [ 1 ])
assert . Equal ( t , "provision" , container . Args [ 2 ])
2020-12-09 15:09:16 +09:00
for _ , c := range c . Spec . Containers {
vars := operatortest . FindDuplicateEnvVars ( c )
assert . Equal ( t , 0 , len ( vars ))
}
2017-12-21 19:41:50 -08:00
}
func TestDaemonset ( t * testing . T ) {
testPodDevices ( t , "" , "sda" , true )
testPodDevices ( t , "/var/lib/mydatadir" , "sdb" , false )
testPodDevices ( t , "" , "" , true )
testPodDevices ( t , "" , "" , false )
}
2018-05-01 09:01:29 -04:00
func testPodDevices ( t * testing . T , dataDir , deviceName string , allDevices bool ) {
2021-05-14 18:03:38 -06:00
devices := [] cephv1 . Device {
2018-05-01 09:01:29 -04:00
{ Name : deviceName },
}
2017-12-21 19:41:50 -08:00
clientset := fake . NewSimpleClientset ()
2020-07-01 22:46:39 -06:00
clusterInfo := & cephclient . ClusterInfo {
2020-07-10 16:40:16 -06:00
Namespace : "ns" ,
2022-07-01 10:38:15 -06:00
CephVersion : cephver . Quincy ,
2019-04-08 16:37:25 +02:00
}
2021-02-12 17:41:40 -07:00
clusterInfo . SetName ( "test" )
2021-02-18 13:10:11 +00:00
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
2020-07-10 16:40:16 -06:00
context := & clusterd . Context { Clientset : clientset , ConfigDir : "/var/lib/rook" , Executor : & exectest . MockExecutor {}}
spec := cephv1 . ClusterSpec {
2021-07-22 10:33:30 +02:00
CephVersion : cephv1 . CephVersionSpec { Image : "quay.io/ceph/ceph:v15" },
2021-05-14 18:03:38 -06:00
Storage : cephv1 . StorageScopeSpec {
Selection : cephv1 . Selection { UseAllDevices : & allDevices , DeviceFilter : deviceName },
Nodes : [] cephv1 . Node {{ Name : "node1" }},
2020-07-10 16:40:16 -06:00
},
2021-09-22 16:39:09 -06:00
PriorityClassNames : map [ cephv1 . KeyType ] string {
2020-07-10 16:40:16 -06:00
cephv1 . KeyOSD : "my-priority-class" ,
},
2021-05-14 18:03:38 -06:00
Annotations : cephv1 . AnnotationsSpec {
2020-10-07 16:29:25 +02:00
"osd" : map [ string ] string {
"TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES" : "134217728" ,
},
},
2023-01-09 15:47:51 +05:30
DataDirHostPath : "/var/lib/rook/" ,
2020-07-10 16:40:16 -06:00
}
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
2017-12-21 19:41:50 -08:00
2018-05-01 09:01:29 -04:00
devMountNeeded := deviceName != "" || allDevices
2017-12-21 19:41:50 -08:00
2020-07-10 16:40:16 -06:00
n := c . spec . Storage . ResolveNode ( spec . Storage . Nodes [ 0 ]. Name )
2018-05-01 09:01:29 -04:00
if len ( devices ) == 0 && len ( dataDir ) == 0 {
return
}
osd := OSDInfo {
2021-03-02 16:06:34 -07:00
ID : 0 ,
CVMode : "raw" ,
2018-05-01 09:01:29 -04:00
}
2019-07-02 10:42:58 +05:30
osdProp := osdProperties {
crushHostname : n . Name ,
selection : n . Selection ,
2022-04-24 17:29:47 +02:00
resources : corev1 . ResourceRequirements {},
2019-07-02 10:42:58 +05:30
storeConfig : config . StoreConfig {},
2020-06-04 15:49:40 +09:00
schedulerName : "custom-scheduler" ,
2019-07-02 10:42:58 +05:30
}
2019-06-14 15:07:06 +02:00
dataPathMap := & provisionConfig {
2020-07-10 16:40:16 -06:00
DataPathMap : opconfig . NewDatalessDaemonDataPathMap ( c . clusterInfo . Namespace , "/var/lib/rook" ),
2019-06-14 15:07:06 +02:00
}
2020-01-31 15:03:04 +01:00
// Test LVM based on OSD on bare metal
2019-06-14 15:07:06 +02:00
deployment , err := c . makeDeployment ( osdProp , osd , dataPathMap )
2018-05-01 09:01:29 -04:00
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2018-08-28 15:15:57 -05:00
assert . Equal ( t , "rook-ceph-osd-0" , deployment . Name )
2020-07-10 16:40:16 -06:00
assert . Equal ( t , c . clusterInfo . Namespace , deployment . Namespace )
2018-11-29 14:21:25 -07:00
assert . Equal ( t , serviceAccountName , deployment . Spec . Template . Spec . ServiceAccountName )
2018-05-01 09:01:29 -04:00
assert . Equal ( t , int32 ( 1 ), * ( deployment . Spec . Replicas ))
2022-04-24 17:29:47 +02:00
assert . Equal ( t , "node1" , deployment . Spec . Template . Spec . NodeSelector [ corev1 . LabelHostname ])
assert . Equal ( t , corev1 . RestartPolicyAlways , deployment . Spec . Template . Spec . RestartPolicy )
2019-08-04 15:40:29 -05:00
assert . Equal ( t , "my-priority-class" , deployment . Spec . Template . Spec . PriorityClassName )
2018-05-01 09:01:29 -04:00
if devMountNeeded && len ( dataDir ) > 0 {
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 9 , len ( deployment . Spec . Template . Spec . Volumes ))
2017-12-21 19:41:50 -08:00
}
2018-05-01 09:01:29 -04:00
if devMountNeeded && len ( dataDir ) == 0 {
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 9 , len ( deployment . Spec . Template . Spec . Volumes ))
2017-12-21 19:41:50 -08:00
}
2018-05-01 09:01:29 -04:00
if ! devMountNeeded && len ( dataDir ) > 0 {
2019-08-05 15:06:47 -06:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Volumes ))
2017-12-21 19:41:50 -08:00
}
2020-06-04 15:49:40 +09:00
assert . Equal ( t , "custom-scheduler" , deployment . Spec . Template . Spec . SchedulerName )
2017-12-21 19:41:50 -08:00
2018-09-20 15:04:03 -06:00
assert . Equal ( t , "rook-data" , deployment . Spec . Template . Spec . Volumes [ 0 ]. Name )
2017-12-21 19:41:50 -08:00
2019-08-27 17:08:26 +05:30
assert . Equal ( t , AppName , deployment . Spec . Template . ObjectMeta . Name )
assert . Equal ( t , AppName , deployment . Spec . Template . ObjectMeta . Labels [ "app" ])
2020-07-10 16:40:16 -06:00
assert . Equal ( t , c . clusterInfo . Namespace , deployment . Spec . Template . ObjectMeta . Labels [ "rook_cluster" ])
2020-10-07 16:29:25 +02:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . ObjectMeta . Annotations ))
2018-05-01 09:01:29 -04:00
2022-11-15 07:17:57 +00:00
assert . Equal ( t , 3 , len ( deployment . Spec . Template . Spec . InitContainers ))
2018-07-31 14:39:53 -06:00
initCont := deployment . Spec . Template . Spec . InitContainers [ 0 ]
2021-07-22 10:33:30 +02:00
assert . Equal ( t , "quay.io/ceph/ceph:v15" , initCont . Image )
2020-01-31 15:03:04 +01:00
assert . Equal ( t , "activate" , initCont . Name )
2021-06-21 17:05:07 +05:30
assert . Equal ( t , 4 , len ( initCont . VolumeMounts ))
2022-12-22 07:43:15 +00:00
initCont = deployment . Spec . Template . Spec . InitContainers [ 1 ]
assert . Equal ( t , "quay.io/ceph/ceph:v15" , initCont . Image )
2022-11-15 07:17:57 +00:00
assert . Equal ( t , "expand-bluefs" , initCont . Name )
assert . Equal ( t , 2 , len ( initCont . VolumeMounts ))
initCont = deployment . Spec . Template . Spec . InitContainers [ 2 ]
assert . Equal ( t , "quay.io/ceph/ceph:v15" , initCont . Image )
2022-12-22 07:43:15 +00:00
assert . Equal ( t , "chown-container-data-dir" , initCont . Name )
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 8 , len ( initCont . VolumeMounts ))
2018-07-31 14:39:53 -06:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
2018-05-01 09:01:29 -04:00
cont := deployment . Spec . Template . Spec . Containers [ 0 ]
2020-07-10 16:40:16 -06:00
assert . Equal ( t , spec . CephVersion . Image , cont . Image )
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 8 , len ( cont . VolumeMounts ))
2023-10-10 21:25:45 +05:30
assert . Equal ( t , "ceph-osd" , cont . Command [ 0 ])
2020-10-07 16:29:25 +02:00
verifyEnvVar ( t , cont . Env , "TCMALLOC_MAX_TOTAL_THREAD_CACHE_BYTES" , "134217728" , true )
2020-01-31 15:03:04 +01:00
// Test OSD on PVC with LVM
osdProp = osdProperties {
crushHostname : n . Name ,
selection : n . Selection ,
2022-04-24 17:29:47 +02:00
resources : corev1 . ResourceRequirements {},
2020-01-31 15:03:04 +01:00
storeConfig : config . StoreConfig {},
2022-04-24 17:29:47 +02:00
pvc : corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc" },
2020-01-31 15:03:04 +01:00
}
// Not needed when running on PVC
osd = OSDInfo {
ID : 0 ,
CVMode : "lvm" ,
}
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2024-04-19 09:04:47 -06:00
assert . Equal ( t , 4 , len ( deployment . Spec . Template . Spec . InitContainers ), deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
2020-01-31 15:03:04 +01:00
assert . Equal ( t , "config-init" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "copy-bins" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
2024-04-19 09:04:47 -06:00
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
2020-01-31 15:03:04 +01:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
initCont = deployment . Spec . Template . Spec . InitContainers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 5 , len ( initCont . VolumeMounts ), initCont . VolumeMounts )
2020-01-31 15:03:04 +01:00
blkInitCont := deployment . Spec . Template . Spec . InitContainers [ 2 ]
assert . Equal ( t , 1 , len ( blkInitCont . VolumeDevices ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 9 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-01-31 15:03:04 +01:00
// Test OSD on PVC with RAW
osd = OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2020-02-11 18:33:50 +01:00
assert . Equal ( t , 4 , len ( deployment . Spec . Template . Spec . InitContainers ), deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
2020-01-31 15:03:04 +01:00
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
2020-02-11 18:33:50 +01:00
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
2020-01-31 15:03:04 +01:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 7 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-01-31 15:03:04 +01:00
2020-08-19 18:45:31 +02:00
// Test with encrypted OSD on PVC with RAW
osdProp . encrypted = true
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2020-10-06 17:56:26 +02:00
assert . Equal ( t , 8 , len ( deployment . Spec . Template . Spec . InitContainers ), deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "encryption-open" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "blkdevmapper-encryption" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "encrypted-block-status" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "expand-encrypted-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
2021-03-24 10:27:51 +01:00
assert . Equal ( t , 2 , len ( deployment . Spec . Template . Spec . InitContainers [ 4 ]. VolumeMounts ), deployment . Spec . Template . Spec . InitContainers [ 4 ]. VolumeMounts )
assert . Equal ( t , "dev-mapper" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. VolumeMounts [ 1 ]. Name , deployment . Spec . Template . Spec . InitContainers [ 4 ]. VolumeMounts )
2020-10-06 17:56:26 +02:00
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 5 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 6 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 7 ]. Name )
2020-08-19 18:45:31 +02:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 8 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-08-19 18:45:31 +02:00
osdProp . encrypted = false
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 10 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes )
2020-08-19 18:45:31 +02:00
// // Test OSD on PVC with RAW and metadata device
osd = OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
2022-04-24 17:29:47 +02:00
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc-metadata" }
2020-08-19 18:45:31 +02:00
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
assert . Equal ( t , 5 , len ( deployment . Spec . Template . Spec . InitContainers ))
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "blkdevmapper-metadata" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 7 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-08-19 18:45:31 +02:00
blkInitCont = deployment . Spec . Template . Spec . InitContainers [ 1 ]
assert . Equal ( t , 1 , len ( blkInitCont . VolumeDevices ))
blkMetaInitCont := deployment . Spec . Template . Spec . InitContainers [ 2 ]
assert . Equal ( t , 1 , len ( blkMetaInitCont . VolumeDevices ))
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 10 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes )
2020-08-19 18:45:31 +02:00
// // Test encrypted OSD on PVC with RAW and metadata device
osd = OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
osdProp . encrypted = true
2022-04-24 17:29:47 +02:00
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc-metadata" }
2020-08-19 18:45:31 +02:00
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2020-10-06 17:56:26 +02:00
assert . Equal ( t , 11 , len ( deployment . Spec . Template . Spec . InitContainers ))
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "blkdevmapper-metadata" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "encryption-open" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "encryption-open-metadata" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "blkdevmapper-encryption" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
assert . Equal ( t , "blkdevmapper-metadata-encryption" , deployment . Spec . Template . Spec . InitContainers [ 5 ]. Name )
assert . Equal ( t , "encrypted-block-status" , deployment . Spec . Template . Spec . InitContainers [ 6 ]. Name )
assert . Equal ( t , "expand-encrypted-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 7 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 8 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 9 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 10 ]. Name )
2020-08-19 18:45:31 +02:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 8 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-08-19 18:45:31 +02:00
blkInitCont = deployment . Spec . Template . Spec . InitContainers [ 1 ]
assert . Equal ( t , 1 , len ( blkInitCont . VolumeDevices ))
2020-10-06 17:56:26 +02:00
blkMetaInitCont = deployment . Spec . Template . Spec . InitContainers [ 8 ]
2020-08-19 18:45:31 +02:00
assert . Equal ( t , 1 , len ( blkMetaInitCont . VolumeDevices ))
osdProp . encrypted = false
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 12 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes )
2020-08-19 18:45:31 +02:00
// // Test OSD on PVC with RAW / metadata and wal device
2020-01-31 15:03:04 +01:00
osd = OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
2022-04-24 17:29:47 +02:00
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc-metadata" }
osdProp . walPVC = corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc-wal" }
2020-01-31 15:03:04 +01:00
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2020-08-09 23:27:50 +08:00
assert . Equal ( t , 6 , len ( deployment . Spec . Template . Spec . InitContainers ))
2020-01-31 15:03:04 +01:00
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "blkdevmapper-metadata" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
2020-08-09 23:27:50 +08:00
assert . Equal ( t , "blkdevmapper-wal" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 5 ]. Name )
2020-01-31 15:03:04 +01:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 7 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-01-31 15:03:04 +01:00
blkInitCont = deployment . Spec . Template . Spec . InitContainers [ 1 ]
assert . Equal ( t , 1 , len ( blkInitCont . VolumeDevices ))
2020-08-19 18:45:31 +02:00
blkMetaInitCont = deployment . Spec . Template . Spec . InitContainers [ 2 ]
assert . Equal ( t , 1 , len ( blkMetaInitCont . VolumeDevices ))
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 12 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes )
2020-08-19 18:45:31 +02:00
// // Test encrypted OSD on PVC with RAW / metadata and wal device
osd = OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
osdProp . encrypted = true
2022-04-24 17:29:47 +02:00
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc-metadata" }
osdProp . walPVC = corev1 . PersistentVolumeClaimVolumeSource { ClaimName : "mypvc-wal" }
2020-08-19 18:45:31 +02:00
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2020-10-06 17:56:26 +02:00
assert . Equal ( t , 14 , len ( deployment . Spec . Template . Spec . InitContainers ))
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "blkdevmapper-metadata" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "blkdevmapper-wal" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "encryption-open" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "encryption-open-metadata" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
assert . Equal ( t , "encryption-open-wal" , deployment . Spec . Template . Spec . InitContainers [ 5 ]. Name )
assert . Equal ( t , "blkdevmapper-encryption" , deployment . Spec . Template . Spec . InitContainers [ 6 ]. Name )
assert . Equal ( t , "blkdevmapper-metadata-encryption" , deployment . Spec . Template . Spec . InitContainers [ 7 ]. Name )
assert . Equal ( t , "blkdevmapper-wal-encryption" , deployment . Spec . Template . Spec . InitContainers [ 8 ]. Name )
assert . Equal ( t , "encrypted-block-status" , deployment . Spec . Template . Spec . InitContainers [ 9 ]. Name )
assert . Equal ( t , "expand-encrypted-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 10 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 11 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 12 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 13 ]. Name )
2020-08-19 18:45:31 +02:00
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 8 , len ( cont . VolumeMounts ), cont . VolumeMounts )
2020-08-19 18:45:31 +02:00
blkInitCont = deployment . Spec . Template . Spec . InitContainers [ 1 ]
assert . Equal ( t , 1 , len ( blkInitCont . VolumeDevices ))
2020-10-06 17:56:26 +02:00
blkMetaInitCont = deployment . Spec . Template . Spec . InitContainers [ 11 ]
2020-01-31 15:03:04 +01:00
assert . Equal ( t , 1 , len ( blkMetaInitCont . VolumeDevices ))
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 14 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes )
2020-10-06 17:56:26 +02:00
// Test with encrypted OSD on PVC with RAW with KMS
osdProp . encrypted = true
2022-04-24 17:29:47 +02:00
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource {}
osdProp . walPVC = corev1 . PersistentVolumeClaimVolumeSource {}
2020-10-06 17:56:26 +02:00
c . spec . Security . KeyManagementService . ConnectionDetails = map [ string ] string { "KMS_PROVIDER" : "vault" }
c . spec . Security . KeyManagementService . TokenSecretName = "vault-token"
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
assert . Equal ( t , 9 , len ( deployment . Spec . Template . Spec . InitContainers ), deployment . Spec . Template . Spec . InitContainers )
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "encryption-kms-get-kek" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "encryption-open" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "blkdevmapper-encryption" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "encrypted-block-status" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
assert . Equal ( t , "expand-encrypted-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 5 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 6 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 7 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 8 ]. Name )
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 8 , len ( cont . VolumeMounts ), cont . VolumeMounts )
assert . Equal ( t , 10 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes ) // One more than the encryption with k8s for the kek get init container
2020-10-06 17:56:26 +02:00
2022-09-02 11:13:43 +05:30
// Test with encrypted OSD on PVC with RAW with KMS
osdProp . encrypted = true
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource {}
osdProp . walPVC = corev1 . PersistentVolumeClaimVolumeSource {}
c . spec . Security . KeyManagementService . ConnectionDetails = map [ string ] string { "KMS_PROVIDER" : "kmip" }
c . spec . Security . KeyManagementService . TokenSecretName = "kmip-credentials"
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
assert . Equal ( t , 9 , len ( deployment . Spec . Template . Spec . InitContainers ), deployment . Spec . Template . Spec . InitContainers )
assert . Equal ( t , "blkdevmapper" , deployment . Spec . Template . Spec . InitContainers [ 0 ]. Name )
assert . Equal ( t , "encryption-kms-get-kek" , deployment . Spec . Template . Spec . InitContainers [ 1 ]. Name )
assert . Equal ( t , "encryption-open" , deployment . Spec . Template . Spec . InitContainers [ 2 ]. Name )
assert . Equal ( t , "blkdevmapper-encryption" , deployment . Spec . Template . Spec . InitContainers [ 3 ]. Name )
assert . Equal ( t , "encrypted-block-status" , deployment . Spec . Template . Spec . InitContainers [ 4 ]. Name )
assert . Equal ( t , "expand-encrypted-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 5 ]. Name )
assert . Equal ( t , "activate" , deployment . Spec . Template . Spec . InitContainers [ 6 ]. Name )
assert . Equal ( t , "expand-bluefs" , deployment . Spec . Template . Spec . InitContainers [ 7 ]. Name )
assert . Equal ( t , "chown-container-data-dir" , deployment . Spec . Template . Spec . InitContainers [ 8 ]. Name )
assert . Equal ( t , 1 , len ( deployment . Spec . Template . Spec . Containers ))
cont = deployment . Spec . Template . Spec . Containers [ 0 ]
2022-11-16 17:57:23 +05:30
assert . Equal ( t , 8 , len ( cont . VolumeMounts ), cont . VolumeMounts )
assert . Equal ( t , 11 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes )
2022-09-02 11:13:43 +05:30
2020-10-06 17:56:26 +02:00
// Test with encrypted OSD on PVC with RAW with KMS with TLS
osdProp . encrypted = true
2022-04-24 17:29:47 +02:00
osdProp . metadataPVC = corev1 . PersistentVolumeClaimVolumeSource {}
osdProp . walPVC = corev1 . PersistentVolumeClaimVolumeSource {}
2020-10-06 17:56:26 +02:00
c . spec . Security . KeyManagementService . ConnectionDetails = map [ string ] string { "KMS_PROVIDER" : "vault" , "VAULT_CACERT" : "vault-ca-cert-secret" , "VAULT_CLIENT_CERT" : "vault-client-cert-secret" , "VAULT_CLIENT_KEY" : "vault-client-key-secret" }
c . spec . Security . KeyManagementService . TokenSecretName = "vault-token"
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
2022-11-16 17:57:23 +05:30
assert . Equal ( t , 11 , len ( deployment . Spec . Template . Spec . Volumes ), deployment . Spec . Template . Spec . Volumes ) // One more than the encryption with k8s for the kek get init container
2023-01-09 15:47:51 +05:30
assert . Equal ( t , 3 , len ( deployment . Spec . Template . Spec . Volumes [ 8 ]. VolumeSource . Projected . Sources ), deployment . Spec . Template . Spec . Volumes [ 0 ]) // 3 more since we have the tls secrets
2020-10-06 17:56:26 +02:00
osdProp . encrypted = false
2020-09-22 16:48:08 +05:30
// Test tune Fast settings when OSD on PVC
osdProp . tuneFastDeviceClass = true
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . NoError ( t , err )
2021-01-26 14:47:35 -07:00
for _ , flag := range defaultTuneFastSettings {
2023-10-10 21:25:45 +05:30
assert . Contains ( t , deployment . Spec . Template . Spec . Containers [ 0 ]. Args , flag )
2020-09-22 16:48:08 +05:30
}
// Test tune Slow settings when OSD on PVC
osdProp . tuneSlowDeviceClass = true
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . NoError ( t , err )
2021-01-26 14:47:35 -07:00
for _ , flag := range defaultTuneSlowSettings {
2023-10-10 21:25:45 +05:30
assert . Contains ( t , deployment . Spec . Template . Spec . Containers [ 0 ]. Args , flag )
2020-09-22 16:48:08 +05:30
}
2021-02-01 18:23:19 +01:00
// Test shareProcessNamespace presence
2022-07-01 10:38:15 -06:00
// We don't need to use the host PID namespace anymore
2021-08-26 16:43:42 +05:30
assert . False ( t , deployment . Spec . Template . Spec . HostPID )
2021-02-01 18:23:19 +01:00
if deployment . Spec . Template . Spec . ShareProcessNamespace != nil {
panic ( "ShareProcessNamespace should be nil" )
}
// Turn on log collector
c . spec . LogCollector . Enabled = true
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . NoError ( t , err )
2021-08-26 16:43:42 +05:30
assert . False ( t , deployment . Spec . Template . Spec . HostPID , deployment . Spec . Template . Spec . HostPID )
if deployment . Spec . Template . Spec . ShareProcessNamespace == nil {
2021-02-01 18:23:19 +01:00
panic ( "ShareProcessNamespace should be nil" )
}
2022-07-01 10:38:15 -06:00
t . Run (( "check hostpid and shareprocessnamespace" ), func ( t * testing . T ) {
2021-02-01 18:23:19 +01:00
clusterInfo := & cephclient . ClusterInfo {
Namespace : "ns" ,
2022-07-01 10:38:15 -06:00
CephVersion : cephver . Quincy ,
2021-02-01 18:23:19 +01:00
}
2021-02-12 17:41:40 -07:00
clusterInfo . SetName ( "test" )
2021-02-18 13:10:11 +00:00
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
2021-02-01 18:23:19 +01:00
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . NoError ( t , err )
assert . False ( t , deployment . Spec . Template . Spec . HostPID , deployment . Spec . Template . Spec . HostPID )
// Turn on log collector
c . spec . LogCollector . Enabled = true
deployment , err = c . makeDeployment ( osdProp , osd , dataPathMap )
assert . NoError ( t , err )
shareProcessNamespace := * deployment . Spec . Template . Spec . ShareProcessNamespace
assert . True ( t , shareProcessNamespace )
2022-07-01 10:38:15 -06:00
})
2021-02-01 18:23:19 +01:00
2022-02-03 20:26:33 +05:30
t . Run (( "check osd ConfigureProbe" ), func ( t * testing . T ) {
c . spec . HealthCheck . StartupProbe = make ( map [ cephv1 . KeyType ] * cephv1 . ProbeSpec )
2022-04-24 17:29:47 +02:00
c . spec . HealthCheck . StartupProbe [ cephv1 . KeyOSD ] = & cephv1 . ProbeSpec { Disabled : false , Probe : & corev1 . Probe { InitialDelaySeconds : 1000 }}
2022-02-03 20:26:33 +05:30
c . spec . HealthCheck . LivenessProbe = make ( map [ cephv1 . KeyType ] * cephv1 . ProbeSpec )
2022-04-24 17:29:47 +02:00
c . spec . HealthCheck . LivenessProbe [ cephv1 . KeyOSD ] = & cephv1 . ProbeSpec { Disabled : false , Probe : & corev1 . Probe { InitialDelaySeconds : 900 }}
2022-02-03 20:26:33 +05:30
deployment , err := c . makeDeployment ( osdProp , osd , dataPathMap )
assert . Nil ( t , err )
assert . NotNil ( t , deployment )
assert . NotNil ( t , deployment . Spec . Template . Spec . Containers [ 0 ]. LivenessProbe )
assert . NotNil ( t , deployment . Spec . Template . Spec . Containers [ 0 ]. StartupProbe )
assert . Equal ( t , int32 ( 900 ), deployment . Spec . Template . Spec . Containers [ 0 ]. LivenessProbe . InitialDelaySeconds )
assert . Equal ( t , int32 ( 1000 ), deployment . Spec . Template . Spec . Containers [ 0 ]. StartupProbe . InitialDelaySeconds )
})
2017-12-21 19:41:50 -08:00
}
2022-04-24 17:29:47 +02:00
func verifyEnvVar ( t * testing . T , envVars [] corev1 . EnvVar , expectedName , expectedValue string , expectedFound bool ) {
2017-12-21 19:41:50 -08:00
found := false
for _ , envVar := range envVars {
if envVar . Name == expectedName {
assert . Equal ( t , expectedValue , envVar . Value )
found = true
break
}
}
assert . Equal ( t , expectedFound , found )
}
func TestStorageSpecConfig ( t * testing . T ) {
2020-07-10 16:40:16 -06:00
clientset := fake . NewSimpleClientset ()
clusterInfo := & cephclient . ClusterInfo {
Namespace : "ns" ,
2022-07-01 10:38:15 -06:00
CephVersion : cephver . Quincy ,
2020-07-10 16:40:16 -06:00
}
2021-02-12 17:41:40 -07:00
clusterInfo . SetName ( "testing" )
2021-02-18 13:10:11 +00:00
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
2020-07-10 16:40:16 -06:00
context := & clusterd . Context { Clientset : clientset , ConfigDir : "/var/lib/rook" , Executor : & exectest . MockExecutor {}}
spec := cephv1 . ClusterSpec {
DataDirHostPath : context . ConfigDir ,
2021-05-14 18:03:38 -06:00
Storage : cephv1 . StorageScopeSpec {
2020-05-14 11:58:23 +02:00
Config : map [ string ] string {
"crushRoot" : "custom-root" ,
},
2021-05-14 18:03:38 -06:00
Nodes : [] cephv1 . Node {
2020-07-10 16:40:16 -06:00
{
Name : "node1" ,
Config : map [ string ] string {
"databaseSizeMB" : "10" ,
"walSizeMB" : "20" ,
"metadataDevice" : "nvme093" ,
2017-12-21 19:41:50 -08:00
},
2021-05-14 18:03:38 -06:00
Selection : cephv1 . Selection {},
2022-04-24 17:29:47 +02:00
Resources : corev1 . ResourceRequirements {
Limits : corev1 . ResourceList {
corev1 . ResourceCPU : * resource . NewQuantity ( 1024.0 , resource . BinarySI ),
corev1 . ResourceMemory : * resource . NewQuantity ( 4096.0 , resource . BinarySI ),
2020-07-10 16:40:16 -06:00
},
2022-04-24 17:29:47 +02:00
Requests : corev1 . ResourceList {
corev1 . ResourceCPU : * resource . NewQuantity ( 500.0 , resource . BinarySI ),
corev1 . ResourceMemory : * resource . NewQuantity ( 2048.0 , resource . BinarySI ),
2020-07-10 16:40:16 -06:00
},
2017-12-21 19:41:50 -08:00
},
},
},
},
}
2020-07-10 16:40:16 -06:00
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
n := c . spec . Storage . ResolveNode ( spec . Storage . Nodes [ 0 ]. Name )
storeConfig := config . ToStoreConfig ( spec . Storage . Nodes [ 0 ]. Config )
metadataDevice := config . MetadataDevice ( spec . Storage . Nodes [ 0 ]. Config )
2017-12-21 19:41:50 -08:00
2019-07-02 10:42:58 +05:30
osdProp := osdProperties {
crushHostname : n . Name ,
devices : n . Devices ,
selection : n . Selection ,
2020-07-10 16:40:16 -06:00
resources : c . spec . Storage . Nodes [ 0 ]. Resources ,
2019-07-02 10:42:58 +05:30
storeConfig : storeConfig ,
metadataDevice : metadataDevice ,
}
2019-06-14 15:07:06 +02:00
dataPathMap := & provisionConfig {
2020-07-10 16:40:16 -06:00
DataPathMap : opconfig . NewDatalessDaemonDataPathMap ( c . clusterInfo . Namespace , "/var/lib/rook" ),
2019-06-14 15:07:06 +02:00
}
job , err := c . makeJob ( osdProp , dataPathMap )
2018-05-01 09:01:29 -04:00
assert . NotNil ( t , job )
assert . Nil ( t , err )
2018-07-19 10:32:54 +02:00
assert . Equal ( t , "rook-ceph-osd-prepare-node1" , job . ObjectMeta . Name )
2019-08-05 15:06:47 -06:00
container := job . Spec . Template . Spec . InitContainers [ 0 ]
2017-12-21 19:41:50 -08:00
assert . NotNil ( t , container )
2019-08-05 15:06:47 -06:00
container = job . Spec . Template . Spec . Containers [ 0 ]
2018-11-01 11:47:11 -06:00
assert . NotNil ( t , container )
2018-05-18 14:32:20 -07:00
verifyEnvVar ( t , container . Env , "ROOK_OSD_DATABASE_SIZE" , "10" , true )
verifyEnvVar ( t , container . Env , "ROOK_OSD_WAL_SIZE" , "20" , true )
2018-05-24 21:34:18 -07:00
verifyEnvVar ( t , container . Env , "ROOK_METADATA_DEVICE" , "nvme093" , true )
2020-05-14 11:58:23 +02:00
verifyEnvVar ( t , container . Env , CrushRootVarName , "custom-root" , true )
2017-12-21 19:41:50 -08:00
}
func TestHostNetwork ( t * testing . T ) {
2021-05-14 18:03:38 -06:00
storageSpec := cephv1 . StorageScopeSpec {
Nodes : [] cephv1 . Node {
2017-12-21 19:41:50 -08:00
{
2019-11-04 17:12:36 -07:00
Name : "node1" ,
2018-05-18 14:32:20 -07:00
Config : map [ string ] string {
"databaseSizeMB" : "10" ,
"walSizeMB" : "20" ,
2017-12-21 19:41:50 -08:00
},
},
},
}
clientset := fake . NewSimpleClientset ()
2020-07-01 22:46:39 -06:00
clusterInfo := & cephclient . ClusterInfo {
2020-07-10 16:40:16 -06:00
Namespace : "ns" ,
2022-07-01 10:38:15 -06:00
CephVersion : cephver . Quincy ,
2019-04-08 16:37:25 +02:00
}
2021-02-12 17:41:40 -07:00
clusterInfo . SetName ( "test" )
2021-02-18 13:10:11 +00:00
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
2020-07-10 16:40:16 -06:00
context := & clusterd . Context { Clientset : clientset , ConfigDir : "/var/lib/rook" , Executor : & exectest . MockExecutor {}}
spec := cephv1 . ClusterSpec {
Storage : storageSpec ,
Network : cephv1 . NetworkSpec { HostNetwork : true },
}
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
2017-12-21 19:41:50 -08:00
2020-07-10 16:40:16 -06:00
n := c . spec . Storage . ResolveNode ( storageSpec . Nodes [ 0 ]. Name )
2018-05-01 09:01:29 -04:00
osd := OSDInfo {
2021-03-02 16:06:34 -07:00
ID : 0 ,
CVMode : "raw" ,
2018-05-01 09:01:29 -04:00
}
2019-07-02 10:42:58 +05:30
osdProp := osdProperties {
crushHostname : n . Name ,
devices : n . Devices ,
selection : n . Selection ,
2020-07-10 16:40:16 -06:00
resources : c . spec . Storage . Nodes [ 0 ]. Resources ,
2019-07-02 10:42:58 +05:30
storeConfig : config . StoreConfig {},
}
2019-06-14 15:07:06 +02:00
dataPathMap := & provisionConfig {
2020-07-10 16:40:16 -06:00
DataPathMap : opconfig . NewDatalessDaemonDataPathMap ( c . clusterInfo . Namespace , "/var/lib/rook" ),
2019-06-14 15:07:06 +02:00
}
r , err := c . makeDeployment ( osdProp , osd , dataPathMap )
2017-12-21 19:41:50 -08:00
assert . NotNil ( t , r )
2018-05-01 09:01:29 -04:00
assert . Nil ( t , err )
2017-12-21 19:41:50 -08:00
2018-08-28 15:15:57 -05:00
assert . Equal ( t , "rook-ceph-osd-0" , r . ObjectMeta . Name )
2017-12-21 19:41:50 -08:00
assert . Equal ( t , true , r . Spec . Template . Spec . HostNetwork )
2022-04-24 17:29:47 +02:00
assert . Equal ( t , corev1 . DNSClusterFirstWithHostNet , r . Spec . Template . Spec . DNSPolicy )
2017-12-21 19:41:50 -08:00
}
2019-06-17 13:59:16 +02:00
2019-10-11 11:08:14 +02:00
func TestOsdPrepareResources ( t * testing . T ) {
clientset := fake . NewSimpleClientset ()
2020-07-10 16:40:16 -06:00
context := & clusterd . Context { Clientset : clientset , ConfigDir : "/var/lib/rook" , Executor : & exectest . MockExecutor {}}
clusterInfo := & cephclient . ClusterInfo { Namespace : "ns" }
2021-02-12 17:41:40 -07:00
clusterInfo . SetName ( "test" )
2021-02-18 13:10:11 +00:00
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
2020-07-10 16:40:16 -06:00
spec := cephv1 . ClusterSpec {
2022-04-24 17:29:47 +02:00
Resources : map [ string ] corev1 . ResourceRequirements { "prepareosd" : {
Limits : corev1 . ResourceList {
corev1 . ResourceCPU : * resource . NewQuantity ( 2000.0 , resource . BinarySI ),
2020-07-10 16:40:16 -06:00
},
2022-04-24 17:29:47 +02:00
Requests : corev1 . ResourceList {
corev1 . ResourceMemory : * resource . NewQuantity ( 250.0 , resource . BinarySI ),
2020-07-10 16:40:16 -06:00
},
2019-10-11 11:08:14 +02:00
},
},
}
2020-07-10 16:40:16 -06:00
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
2019-10-11 11:08:14 +02:00
2020-07-10 16:40:16 -06:00
r := cephv1 . GetPrepareOSDResources ( c . spec . Resources )
assert . Equal ( t , "2000" , r . Limits . Cpu (). String ())
2019-10-11 11:08:14 +02:00
assert . Equal ( t , "0" , r . Requests . Cpu (). String ())
assert . Equal ( t , "0" , r . Limits . Memory (). String ())
assert . Equal ( t , "250" , r . Requests . Memory (). String ())
}
2020-08-05 13:34:06 +02:00
func TestClusterGetPVCEncryptionOpenInitContainerActivate ( t * testing . T ) {
2021-02-18 13:10:11 +00:00
c := New ( & clusterd . Context {}, & cephclient . ClusterInfo { OwnerInfo : & k8sutil . OwnerInfo {}}, cephv1 . ClusterSpec {}, "rook/rook:myversion" )
2020-08-05 13:34:06 +02:00
osdProperties := osdProperties {
2022-04-24 17:29:47 +02:00
pvc : corev1 . PersistentVolumeClaimVolumeSource {
2020-08-05 13:34:06 +02:00
ClaimName : "pvc1" ,
},
}
2020-10-06 17:56:26 +02:00
mountPath := "/var/lib/ceph/osd/ceph-0"
2020-08-05 13:34:06 +02:00
// No metadata PVC
2020-10-06 17:56:26 +02:00
containers := c . getPVCEncryptionOpenInitContainerActivate ( mountPath , osdProperties )
2020-08-05 13:34:06 +02:00
assert . Equal ( t , 1 , len ( containers ))
// With metadata PVC
2020-08-13 10:39:39 +02:00
osdProperties . metadataPVC . ClaimName = "pvcDB"
2020-10-06 17:56:26 +02:00
containers = c . getPVCEncryptionOpenInitContainerActivate ( mountPath , osdProperties )
2020-08-05 13:34:06 +02:00
assert . Equal ( t , 2 , len ( containers ))
2020-08-13 10:39:39 +02:00
// With wal PVC
osdProperties . walPVC . ClaimName = "pvcWal"
2020-10-06 17:56:26 +02:00
containers = c . getPVCEncryptionOpenInitContainerActivate ( mountPath , osdProperties )
2020-08-13 10:39:39 +02:00
assert . Equal ( t , 3 , len ( containers ))
2020-08-05 13:34:06 +02:00
}
func TestClusterGetPVCEncryptionInitContainerActivate ( t * testing . T ) {
2021-02-18 13:10:11 +00:00
c := New ( & clusterd . Context {}, & cephclient . ClusterInfo { OwnerInfo : & k8sutil . OwnerInfo {}}, cephv1 . ClusterSpec {}, "rook/rook:myversion" )
2020-08-05 13:34:06 +02:00
osdProperties := osdProperties {
2022-04-24 17:29:47 +02:00
pvc : corev1 . PersistentVolumeClaimVolumeSource {
2020-08-05 13:34:06 +02:00
ClaimName : "pvc1" ,
},
2022-04-24 17:29:47 +02:00
resources : corev1 . ResourceRequirements {},
2020-08-05 13:34:06 +02:00
}
mountPath := "/var/lib/ceph/osd/ceph-0"
// No metadata PVC
containers := c . getPVCEncryptionInitContainerActivate ( mountPath , osdProperties )
assert . Equal ( t , 1 , len ( containers ))
// With metadata PVC
2020-08-13 10:39:39 +02:00
osdProperties . metadataPVC . ClaimName = "pvcDB"
2020-08-05 13:34:06 +02:00
containers = c . getPVCEncryptionInitContainerActivate ( mountPath , osdProperties )
assert . Equal ( t , 2 , len ( containers ))
2020-08-13 10:39:39 +02:00
// With wal PVC
osdProperties . walPVC . ClaimName = "pvcWal"
containers = c . getPVCEncryptionInitContainerActivate ( mountPath , osdProperties )
assert . Equal ( t , 3 , len ( containers ))
2020-08-05 13:34:06 +02:00
}
2021-03-02 16:06:34 -07:00
2021-05-03 11:54:46 -06:00
// WARNING! modifies c.deviceSets
2021-03-02 16:06:34 -07:00
func getDummyDeploymentOnPVC ( clientset * fake . Clientset , c * Cluster , pvcName string , osdID int ) * appsv1 . Deployment {
osd := OSDInfo {
ID : osdID ,
UUID : "some-uuid" ,
BlockPath : "/some/path" ,
CVMode : "raw" ,
2023-06-22 09:59:34 +05:30
Store : "bluestore" ,
2021-03-02 16:06:34 -07:00
}
2021-05-03 11:54:46 -06:00
c . deviceSets = append ( c . deviceSets , deviceSet {
2021-03-02 16:06:34 -07:00
Name : pvcName ,
2022-04-24 17:29:47 +02:00
PVCSources : map [ string ] corev1 . PersistentVolumeClaimVolumeSource {
2021-03-02 16:06:34 -07:00
bluestorePVCData : { ClaimName : pvcName },
},
Portable : true ,
})
config := c . newProvisionConfig ()
d , err := deploymentOnPVC ( c , osd , pvcName , config )
if err != nil {
panic ( err )
}
return d
}
// WARNING! modifies c.ValidStorage
func getDummyDeploymentOnNode ( clientset * fake . Clientset , c * Cluster , nodeName string , osdID int ) * appsv1 . Deployment {
osd := OSDInfo {
ID : osdID ,
UUID : "some-uuid" ,
BlockPath : "/dev/vda" ,
CVMode : "raw" ,
2023-06-22 09:59:34 +05:30
Store : "bluestore" ,
2021-03-02 16:06:34 -07:00
}
2021-05-14 18:03:38 -06:00
c . ValidStorage . Nodes = append ( c . ValidStorage . Nodes , cephv1 . Node { Name : nodeName })
2021-03-02 16:06:34 -07:00
config := c . newProvisionConfig ()
d , err := deploymentOnNode ( c , osd , nodeName , config )
if err != nil {
panic ( err )
}
return d
}
2021-07-26 14:58:23 +05:30
func TestOSDPlacement ( t * testing . T ) {
clientset := fake . NewSimpleClientset ()
clusterInfo := & cephclient . ClusterInfo {
Namespace : "ns" ,
2022-07-01 10:38:15 -06:00
CephVersion : cephver . Quincy ,
2021-07-26 14:58:23 +05:30
}
clusterInfo . SetName ( "testing" )
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
context := & clusterd . Context { Clientset : clientset , ConfigDir : "/var/lib/rook" , Executor : & exectest . MockExecutor {}}
spec := cephv1 . ClusterSpec {
Placement : cephv1 . PlacementSpec {
"all" : {
2022-04-24 17:29:47 +02:00
NodeAffinity : & corev1 . NodeAffinity {
RequiredDuringSchedulingIgnoredDuringExecution : & corev1 . NodeSelector {
NodeSelectorTerms : [] corev1 . NodeSelectorTerm {
2021-07-26 14:58:23 +05:30
{
2022-04-24 17:29:47 +02:00
MatchExpressions : [] corev1 . NodeSelectorRequirement {{
2021-07-26 14:58:23 +05:30
Key : "role" ,
2022-04-24 17:29:47 +02:00
Operator : corev1 . NodeSelectorOpIn ,
2021-07-26 14:58:23 +05:30
Values : [] string { "storage-node1" },
}},
},
},
},
},
},
"osd" : {
2022-04-24 17:29:47 +02:00
NodeAffinity : & corev1 . NodeAffinity {
RequiredDuringSchedulingIgnoredDuringExecution : & corev1 . NodeSelector {
NodeSelectorTerms : [] corev1 . NodeSelectorTerm {
2021-07-26 14:58:23 +05:30
{
2022-04-24 17:29:47 +02:00
MatchExpressions : [] corev1 . NodeSelectorRequirement {{
2021-07-26 14:58:23 +05:30
Key : "role" ,
2022-04-24 17:29:47 +02:00
Operator : corev1 . NodeSelectorOpIn ,
2021-07-26 14:58:23 +05:30
Values : [] string { "storage-node1" },
}},
},
},
},
},
},
"prepareosd" : {
2022-04-24 17:29:47 +02:00
NodeAffinity : & corev1 . NodeAffinity {
RequiredDuringSchedulingIgnoredDuringExecution : & corev1 . NodeSelector {
NodeSelectorTerms : [] corev1 . NodeSelectorTerm {
2021-07-26 14:58:23 +05:30
{
2022-04-24 17:29:47 +02:00
MatchExpressions : [] corev1 . NodeSelectorRequirement {{
2021-07-26 14:58:23 +05:30
Key : "role" ,
2022-04-24 17:29:47 +02:00
Operator : corev1 . NodeSelectorOpIn ,
2021-07-26 14:58:23 +05:30
Values : [] string { "storage-node1" },
}},
},
},
},
},
},
},
Storage : cephv1 . StorageScopeSpec {
OnlyApplyOSDPlacement : false ,
},
}
osdProps := osdProperties {
2022-04-24 17:29:47 +02:00
pvc : corev1 . PersistentVolumeClaimVolumeSource {
2021-07-26 14:58:23 +05:30
ClaimName : "pvc1" ,
},
}
osdProps . placement = cephv1 . Placement { NodeAffinity : & corev1 . NodeAffinity {
RequiredDuringSchedulingIgnoredDuringExecution : & corev1 . NodeSelector {
NodeSelectorTerms : [] corev1 . NodeSelectorTerm {
{
MatchExpressions : [] corev1 . NodeSelectorRequirement {
{
Key : "role" ,
2022-04-24 17:29:47 +02:00
Operator : corev1 . NodeSelectorOpIn ,
2021-07-26 14:58:23 +05:30
Values : [] string { "storage-node3" },
},
},
},
},
},
},
}
osdProps . preparePlacement = & cephv1 . Placement { NodeAffinity : & corev1 . NodeAffinity {
RequiredDuringSchedulingIgnoredDuringExecution : & corev1 . NodeSelector {
NodeSelectorTerms : [] corev1 . NodeSelectorTerm {
{
MatchExpressions : [] corev1 . NodeSelectorRequirement {
{
Key : "role" ,
2022-04-24 17:29:47 +02:00
Operator : corev1 . NodeSelectorOpIn ,
2021-07-26 14:58:23 +05:30
Values : [] string { "storage-node3" },
},
},
},
},
},
},
}
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
osd := OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
dataPathMap := & provisionConfig {
DataPathMap : opconfig . NewDatalessDaemonDataPathMap ( c . clusterInfo . Namespace , "/var/lib/rook" ),
}
// For OSD daemon
// When OnlyApplyOSDPlacement false, in case of PVC
r , err := c . makeDeployment ( osdProps , osd , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 2 , len ( r . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// For OSD-prepare job
job , err := c . makeJob ( osdProps , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 2 , len ( job . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// When OnlyApplyOSDPlacement true, in case of PVC
spec . Storage . OnlyApplyOSDPlacement = true
c = New ( context , clusterInfo , spec , "rook/rook:myversion" )
r , err = c . makeDeployment ( osdProps , osd , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 1 , len ( r . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// For OSD-prepare job
job , err = c . makeJob ( osdProps , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 1 , len ( job . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// When OnlyApplyOSDPlacement false, in case of non-PVC
spec . Storage . OnlyApplyOSDPlacement = false
osdProps = osdProperties {}
c = New ( context , clusterInfo , spec , "rook/rook:myversion" )
r , err = c . makeDeployment ( osdProps , osd , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 2 , len ( r . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// For OSD-prepare job
job , err = c . makeJob ( osdProps , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 2 , len ( job . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// When OnlyApplyOSDPlacement true, in case of non-PVC
spec . Storage . OnlyApplyOSDPlacement = true
c = New ( context , clusterInfo , spec , "rook/rook:myversion" )
r , err = c . makeDeployment ( osdProps , osd , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 1 , len ( r . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
// For OSD-prepare job
job , err = c . makeJob ( osdProps , dataPathMap )
assert . NoError ( t , err )
assert . Equal ( t , 1 , len ( job . Spec . Template . Spec . Affinity . NodeAffinity . RequiredDuringSchedulingIgnoredDuringExecution . NodeSelectorTerms [ 0 ]. MatchExpressions ))
}
2023-01-23 18:01:50 +05:30
func TestCreateOSDService ( t * testing . T ) {
clientset := fake . NewSimpleClientset ()
context := & clusterd . Context { Clientset : clientset , ConfigDir : "/var/lib/rook" , Executor : & exectest . MockExecutor {}}
clusterInfo := & cephclient . ClusterInfo { Namespace : "ns" }
clusterInfo . SetName ( "test" )
clusterInfo . OwnerInfo = cephclient . NewMinimumOwnerInfo ( t )
spec := cephv1 . ClusterSpec {
Network : cephv1 . NetworkSpec { Connections : & cephv1 . ConnectionsSpec { RequireMsgr2 : false }},
}
c := New ( context , clusterInfo , spec , "rook/rook:myversion" )
osd := OSDInfo {
ID : 0 ,
CVMode : "raw" ,
}
service , err := c . createOSDService ( osd , map [ string ] string {})
assert . NoError ( t , err )
// the clusterIP will not be set in a mock service
assert . Equal ( t , "" , service . Spec . ClusterIP )
assert . Equal ( t , 2 , len ( service . Spec . Ports ))
c . spec . Network . Connections . RequireMsgr2 = true
service , err = c . createOSDService ( osd , map [ string ] string {})
assert . NoError ( t , err )
// only 6800 port is added if RequireMsgr2 is enabled
assert . Equal ( t , 1 , len ( service . Spec . Ports ))
assert . Equal ( t , int32 ( osdPortv2 ), service . Spec . Ports [ 0 ]. Port )
}