Merge pull request #1710 from galexrt/1386

ceph mon: Only run one mon on a node
This commit is contained in:
Travis Nielsen authored and GitHub committed 2018-06-07 09:21:36 -07:00
commit ccc5acd98b
22 files changed
+304 -263

No files matched your search

+9 -20
View File
@@ -5,21 +5,17 @@ indent: true
---
# Ceph Cluster CRD
Rook allows creation and customization of storage clusters through the custom resource definitions (CRDs). The following settings are
available for a Ceph cluster.
## Settings
Settings can be specified at the global level to apply to the cluster as a whole, while other settings can be specified at more fine-grained levels. If any setting is unspecified, a suitable default will be used automatically.
### Cluster metadata
- `name`: The name that will be used internally for the Ceph cluster. Most commonly the name is the same as the namespace since multiple clusters are not supported in the same namespace.
- `namespace`: The Kubernetes namespace that will be created for the Rook cluster. The services, pods, and other resources created by the operator will be added to this namespace. The common scenario is to create a single Rook cluster. If multiple clusters are created, they must not have conflicting devices or host paths.
### Cluster settings
### Cluster Settings
- `dataDirHostPath`: The path on the host ([hostPath](https://kubernetes.io/docs/concepts/storage/volumes/#hostpath)) where config and data should be stored for each of the services. If the directory does not exist, it will be created. Because this directory persists on the host, it will remain after pods are deleted.
- On **Minikube** environments, use `/data/rook`. Minikube boots into a tmpfs but it provides some [directories](https://github.com/kubernetes/minikube/blob/master/docs/persistent_volumes.md) where files can be persisted across reboots. Using one of these directories will ensure that Rook's data and configuration files are persisted and that enough storage space is available.
- If a path is not specified, an [empty dir](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir) will be used and the config will be lost when the pod or host is restarted. This option is **not recommended**.
@@ -27,7 +23,7 @@ Settings can be specified at the global level to apply to the cluster as a whole
If this value is empty, each pod will get an ephemeral directory to store their config files that is tied to the lifetime of the pod running on that node. More details can be found in the Kubernetes [empty dir docs](https://kubernetes.io/docs/concepts/storage/volumes/#emptydir).
- `network`: The network settings for the cluster
- `hostNetwork`: uses network of the hosts instead of using the SDN below the containers.
- `monCount`: set the number of mons to be started. The number should be odd and between `1` and `9`. Default if not specified is `3`.
- `mon`: contains mon related options [mon settings](#mon-settings)
For more details on the mons and when to choose a number other than `3`, see the [mon health design doc](https://github.com/rook/rook/blob/master/design/mon-health.md).
- `placement`: [placement configuration settings](#placement-configuration-settings)
- `resources`: [resources configuration settings](#cluster-wide-resources-configuration-settings)
@@ -39,13 +35,16 @@ For more details on the mons and when to choose a number other than `3`, see the
- [storage selection settings](#storage-selection-settings)
- [storage configuration settings](#storage-configuration-settings)
#### Node updates
#### Node Updates
Nodes can be added and removed over time by updating the Cluster CRD, for example with `kubectl -n rook-ceph edit cluster rook`.
This will bring up your default text editor and allow you to add and remove storage nodes from the cluster.
This feature is only available when `useAllNodes` has been set to `false`.
### Node settings
### Mon Settings
- `count`: set the number of mons to be started. The number should be odd and between `1` and `9`. Default if not specified is `3`.
- `allowMultiplePerNode`: enable (`true`) or disable (`false`) the placement of multiple mons on one node. Default is `false`.
### Node Settings
In addition to the cluster level settings specified above, each individual node can also specify configuration to override the cluster level settings and defaults.
If a node does not specify any configuration then it will inherit the cluster level settings.
- `name`: The name of the node, which should match its `kubernetes.io/hostname` label.
@@ -54,8 +53,7 @@ If a node does not specify any configuration then it will inherit the cluster le
- [storage configuration settings](#storage-configuration-settings)
### Storage Selection Settings
Below are the settings available, both at the cluster and individual node level, for selecting which storage resources will be included in the cluster.
Below are the settings available, both at the cluster and individual node level, for selecting which storage resources will be included in the cluster.
- `useAllDevices`: `true` or `false`, indicating whether all devices found on nodes in the cluster should be automatically consumed by OSDs. **Not recommended** unless you have a very controlled environment where you will not risk formatting of devices with existing data. When `true`, all devices will be used except those with partitions created or a local filesystem. Is overridden by `deviceFilter` if specified.
- `deviceFilter`: A regular expression that allows selection of devices to be consumed by OSDs. If individual devices have been specified for a node then this filter will be ignored. This field uses [golang regular expression syntax](https://golang.org/pkg/regexp/syntax/). For example:
- `sdb`: Only selects the `sdb` device if found
@@ -72,7 +70,7 @@ Below are the settings available, both at the cluster and individual node level,
- `location`: Location information about the cluster to help with data placement, such as region or data center. This is directly fed into the underlying Ceph CRUSH map. More information on CRUSH maps can be found in the [ceph docs](http://docs.ceph.com/docs/master/rados/operations/crush-map/).
### OSD Configuration settings
### OSD Configuration Settings
The following storage selection settings are specific to Ceph and do not apply to other backends. All variables are key-value pairs represented as strings.
- `metadataDevice`: Name of a device to use for the metadata of OSDs on each node. Performance can be improved by using a low latency device (such as SSD or NVMe) as the metadata device, while other spinning platter (HDD) devices on a node are used to store data.
- `storeType`: `filestore` or `bluestore`, the underlying storage format to use for each OSD. The default is set dynamically to `bluestore` for devices, while `filestore` is the default for directories. Set this store type explicitly to override the default. Warning: Bluestore is **not** recommended for directories in production. Bluestore does not purge data from the directory and over time will grow without the ability to compact or shrink.
@@ -81,7 +79,6 @@ The following storage selection settings are specific to Ceph and do not apply t
- `journalSizeMB`: The size in MB of a filestore journal. Include quotes around the size.
### Placement Configuration Settings
Placement configuration for the cluster services. It includes the following keys: `mgr`, `mon`, `osd` and `all`. Each service will have its placement configuration generated by merging the generic configuration under `all` with the most specific one (which will override any attributes).
A Placement configuration is specified (according to the kubernetes PodSpec) as:
@@ -95,7 +92,6 @@ This is because of the mons having built-in anti-affinity with each other throug
See the [mon design doc](https://github.com/rook/rook/blob/master/design/mon-health.md) for more details on the mon failover design.
### Cluster-wide Resources Configuration Settings
Resources should be specified so that the rook components are handled after [Kubernetes Pod Quality of Service classes](https://kubernetes.io/docs/tasks/configure-pod-container/quality-service-pod/).
This allows to keep rook components running when for example a node runs out of memory and the rook components are not killed depending on their Quality of Service class.
@@ -105,7 +101,6 @@ You can set resource requests/limits for rook components through the [Resource R
- `osd`: Set resource requests/limits for OSDs.
### Resource Requirements/Limits
For more information on resource requests/limits see the official Kubernetes documentation: [Kubernetes - Managing Compute Resources for Containers](https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/#resource-requests-and-limits-of-pod-and-container)
- `requests`: Requests for cpu or memory.
- `cpu`: Request for CPU (example: one CPU core `1`, 50% of one CPU core `500m`).
@@ -115,9 +110,7 @@ For more information on resource requests/limits see the official Kubernetes doc
- `memory`: Limit for Memory (example: one gigabyte of memory `1Gi`, half a gigabyte of memory `512Mi`).
## Samples
### Storage configuration: All devices
```yaml
apiVersion: v1
kind: Namespace
@@ -144,7 +137,6 @@ spec:
```
### Storage Configuration: Specific devices
Individual nodes and their config can be specified so that only the named nodes below will be used as storage resources.
Each node's 'name' field should match their 'kubernetes.io/hostname' label.
@@ -186,7 +178,6 @@ spec:
```
### Storage Configuration: Cluster wide Directories
This example is based up on the [Storage Configuration: Specific devices](#storage-configuration-specific-devices).
Individual nodes can override the cluster wide specified directories list.
@@ -221,7 +212,6 @@ spec:
```
### Node Affinity
To control where various services will be scheduled by kubernetes, use the placement configuration sections below.
The example under 'all' would have all services scheduled on kubernetes nodes labeled with 'role=storage' and
tolerate taints with a key of 'storage-node'.
@@ -264,7 +254,6 @@ spec:
```
### Resource requests/Limits
To control how many resources the rook components can request/use, you can set requests and limits in Kubernetes for them.
You can override these requests/limits for OSDs per node when using `useAllNodes: false` in the `node` item in the `nodes` list.
@@ -14,10 +14,12 @@ spec:
# In Minikube, the '/data' directory is configured to persist across reboots. Use "/data/rook" in Minikube environment.
dataDirHostPath: /var/lib/rook
# set the amount of mons to be started
monCount: 3
mon:
count: 3
allowMultiplePerNode: true
network:
# toggle to use hostNetwork
hostNetwork: false
hostNetwork: false
# To control where various services will be scheduled by kubernetes, use the placement configuration sections below.
# The example under 'all' would have all services scheduled on kubernetes nodes labeled with 'role=storage' and
# tolerate taints with a key of 'storage-node'.
@@ -60,7 +62,7 @@ spec:
config:
# The default and recommended storeType is dynamically set to bluestore for devices and filestore for directories.
# Set the storeType explicitly only if it is required not to use the default.
# storeType: bluestore
# storeType: bluestore
databaseSizeMB: "1024" # this value can be removed for environments with normal sized disks (100 GB or larger)
journalSizeMB: "1024" # this value can be removed for environments with normal sized disks (20 GB or larger)
# Cluster level list of directories to use for storage. These values will be set for all nodes that have no `directories` set.
+5 -3
View File
@@ -29,7 +29,9 @@ Therefore, updating storage resources should be performed by the operator with s
The Cluster CRD has many fields, but not all of them will be updatable (i.e., the operator will not attempt to make any changes to the cluster for updates to some fields).
#### Supported Fields
The following fields will be **supported** for updates:
* `monCount`: The number of monitors can be updated and the operator will ensure that as monitors are scaled up or down the cluster remains in quorum.
* `moun`: Ceph mon specific settings can be changed.
* `count`: The number of monitors can be updated and the operator will ensure that as monitors are scaled up or down the cluster remains in quorum.
* `allowMultiplePerNode`: The policy to allow multiple mons to be placed on one node can be toggled.
* `deviceFilter`: The regex filter for devices allowed to be used for storage can be updated and OSDs will be added or removed to match the new filter pattern.
* `useAllDevices`: If this value is updated to `true`, then OSDs will be added to start using all devices on nodes.
However, if this value is updated to `false`, the operator will only allow OSDs to be removed if there is a value set for `deviceFilter`.
@@ -88,7 +90,7 @@ Let's walk through a couple simple scenarios to illustrate this approach:
### Orchestration
When the operator receives an event that the Cluster CRD has been updated, it will need to perform some orchestration in order to bring actual state of the cluster in agreement with the desired state.
For example, when `monCount` is updated, the operator will add or remove a single monitor at a time, ensuring that quorum is restored before moving onto the next monitor.
For example, when `mon.count` is updated, the operator will add or remove a single monitor at a time, ensuring that quorum is restored before moving onto the next monitor.
Updates to the storage spec for the cluster require even more careful consideration and management by the operator, which will be discussed in this section.
First and foremost, changes to the cluster state should not be carried out when the cluster is not in a healthy state.
@@ -205,5 +207,5 @@ One proposal for implementation phases would be:
Cluster performance impact would not be ideal but may be tolerable for many scenarios, and Rook clusters would then have dynamic storage capabilities.
1. **Simple remove storage**: Similar to the simple adding of storage, storage resources can be removed from the Cluster CRD with minimal orchestration.
1. **Dynamic storage orchestration**: The more careful orchestration of storage changes would be implemented, with the operator and OSD pods coordinating across the cluster to slowly ramp up/down storage changes with minimal impact to cluster performance.
1. **Non-storage cluster field updates**: All other properties in the cluster CRD supported for updates will be implemented (e.g., `monCount`, `resources`, etc.).
1. **Non-storage cluster field updates**: All other properties in the cluster CRD supported for updates will be implemented (e.g., `mon`, `resources`, etc.).
1. **Placement Group updates**: Placement group counts will be updated over time as the cluster grows in order to optimize cluster performance.
+7 -3
View File
@@ -159,7 +159,9 @@ With this approach, the user experience to create a cluster would look like the
apiVersion: ceph.rook.io/v1
kind: Cluster
spec:
monCount: 3
mon:
count: 3
allowMultiplePerNode: false
network:
placement:
resources:
@@ -194,7 +196,7 @@ type ClusterSpec struct {
Network rook.NetworkSpec `json:"network"`
Placement rook.PlacementSpec `json:"placement"`
Resources rook.ResourceSpec `json:"resources"`
MonCount int `json:"monCount"`
Mon rook.MonSpec `json:"mon"`
}
```
@@ -397,7 +399,9 @@ metadata:
name: ceph
namespace: rook-ceph
spec:
monCount: 3
mon:
count: 3
allowMultiplePerNode: false
network:
hostNetwork: false
placement:
+3 -1
View File
@@ -82,7 +82,9 @@ metadata:
spec:
dataDirHostPath: /var/lib/rook
hostNetwork: false
monCount: 3
mon:
count: 3
allowMultiplePerNode: false
placement:
resources:
api:
+7 -2
View File
@@ -29,7 +29,9 @@ import (
func TestClusterSpecMarshal(t *testing.T) {
specYaml := []byte(`
dataDirHostPath: /var/lib/rook
monCount: 5
mon:
count: 5
allowMultiplePerNode: false
network:
hostNetwork: true
storage:
@@ -65,7 +67,10 @@ storage:
// the unmarshalled storage spec should equal the expected spec below
useAllDevices := false
expectedSpec := ClusterSpec{
MonCount: 5,
Mon: MonSpec{
Count: 5,
AllowMultiplePerNode: false,
},
DataDirHostPath: "/var/lib/rook",
Network: rookalpha.NetworkSpec{
HostNetwork: true,
+7 -2
View File
@@ -63,8 +63,8 @@ type ClusterSpec struct {
// The path on the host where config and data can be persisted.
DataDirHostPath string `json:"dataDirHostPath,omitempty"`
// MonCount sets the mon size
MonCount int `json:"monCount,omitempty"`
// A spec for mon releated options
Mon MonSpec `json:"mon"`
}
type ClusterStatus struct {
@@ -81,6 +81,11 @@ const (
ClusterStateError ClusterState = "Error"
)
type MonSpec struct {
Count int `json:"count,omitempty"`
AllowMultiplePerNode bool `json:"allowMultiplePerNode,omitempty"`
}
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -109,6 +109,7 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) {
(*out)[key] = *val.DeepCopy()
}
}
out.Mon = in.Mon
return
}
@@ -275,6 +276,22 @@ func (in *MetadataServerSpec) DeepCopy() *MetadataServerSpec {
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *MonSpec) DeepCopyInto(out *MonSpec) {
*out = *in
return
}
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MonSpec.
func (in *MonSpec) DeepCopy() *MonSpec {
if in == nil {
return nil
}
out := new(MonSpec)
in.DeepCopyInto(out)
return out
}
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ObjectStore) DeepCopyInto(out *ObjectStore) {
*out = *in
+14 -4
View File
@@ -17,14 +17,20 @@ package test
import (
"encoding/json"
"strconv"
"fmt"
"github.com/rook/rook/pkg/daemon/ceph/client"
)
func MonInQuorumResponse() string {
resp := client.MonStatusResponse{Quorum: []int{0}}
resp.MonMap.Mons = []client.MonMapEntry{{Name: "mon1", Rank: 0, Address: "1.2.3.4"}}
resp.MonMap.Mons = []client.MonMapEntry{
{
Name: "rook-ceph-mon1",
Rank: 0,
Address: "1.2.3.1",
},
}
serialized, _ := json.Marshal(resp)
return string(serialized)
}
@@ -32,8 +38,12 @@ func MonInQuorumResponse() string {
func MonInQuorumResponseMany(count int) string {
resp := client.MonStatusResponse{Quorum: []int{0}}
resp.MonMap.Mons = []client.MonMapEntry{}
for i := 1; i <= count; i++ {
resp.MonMap.Mons = append(resp.MonMap.Mons, client.MonMapEntry{Name: "mon" + strconv.Itoa(i), Rank: 0, Address: "1.2.3.4"})
for i := 0; i <= count; i++ {
resp.MonMap.Mons = append(resp.MonMap.Mons, client.MonMapEntry{
Name: fmt.Sprintf("rook-ceph-mon%d", i),
Rank: 0,
Address: fmt.Sprintf("1.2.3.%d", i),
})
}
serialized, _ := json.Marshal(resp)
return string(serialized)
+9 -11
View File
@@ -57,8 +57,6 @@ const (
clusterCreateTimeout = 5 * time.Minute
updateClusterInterval = 30 * time.Second
updateClusterTimeout = 1 * time.Hour
defaultMonCount = 3
maxMonCount = 9
)
const (
@@ -184,16 +182,16 @@ func (c *ClusterController) onAdd(obj interface{}) {
c.devicesInUse = true
}
if cluster.Spec.MonCount <= 0 {
logger.Warningf("mon count is 0 or less (given: %d), should be greater than 0, defaulting to %d", cluster.Spec.MonCount, defaultMonCount)
cluster.Spec.MonCount = defaultMonCount
if cluster.Spec.Mon.Count <= 0 {
logger.Warning("mon count is 0 or less, should be at least 1, will use default value of %d", mon.DefaultMonCount)
cluster.Spec.Mon.Count = 0
}
if cluster.Spec.MonCount > maxMonCount {
logger.Warningf("mon count is bigger than %d (given: %d), not supported, changing to %d", maxMonCount, cluster.Spec.MonCount, maxMonCount)
cluster.Spec.MonCount = maxMonCount
if cluster.Spec.Mon.Count > mon.MaxMonCount {
logger.Warningf("mon count is bigger than %d (given: %d), not supported, changing to %d", mon.MaxMonCount, cluster.Spec.Mon.Count, mon.MaxMonCount)
cluster.Spec.Mon.Count = mon.MaxMonCount
}
if cluster.Spec.MonCount%2 == 0 {
logger.Warningf("mon count is even (given: %d), should be uneven, continuing", cluster.Spec.MonCount)
if cluster.Spec.Mon.Count%2 == 0 {
logger.Warningf("mon count is even (given: %d), should be uneven, continuing", cluster.Spec.Mon.Count)
}
// Start the Rook cluster components. Retry several times in case of failure.
@@ -594,7 +592,7 @@ func (c *cluster) createInstance(rookImage string) error {
}
// Start the mon pods
c.mons = mon.New(c.context, c.Namespace, c.Spec.DataDirHostPath, rookImage, c.Spec.MonCount, cephv1alpha1.GetMonPlacement(c.Spec.Placement),
c.mons = mon.New(c.context, c.Namespace, c.Spec.DataDirHostPath, rookImage, c.Spec.Mon, cephv1alpha1.GetMonPlacement(c.Spec.Placement),
c.Spec.Network.HostNetwork, cephv1alpha1.GetMonResources(c.Spec.Resources), c.ownerRef)
err = c.mons.Start()
if err != nil {
+4 -1
View File
@@ -99,7 +99,10 @@ func convertLegacyCluster(legacyCluster *rookv1alpha1.Cluster) *cephv1alpha1.Clu
},
Resources: convertLegacyResourceSpec(legacySpec.Resources),
DataDirHostPath: legacySpec.DataDirHostPath,
MonCount: legacySpec.MonCount,
Mon: cephv1alpha1.MonSpec{
Count: legacySpec.MonCount,
AllowMultiplePerNode: false,
},
},
}
+5 -2
View File
@@ -224,8 +224,11 @@ func TestConvertLegacyCluster(t *testing.T) {
},
Spec: cephv1alpha1.ClusterSpec{
DataDirHostPath: "/var/lib/rook302",
MonCount: 5,
Network: rookv1alpha2.NetworkSpec{HostNetwork: true},
Mon: cephv1alpha1.MonSpec{
Count: 5,
AllowMultiplePerNode: false,
},
Network: rookv1alpha2.NetworkSpec{HostNetwork: true},
Placement: rookv1alpha2.PlacementSpec{
rookv1alpha2.PlacementKeyAll: rookv1alpha2.Placement{Tolerations: []v1.Toleration{{Key: "storage-node", Operator: v1.TolerationOpExists}}},
cephv1alpha1.PlacementKeyMon: rookv1alpha2.Placement{
+2 -2
View File
@@ -158,7 +158,7 @@ func (c *Cluster) checkHealth() error {
// create/start new mons when there are less mons
if len(status.MonMap.Mons) < c.Size {
logger.Infof("found only %d mons less than given monCount %d, starting more mons", len(status.MonMap.Mons), c.Size)
logger.Infof("found only %d mons less than given mon.count %d, starting more mons", len(status.MonMap.Mons), c.Size)
return c.startMons()
}
@@ -242,7 +242,7 @@ func (c *Cluster) failoverMon(name string) error {
// Assign the pod to a node
if err = c.assignMons(mConf); err != nil {
return fmt.Errorf("failed to assign pods to mons. %+v", err)
return fmt.Errorf("failed to place new mon on a node. %+v", err)
}
if c.HostNetwork {
+38 -34
View File
@@ -23,6 +23,7 @@ import (
"os"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/daemon/ceph/client"
@@ -51,12 +52,13 @@ func TestCheckHealth(t *testing.T) {
ConfigDir: configDir,
Executor: executor,
}
c := New(context, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(context, "ns", "", "myversion", cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true},
rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(1)
c.waitForStart = false
defer os.RemoveAll(c.context.ConfigDir)
c.mapping.Node["mon1"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon1"] = &NodeInfo{
Name: "node0",
Address: "",
}
@@ -66,7 +68,7 @@ func TestCheckHealth(t *testing.T) {
err := c.checkHealth()
assert.Nil(t, err)
err = c.failoverMon("mon1")
err = c.failoverMon("rook-ceph-mon1")
assert.Nil(t, err)
newMons := []string{
@@ -94,16 +96,17 @@ func TestCheckHealthNotFound(t *testing.T) {
ConfigDir: configDir,
Executor: executor,
}
c := New(context, "ns", "", "myversion", 2, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(context, "ns", "", "myversion", cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true},
rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(2)
c.waitForStart = false
defer os.RemoveAll(c.context.ConfigDir)
c.mapping.Node["mon1"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon1"] = &NodeInfo{
Name: "node0",
Address: "",
}
c.mapping.Node["mon2"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon2"] = &NodeInfo{
Name: "node0",
Address: "",
}
@@ -115,10 +118,10 @@ func TestCheckHealthNotFound(t *testing.T) {
// Check if the two mons are found in the configmap
cm, err := c.context.Clientset.CoreV1().ConfigMaps(c.Namespace).Get(EndpointConfigMapName, metav1.GetOptions{})
assert.Nil(t, err)
if cm.Data[EndpointDataKey] == "mon1=1.2.3.1:6790,mon2=1.2.3.2:6790" {
assert.Equal(t, "mon1=1.2.3.1:6790,mon2=1.2.3.2:6790", cm.Data[EndpointDataKey])
if cm.Data[EndpointDataKey] == "rook-ceph-mon1=1.2.3.1:6790,rook-ceph-mon2=1.2.3.2:6790" {
assert.Equal(t, "rook-ceph-mon1=1.2.3.1:6790,rook-ceph-mon2=1.2.3.2:6790", cm.Data[EndpointDataKey])
} else {
assert.Equal(t, "mon2=1.2.3.2:6790,mon1=1.2.3.1:6790", cm.Data[EndpointDataKey])
assert.Equal(t, "rook-ceph-mon2=1.2.3.2:6790,rook-ceph-mon1=1.2.3.1:6790", cm.Data[EndpointDataKey])
}
// Because mon2 isn't in the MonInQuorumResponse() this will create a mon11
@@ -128,10 +131,10 @@ func TestCheckHealthNotFound(t *testing.T) {
// recheck that the "not found" mon has been replaced with a new one
cm, err = c.context.Clientset.CoreV1().ConfigMaps(c.Namespace).Get(EndpointConfigMapName, metav1.GetOptions{})
assert.Nil(t, err)
if cm.Data[EndpointDataKey] == "mon1=1.2.3.1:6790,rook-ceph-mon11=:6790" {
assert.Equal(t, "mon1=1.2.3.1:6790,rook-ceph-mon11=:6790", cm.Data[EndpointDataKey])
if cm.Data[EndpointDataKey] == "rook-ceph-mon1=1.2.3.1:6790,rook-ceph-mon11=:6790" {
assert.Equal(t, "rook-ceph-mon1=1.2.3.1:6790,rook-ceph-mon11=:6790", cm.Data[EndpointDataKey])
} else {
assert.Equal(t, "rook-ceph-mon11=:6790,mon1=1.2.3.1:6790", cm.Data[EndpointDataKey])
assert.Equal(t, "rook-ceph-mon11=:6790,rook-ceph-mon1=1.2.3.1:6790", cm.Data[EndpointDataKey])
}
}
@@ -143,7 +146,7 @@ func TestCheckHealthTwoMonsOneNode(t *testing.T) {
resp := client.MonStatusResponse{Quorum: []int{0}}
resp.MonMap.Mons = []client.MonMapEntry{
{
Name: "mon1",
Name: "rook-ceph-mon1",
Rank: 0,
Address: "1.2.3.4",
},
@@ -167,18 +170,19 @@ func TestCheckHealthTwoMonsOneNode(t *testing.T) {
ConfigDir: configDir,
Executor: executor,
}
c := New(context, "ns", "", "myversion", 2, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(context, "ns", "", "myversion", cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true},
rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(2)
c.waitForStart = false
defer os.RemoveAll(c.context.ConfigDir)
// add two mons to the mapping on node0
c.mapping.Node["mon1"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon1"] = &NodeInfo{
Name: "node0",
Hostname: "mynode0",
Address: "0.0.0.0",
}
c.mapping.Node["mon2"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon2"] = &NodeInfo{
Name: "node0",
Hostname: "mynode0",
Address: "0.0.0.0",
@@ -198,10 +202,10 @@ func TestCheckHealthTwoMonsOneNode(t *testing.T) {
// initial health check should already see that there is more than one mon on one node (node1)
_, err := c.checkMonsOnSameNode()
assert.Nil(t, err)
assert.Equal(t, "node0", c.mapping.Node["mon1"].Name)
assert.Equal(t, "node0", c.mapping.Node["mon2"].Name)
assert.Equal(t, "mynode0", c.mapping.Node["mon1"].Hostname)
assert.Equal(t, "mynode0", c.mapping.Node["mon2"].Hostname)
assert.Equal(t, "node0", c.mapping.Node["rook-ceph-mon1"].Name)
assert.Equal(t, "node0", c.mapping.Node["rook-ceph-mon2"].Name)
assert.Equal(t, "mynode0", c.mapping.Node["rook-ceph-mon1"].Hostname)
assert.Equal(t, "mynode0", c.mapping.Node["rook-ceph-mon2"].Hostname)
// add new node and check if the second mon gets failovered to it
n := &v1.Node{
@@ -236,13 +240,13 @@ func TestCheckHealthTwoMonsOneNode(t *testing.T) {
deleted := false
for _, rs := range rsses.Items {
if rs.Name == "mon1" || rs.Name == "rook-ceph-mon3" {
if rs.Name == "rook-ceph-mon1" || rs.Name == "rook-ceph-mon3" {
deleted = true
} else {
deleted = false
}
}
assert.Equal(t, true, deleted, "mon2 not failovered/deleted after health check")
assert.Equal(t, true, deleted, "rook-ceph-mon2 not failovered/deleted after health check")
// enable different ceph mon map output
executorNextMons = true
@@ -256,7 +260,7 @@ func TestCheckHealthTwoMonsOneNode(t *testing.T) {
for _, rs := range rsses.Items {
// both mons should always be on the same node as in this test due to the order
//the mons are processed in the loop
if (rs.Name == "mon1" && rs.Spec.Template.Spec.NodeSelector[apis.LabelHostname] == "node1") || (rs.Name != "rook-ceph-mon3" && rs.Spec.Template.Spec.NodeSelector[apis.LabelHostname] == "node2") {
if (rs.Name == "rook-ceph-mon1" && rs.Spec.Template.Spec.NodeSelector[apis.LabelHostname] == "node1") || (rs.Name != "rook-ceph-mon3" && rs.Spec.Template.Spec.NodeSelector[apis.LabelHostname] == "node2") {
assert.Fail(t, fmt.Sprintf("mon %s shouldn't exist", rs.Name))
}
}
@@ -276,17 +280,18 @@ func TestCheckMonsValid(t *testing.T) {
ConfigDir: configDir,
Executor: executor,
}
c := New(context, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(context, "ns", "", "myversion", cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true},
rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(1)
c.waitForStart = false
defer os.RemoveAll(c.context.ConfigDir)
// add two mons to the mapping on node0
c.mapping.Node["mon1"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon1"] = &NodeInfo{
Name: "node0",
Address: "0.0.0.0",
}
c.mapping.Node["mon2"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon2"] = &NodeInfo{
Name: "node1",
Address: "0.0.0.0",
}
@@ -314,8 +319,8 @@ func TestCheckMonsValid(t *testing.T) {
_, err := c.checkMonsOnValidNodes()
assert.Nil(t, err)
assert.Equal(t, "node0", c.mapping.Node["mon1"].Name)
assert.Equal(t, "node1", c.mapping.Node["mon2"].Name)
assert.Equal(t, "node0", c.mapping.Node["rook-ceph-mon1"].Name)
assert.Equal(t, "node1", c.mapping.Node["rook-ceph-mon2"].Name)
// set node1 unschedulable and check that mon2 gets failovered to be mon3 to node2
node0, err := c.context.Clientset.CoreV1().Nodes().Get("node0", metav1.GetOptions{})
@@ -335,11 +340,11 @@ func TestCheckMonsValid(t *testing.T) {
assert.Nil(t, err)
assert.Len(t, c.mapping.Node, 2)
assert.Nil(t, c.mapping.Node["mon1"])
assert.Nil(t, c.mapping.Node["rook-ceph-mon1"])
// the new mon should always be on the empty node2
// the failovered mon's name is "rook-ceph-mon0"
assert.Equal(t, "node2", c.mapping.Node["rook-ceph-mon0"].Name)
assert.Equal(t, "node1", c.mapping.Node["mon2"].Name)
assert.Equal(t, "node1", c.mapping.Node["rook-ceph-mon2"].Name)
}
func TestCheckLessMonsStartNewMons(t *testing.T) {
@@ -356,15 +361,14 @@ func TestCheckLessMonsStartNewMons(t *testing.T) {
ConfigDir: configDir,
Executor: executor,
}
c := New(context, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(context, "ns", "", "myversion", cephv1alpha1.MonSpec{Count: 5, AllowMultiplePerNode: true},
rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.maxMonID = 1
c.clusterInfo = test.CreateConfigDir(1)
c.waitForStart = false
defer os.RemoveAll(c.context.ConfigDir)
c.Size = 5
err := c.checkHealth()
assert.Nil(t, err)
assert.Equal(t, 5, len(c.clusterInfo.Monitors))
}
+57 -46
View File
@@ -24,6 +24,7 @@ import (
"time"
"github.com/coreos/pkg/capnslog"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/daemon/ceph/client"
@@ -56,29 +57,35 @@ const (
monSecretName = "mon-secret"
adminSecretName = "admin-secret"
clusterSecretName = "cluster-name"
// DefaultMonCount Default mon count for cluster
DefaultMonCount = 3
// MaxMonCount Maximum allowed mon count for a cluster
MaxMonCount = 9
)
// Cluster is for the cluster of monitors
type Cluster struct {
context *clusterd.Context
Namespace string
Keyring string
Version string
MasterHost string
Size int
Port int32
clusterInfo *mon.ClusterInfo
placement rookalpha.Placement
maxMonID int
waitForStart bool
dataDirHostPath string
monPodRetryInterval time.Duration
monPodTimeout time.Duration
monTimeoutList map[string]time.Time
HostNetwork bool
mapping *Mapping
resources v1.ResourceRequirements
ownerRef metav1.OwnerReference
context *clusterd.Context
Namespace string
Keyring string
Version string
MasterHost string
Size int
AllowMultiplePerNode bool
Port int32
clusterInfo *mon.ClusterInfo
placement rookalpha.Placement
maxMonID int
waitForStart bool
dataDirHostPath string
monPodRetryInterval time.Duration
monPodTimeout time.Duration
monTimeoutList map[string]time.Time
HostNetwork bool
mapping *Mapping
resources v1.ResourceRequirements
ownerRef metav1.OwnerReference
}
// monConfig for a single monitor
@@ -102,21 +109,22 @@ type NodeInfo struct {
}
// New creates an instance of a mon cluster
func New(context *clusterd.Context, namespace, dataDirHostPath, version string, size int, placement rookalpha.Placement, hostNetwork bool,
func New(context *clusterd.Context, namespace, dataDirHostPath, version string, mon cephv1alpha1.MonSpec, placement rookalpha.Placement, hostNetwork bool,
resources v1.ResourceRequirements, ownerRef metav1.OwnerReference) *Cluster {
return &Cluster{
context: context,
placement: placement,
dataDirHostPath: dataDirHostPath,
Namespace: namespace,
Version: version,
Size: size,
maxMonID: -1,
waitForStart: true,
monPodRetryInterval: 6 * time.Second,
monPodTimeout: 5 * time.Minute,
monTimeoutList: map[string]time.Time{},
HostNetwork: hostNetwork,
context: context,
placement: placement,
dataDirHostPath: dataDirHostPath,
Namespace: namespace,
Version: version,
Size: mon.Count,
AllowMultiplePerNode: mon.AllowMultiplePerNode,
maxMonID: -1,
waitForStart: true,
monPodRetryInterval: 6 * time.Second,
monPodTimeout: 5 * time.Minute,
monTimeoutList: map[string]time.Time{},
HostNetwork: hostNetwork,
mapping: &Mapping{
Node: map[string]*NodeInfo{},
Port: map[string]int32{},
@@ -134,16 +142,17 @@ func (c *Cluster) Start() error {
return fmt.Errorf("failed to initialize ceph cluster info. %+v", err)
}
// when we don't have enough monitors, start them
if len(c.clusterInfo.Monitors) < c.Size {
c.startMons()
} else {
// Check the health of a previously started cluster
if err := c.checkHealth(); err != nil {
logger.Warningf("failed to check mon health %+v. %+v", c.clusterInfo.Monitors, err)
}
return c.startMons()
}
// we have enough mons, run a health check
err := c.checkHealth()
if err != nil {
logger.Warningf("failed to check mon health %+v. %+v", c.clusterInfo.Monitors, err)
}
return nil
return err
}
func (c *Cluster) startMons() error {
@@ -291,6 +300,11 @@ func (c *Cluster) assignMons(mons []*monConfig) error {
return fmt.Errorf("failed to get available nodes for mons. %+v", err)
}
// if all nodes already have mons return error as we don't place two mons on one node
if len(availableNodes) == 0 {
return fmt.Errorf("no nodes available for mon placement")
}
nodeIndex := 0
for _, m := range mons {
if _, ok := c.mapping.Node[m.Name]; ok {
@@ -318,7 +332,7 @@ func (c *Cluster) assignMons(mons []*monConfig) error {
nodeIndex++
}
logger.Debug("assigned mons to nodes")
logger.Debug("mons have been assigned to nodes")
return nil
}
@@ -336,7 +350,7 @@ func getNodeInfoFromNode(n v1.Node) (*NodeInfo, error) {
}
}
if nr.Address == "" {
return nil, fmt.Errorf("no IP given for node %s", nr.Name)
return nil, fmt.Errorf("couldn't get IP of node %s", nr.Name)
}
return nr, nil
}
@@ -425,8 +439,8 @@ func (c *Cluster) getMonNodes() ([]v1.Node, error) {
}
logger.Infof("Found %d running nodes without mons", len(availableNodes))
// if all nodes already have mons, just add all nodes to be available
if len(availableNodes) == 0 {
// if all nodes already have mons and the user has given the mon.count, add all nodes to be available
if c.AllowMultiplePerNode && len(availableNodes) == 0 {
logger.Infof("All nodes are running mons. Adding all %d nodes to the availability.", len(nodes.Items))
for _, node := range nodes.Items {
if validNode(node, c.placement) {
@@ -434,9 +448,6 @@ func (c *Cluster) getMonNodes() ([]v1.Node, error) {
}
}
}
if len(availableNodes) == 0 {
return nil, fmt.Errorf("no nodes are available for mons")
}
return availableNodes, nil
}
+73 -101
View File
@@ -16,20 +16,20 @@ limitations under the License.
package mon
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
"strings"
"testing"
"time"
"os"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/daemon/ceph/client"
clienttest "github.com/rook/rook/pkg/daemon/ceph/client/test"
cephmon "github.com/rook/rook/pkg/daemon/ceph/mon"
cephtest "github.com/rook/rook/pkg/daemon/ceph/test"
"github.com/rook/rook/pkg/operator/test"
@@ -50,6 +50,10 @@ func newTestStartCluster(namespace string) *clusterd.Context {
}
return "", nil
},
MockExecuteCommandWithOutputFile: func(debug bool, actionName string, command string, outFileArg string, args ...string) (string, error) {
// mock quorum health check because a second `Start()` triggers a health check
return clienttest.MonInQuorumResponseMany(3), nil
},
}
return &clusterd.Context{
Clientset: clientset,
@@ -60,16 +64,17 @@ func newTestStartCluster(namespace string) *clusterd.Context {
func newCluster(context *clusterd.Context, namespace string, hostNetwork bool, resources v1.ResourceRequirements) *Cluster {
return &Cluster{
HostNetwork: hostNetwork,
context: context,
Namespace: namespace,
Version: "myversion",
Size: 3,
maxMonID: -1,
waitForStart: false,
monPodRetryInterval: 10 * time.Millisecond,
monPodTimeout: 1 * time.Second,
monTimeoutList: map[string]time.Time{},
HostNetwork: hostNetwork,
context: context,
Namespace: namespace,
Version: "myversion",
Size: 3,
AllowMultiplePerNode: true,
maxMonID: -1,
waitForStart: false,
monPodRetryInterval: 10 * time.Millisecond,
monPodTimeout: 1 * time.Second,
monTimeoutList: map[string]time.Time{},
mapping: &Mapping{
Node: map[string]*NodeInfo{},
Port: map[string]int32{},
@@ -100,38 +105,6 @@ func TestStartMonPods(t *testing.T) {
func TestOperatorRestart(t *testing.T) {
namespace := "ns"
context := newTestStartCluster(namespace)
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(debug bool, actionName string, command string, arg ...string) (string, error) {
if strings.Contains(command, "ceph-authtool") {
cephtest.CreateConfigDir(path.Join(context.ConfigDir, namespace))
}
return "", nil
},
MockExecuteCommandWithOutputFile: func(debug bool, actionName string, command string, outFileArg string, args ...string) (string, error) {
cephtest.CreateConfigDir(path.Join(context.ConfigDir, namespace))
resp := client.MonStatusResponse{Quorum: []int{0}}
resp.MonMap.Mons = []client.MonMapEntry{
{
Name: "rook-ceph-mon0",
Rank: 0,
Address: "0.0.0.0",
},
{
Name: "rook-ceph-mon1",
Rank: 0,
Address: "0.0.0.0",
},
{
Name: "rook-ceph-mon2",
Rank: 0,
Address: "0.0.0.0",
},
}
serialized, _ := json.Marshal(resp)
return string(serialized), nil
},
}
context.Executor = executor
c := newCluster(context, namespace, false, v1.ResourceRequirements{})
c.clusterInfo = test.CreateConfigDir(1)
@@ -154,38 +127,6 @@ func TestOperatorRestart(t *testing.T) {
func TestOperatorRestartHostNetwork(t *testing.T) {
namespace := "ns"
context := newTestStartCluster(namespace)
executor := &exectest.MockExecutor{
MockExecuteCommandWithOutput: func(debug bool, actionName string, command string, arg ...string) (string, error) {
if strings.Contains(command, "ceph-authtool") {
cephtest.CreateConfigDir(path.Join(context.ConfigDir, namespace))
}
return "", nil
},
MockExecuteCommandWithOutputFile: func(debug bool, actionName string, command string, outFileArg string, args ...string) (string, error) {
cephtest.CreateConfigDir(path.Join(context.ConfigDir, namespace))
resp := client.MonStatusResponse{Quorum: []int{0}}
resp.MonMap.Mons = []client.MonMapEntry{
{
Name: "rook-ceph-mon0",
Rank: 0,
Address: "0.0.0.0",
},
{
Name: "rook-ceph-mon1",
Rank: 0,
Address: "0.0.0.0",
},
{
Name: "rook-ceph-mon2",
Rank: 0,
Address: "0.0.0.0",
},
}
serialized, _ := json.Marshal(resp)
return string(serialized), nil
},
}
context.Executor = executor
c := newCluster(context, namespace, false, v1.ResourceRequirements{})
c.clusterInfo = test.CreateConfigDir(1)
@@ -218,7 +159,9 @@ func TestSaveMonEndpoints(t *testing.T) {
clientset := test.New(1)
configDir, _ := ioutil.TempDir("", "")
defer os.RemoveAll(configDir)
c := New(&clusterd.Context{Clientset: clientset, ConfigDir: configDir}, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset, ConfigDir: configDir}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{}, false,
v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(1)
// create the initial config map
@@ -227,14 +170,14 @@ func TestSaveMonEndpoints(t *testing.T) {
cm, err := c.context.Clientset.CoreV1().ConfigMaps(c.Namespace).Get(EndpointConfigMapName, metav1.GetOptions{})
assert.Nil(t, err)
assert.Equal(t, "mon1=1.2.3.1:6790", cm.Data[EndpointDataKey])
assert.Equal(t, "rook-ceph-mon1=1.2.3.1:6790", cm.Data[EndpointDataKey])
assert.Equal(t, `{"node":{},"port":{}}`, cm.Data[MappingKey])
assert.Equal(t, "-1", cm.Data[MaxMonIDKey])
// update the config map
c.clusterInfo.Monitors["mon1"].Endpoint = "2.3.4.5:6790"
c.clusterInfo.Monitors["rook-ceph-mon1"].Endpoint = "2.3.4.5:6790"
c.maxMonID = 2
c.mapping.Node["mon1"] = &NodeInfo{
c.mapping.Node["rook-ceph-mon1"] = &NodeInfo{
Name: "node0",
Address: "1.1.1.1",
Hostname: "myhost",
@@ -245,8 +188,8 @@ func TestSaveMonEndpoints(t *testing.T) {
cm, err = c.context.Clientset.CoreV1().ConfigMaps(c.Namespace).Get(EndpointConfigMapName, metav1.GetOptions{})
assert.Nil(t, err)
assert.Equal(t, "mon1=2.3.4.5:6790", cm.Data[EndpointDataKey])
assert.Equal(t, `{"node":{"mon1":{"Name":"node0","Hostname":"myhost","Address":"1.1.1.1"}},"port":{"node0":12345}}`, cm.Data[MappingKey])
assert.Equal(t, "rook-ceph-mon1=2.3.4.5:6790", cm.Data[EndpointDataKey])
assert.Equal(t, `{"node":{"rook-ceph-mon1":{"Name":"node0","Hostname":"myhost","Address":"1.1.1.1"}},"port":{"node0":12345}}`, cm.Data[MappingKey])
assert.Equal(t, "2", cm.Data[MaxMonIDKey])
}
@@ -290,24 +233,36 @@ func TestMonID(t *testing.T) {
func TestAvailableMonNodes(t *testing.T) {
clientset := test.New(1)
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{},
false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
nodes, err := c.getMonNodes()
assert.Nil(t, err)
assert.Equal(t, 1, len(nodes))
// set node to not ready
conditions := v1.NodeCondition{Type: v1.NodeOutOfDisk}
nodes[0].Status = v1.NodeStatus{Conditions: []v1.NodeCondition{conditions}}
clientset.CoreV1().Nodes().Update(&nodes[0])
// when the node is not ready there should be no nodes returned and an error
emptyNodes, err := c.getMonNodes()
assert.NotNil(t, err)
assert.Nil(t, emptyNodes)
assert.Nil(t, err)
assert.Equal(t, 0, len(emptyNodes))
// even if AllowMultiplePerNode is true there should be no node returned
c.AllowMultiplePerNode = true
emptyNodes, err = c.getMonNodes()
assert.Nil(t, err)
assert.Equal(t, 0, len(emptyNodes))
}
func TestAvailableNodesInUse(t *testing.T) {
clientset := test.New(3)
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{},
false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
// all three nodes are available by default
@@ -326,19 +281,29 @@ func TestAvailableNodesInUse(t *testing.T) {
assert.Equal(t, 1, len(reducedNodes))
assert.Equal(t, nodes[2].Name, reducedNodes[0].Name)
// start pods on the remaining node. We expect all nodes to be available for placement
// start pods on the remaining node. We expect no nodes to be available for placement
// since there is no way to place a mon on an unused node.
pod := c.makeMonPod(&monConfig{Name: "mon2"}, nodes[2].Name)
pod := c.makeMonPod(&monConfig{Name: "rook-ceph-mon2"}, nodes[2].Name)
_, err = clientset.CoreV1().Pods(c.Namespace).Create(pod)
assert.Nil(t, err)
nodes, err = c.getMonNodes()
// no mon nodes is no error, just an empty nodes list
assert.Nil(t, err)
assert.Equal(t, 3, len(nodes))
// no nodes should be returned when AllowMultiplePerNode is false
c.AllowMultiplePerNode = false
nodes, err = c.getMonNodes()
// no mon nodes is no error, just an empty nodes list
assert.Nil(t, err)
assert.Equal(t, 0, len(nodes))
}
func TestTaintedNodes(t *testing.T) {
clientset := test.New(3)
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{},
false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
nodes, err := c.getMonNodes()
@@ -371,7 +336,9 @@ func TestTaintedNodes(t *testing.T) {
func TestNodeAffinity(t *testing.T) {
clientset := test.New(3)
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{},
false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
nodes, err := c.getMonNodes()
@@ -411,7 +378,9 @@ func TestNodeAffinity(t *testing.T) {
func TestHostNetwork(t *testing.T) {
clientset := test.New(3)
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{},
false, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
c.HostNetwork = true
@@ -420,7 +389,7 @@ func TestHostNetwork(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, 3, len(nodes))
pod := c.makeMonPod(&monConfig{Name: "mon2"}, nodes[2].Name)
pod := c.makeMonPod(&monConfig{Name: "rook-ceph-mon2"}, nodes[2].Name)
assert.NotNil(t, pod)
assert.Equal(t, true, pod.Spec.HostNetwork)
@@ -441,7 +410,9 @@ func TestGetNodeInfoFromNode(t *testing.T) {
},
}
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion", 3, rookalpha.Placement{}, true, v1.ResourceRequirements{}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", "", "myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{},
true, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
var info *NodeInfo
@@ -470,16 +441,17 @@ func TestHostNetworkPortIncrease(t *testing.T) {
c := New(&clusterd.Context{
Clientset: clientset,
ConfigDir: configDir,
}, "ns", "", "myversion", 3, rookalpha.Placement{}, true, v1.ResourceRequirements{}, metav1.OwnerReference{})
}, "ns", "", "myversion", cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true},
rookalpha.Placement{}, true, v1.ResourceRequirements{}, metav1.OwnerReference{})
c.clusterInfo = test.CreateConfigDir(0)
mons := []*monConfig{
{
Name: "mon1",
Name: "rook-ceph-mon1",
Port: cephmon.DefaultPort,
},
{
Name: "mon2",
Name: "rook-ceph-mon2",
Port: cephmon.DefaultPort,
},
}
@@ -490,11 +462,11 @@ func TestHostNetworkPortIncrease(t *testing.T) {
err = c.initMonIPs(mons)
assert.Nil(t, err)
assert.Equal(t, node.Name, c.mapping.Node["mon1"].Name)
assert.Equal(t, node.Name, c.mapping.Node["mon2"].Name)
assert.Equal(t, node.Name, c.mapping.Node["rook-ceph-mon1"].Name)
assert.Equal(t, node.Name, c.mapping.Node["rook-ceph-mon2"].Name)
sEndpoint := strings.Split(c.clusterInfo.Monitors["mon1"].Endpoint, ":")
sEndpoint := strings.Split(c.clusterInfo.Monitors["rook-ceph-mon1"].Endpoint, ":")
assert.Equal(t, strconv.Itoa(cephmon.DefaultPort), sEndpoint[1])
sEndpoint = strings.Split(c.clusterInfo.Monitors["mon2"].Endpoint, ":")
sEndpoint = strings.Split(c.clusterInfo.Monitors["rook-ceph-mon2"].Endpoint, ":")
assert.Equal(t, strconv.Itoa(cephmon.DefaultPort+1), sEndpoint[1])
}
+15 -12
View File
@@ -19,6 +19,7 @@ import (
"fmt"
"testing"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
rookalpha "github.com/rook/rook/pkg/apis/rook.io/v1alpha2"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/operator/k8sutil"
@@ -36,20 +37,22 @@ func TestPodSpecs(t *testing.T) {
func testPodSpec(t *testing.T, dataDir string) {
clientset := testop.New(1)
c := New(&clusterd.Context{Clientset: clientset}, "ns", dataDir, "rook/rook:myversion", 3, rookalpha.Placement{}, false, v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: *resource.NewQuantity(100.0, resource.BinarySI),
},
Requests: v1.ResourceList{
v1.ResourceMemory: *resource.NewQuantity(1337.0, resource.BinarySI),
},
}, metav1.OwnerReference{})
c := New(&clusterd.Context{Clientset: clientset}, "ns", dataDir, "rook/rook:myversion",
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, rookalpha.Placement{}, false,
v1.ResourceRequirements{
Limits: v1.ResourceList{
v1.ResourceCPU: *resource.NewQuantity(100.0, resource.BinarySI),
},
Requests: v1.ResourceList{
v1.ResourceMemory: *resource.NewQuantity(1337.0, resource.BinarySI),
},
}, metav1.OwnerReference{})
c.clusterInfo = testop.CreateConfigDir(0)
config := &monConfig{Name: "mon0", Port: 6790}
config := &monConfig{Name: "rook-ceph-mon0", Port: 6790}
pod := c.makeMonPod(config, "foo")
assert.NotNil(t, pod)
assert.Equal(t, "mon0", pod.Name)
assert.Equal(t, "rook-ceph-mon0", pod.Name)
assert.Equal(t, v1.RestartPolicyAlways, pod.Spec.RestartPolicy)
assert.Equal(t, 2, len(pod.Spec.Volumes))
assert.Equal(t, "rook-data", pod.Spec.Volumes[0].Name)
@@ -62,7 +65,7 @@ func testPodSpec(t *testing.T, dataDir string) {
assert.Equal(t, dataDir, pod.Spec.Volumes[0].HostPath.Path)
}
assert.Equal(t, "mon0", pod.ObjectMeta.Name)
assert.Equal(t, "rook-ceph-mon0", pod.ObjectMeta.Name)
assert.Equal(t, appName, pod.ObjectMeta.Labels["app"])
assert.Equal(t, c.Namespace, pod.ObjectMeta.Labels["mon_cluster"])
@@ -75,7 +78,7 @@ func testPodSpec(t *testing.T, dataDir string) {
assert.Equal(t, "ceph", cont.Args[0])
assert.Equal(t, "mon", cont.Args[1])
assert.Equal(t, "--config-dir=/var/lib/rook", cont.Args[2])
assert.Equal(t, "--name=mon0", cont.Args[3])
assert.Equal(t, "--name=rook-ceph-mon0", cont.Args[3])
assert.Equal(t, "--port=6790", cont.Args[4])
assert.Equal(t, fmt.Sprintf("--fsid=%s", c.clusterInfo.FSID), cont.Args[5])
+1 -1
View File
@@ -33,7 +33,7 @@ func CreateConfigDir(mons int) *mon.ClusterInfo {
Monitors: map[string]*mon.CephMonitorConfig{},
}
for i := 1; i <= mons; i++ {
id := fmt.Sprintf("mon%d", i)
id := fmt.Sprintf("rook-ceph-mon%d", i)
c.Monitors[id] = &mon.CephMonitorConfig{
Name: id,
Endpoint: fmt.Sprintf("1.2.3.%d:6790", i),
+6 -6
View File
@@ -98,8 +98,7 @@ spec:
plural: volumes
singular: volume
scope: Namespaced
version: v1alpha2
`
version: v1alpha2`
}
//GetRookOperator returns rook Operator manifest
@@ -254,8 +253,10 @@ metadata:
spec:
dataDirHostPath: ` + dataDirHostPath + `
network:
hostNetwork: false
monCount: ` + strconv.Itoa(mons) + `
hostNetwork: false
mon:
count: ` + strconv.Itoa(mons) + `
allowMultiplePerNode: true
metadataDevice:
storage:
useAllNodes: true
@@ -265,8 +266,7 @@ spec:
config:
storeType: "` + storeType + `"
databaseSizeMB: "1024"
journalSizeMB: "1024"
`
journalSizeMB: "1024"`
}
//GetRookToolBox returns rook-toolbox manifest
+13 -7
View File
@@ -28,6 +28,7 @@ import (
"github.com/coreos/pkg/capnslog"
"github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
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/osd/config"
@@ -147,12 +148,13 @@ func (h *InstallHelper) CreateK8sRookToolbox(namespace string) (err error) {
}
func (h *InstallHelper) CreateK8sRookCluster(namespace string, storeType string) (err error) {
return h.CreateK8sRookClusterWithHostPathAndDevices(namespace, storeType, "", false, 1, true /* startWithAllNodes */)
return h.CreateK8sRookClusterWithHostPathAndDevices(namespace, storeType, "", false,
cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true}, true /* startWithAllNodes */)
}
//CreateK8sRookCluster creates rook cluster via kubectl
func (h *InstallHelper) CreateK8sRookClusterWithHostPathAndDevices(namespace, storeType, dataDirHostPath string,
useAllDevices bool, mons int, startWithAllNodes bool) error {
useAllDevices bool, mon cephv1alpha1.MonSpec, startWithAllNodes bool) error {
ns := &v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}}
_, err := h.k8shelper.Clientset.CoreV1().Namespaces().Create(ns)
@@ -170,7 +172,10 @@ func (h *InstallHelper) CreateK8sRookClusterWithHostPathAndDevices(namespace, st
},
Spec: v1alpha1.ClusterSpec{
DataDirHostPath: dataDirHostPath,
MonCount: mons,
Mon: v1alpha1.MonSpec{
Count: mon.Count,
AllowMultiplePerNode: mon.AllowMultiplePerNode,
},
Storage: rookalpha.StorageScopeSpec{
UseAllNodes: startWithAllNodes,
Selection: rookalpha.Selection{
@@ -216,13 +221,13 @@ func (h *InstallHelper) CreateK8sRookClusterWithHostPathAndDevices(namespace, st
}
} else {
logger.Infof("Starting Rook Cluster with yaml")
rookCluster := h.installData.GetRookCluster(namespace, storeType, dataDirHostPath, useAllDevices, mons)
rookCluster := h.installData.GetRookCluster(namespace, storeType, dataDirHostPath, useAllDevices, mon.Count)
if _, err := h.k8shelper.KubectlWithStdin(rookCluster, createArgs...); err != nil {
return fmt.Errorf("Failed to create rook cluster : %v ", err)
}
}
err = h.k8shelper.WaitForPodCount("app=rook-ceph-mon", namespace, mons)
err = h.k8shelper.WaitForPodCount("app=rook-ceph-mon", namespace, mon.Count)
if err != nil {
return err
}
@@ -243,7 +248,7 @@ func SystemNamespace(namespace string) string {
//InstallRookOnK8sWithHostPathAndDevices installs rook on k8s
func (h *InstallHelper) InstallRookOnK8sWithHostPathAndDevices(namespace, storeType, dataDirHostPath string,
helmInstalled, useDevices bool, mons int, startWithAllNodes bool) (bool, error) {
helmInstalled, useDevices bool, mon cephv1alpha1.MonSpec, startWithAllNodes bool) (bool, error) {
var err error
//flag used for local debuggin purpose, when rook is pre-installed
@@ -285,7 +290,8 @@ func (h *InstallHelper) InstallRookOnK8sWithHostPathAndDevices(namespace, storeT
}
//Create rook cluster
err = h.CreateK8sRookClusterWithHostPathAndDevices(namespace, storeType, dataDirHostPath, useDevices, mons, startWithAllNodes)
err = h.CreateK8sRookClusterWithHostPathAndDevices(namespace, storeType, dataDirHostPath,
useDevices, cephv1alpha1.MonSpec{Count: mon.Count, AllowMultiplePerNode: mon.AllowMultiplePerNode}, startWithAllNodes)
if err != nil {
logger.Errorf("Rook cluster %s not installed, error -> %v", namespace, err)
return false, err
+3 -1
View File
@@ -23,6 +23,7 @@ import (
"testing"
"github.com/coreos/pkg/capnslog"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
"github.com/rook/rook/tests/framework/clients"
"github.com/rook/rook/tests/framework/contracts"
"github.com/rook/rook/tests/framework/installer"
@@ -126,7 +127,8 @@ func StartBaseTestOperations(t func() *testing.T, namespace, storeType, dataDirH
//SetUpRook is a wrapper for setting up rook
func (op BaseTestOperations) SetUp() {
isRookInstalled, err := op.installer.InstallRookOnK8sWithHostPathAndDevices(op.namespace, op.storeType,
op.dataDirHostPath, op.helmInstalled, op.useDevices, op.mons, false /* startWithAllNodes */)
op.dataDirHostPath, op.helmInstalled, op.useDevices,
cephv1alpha1.MonSpec{Count: op.mons, AllowMultiplePerNode: true}, false /* startWithAllNodes */)
assert.NoError(op.T(), err)
if !isRookInstalled {
logger.Errorf("Rook was not installed successfully")
+4 -1
View File
@@ -6,6 +6,7 @@ import (
"testing"
"time"
cephv1alpha1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1alpha1"
"github.com/rook/rook/tests/framework/clients"
"github.com/rook/rook/tests/framework/installer"
"github.com/rook/rook/tests/framework/utils"
@@ -158,7 +159,9 @@ func StartBaseLoadTestOperations(t func() *testing.T, namespace string) (BaseLoa
func (o BaseLoadTestOperations) SetUp() {
if !o.kh.IsRookInstalled(o.namespace) {
isRookInstalled, err := o.installer.InstallRookOnK8sWithHostPathAndDevices(o.namespace, "bluestore", "/temp/rookBackup", false, true, 3, true /* startWithAllNodes */)
isRookInstalled, err := o.installer.InstallRookOnK8sWithHostPathAndDevices(o.namespace, "bluestore",
"/temp/rookBackup", false, true, cephv1alpha1.MonSpec{Count: 3, AllowMultiplePerNode: true},
true /* startWithAllNodes */)
require.NoError(o.T(), err)
require.True(o.T(), isRookInstalled)