ceph: reduce the number of admission controller pods in small cluster

The number of admission controller pods is 2. When there is only one
node as the CI environment, one of these becomes Pending state.
Although it's harmless, it's better to reduce this value to 1.

Signed-off-by: Satoru Takeuchi <satoru.takeuchi@gmail.com>
This commit is contained in:
Satoru Takeuchi committed 2020-10-21 11:47:08 +00:00
1 parent 66636f5420
commit 081c7c4dba
1 file changed
+13 -3
+13 -3
View File
@@ -17,6 +17,8 @@ limitations under the License.
package operator
import (
"os"
"github.com/pkg/errors"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/operator/ceph/csi"
@@ -26,7 +28,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"os"
)
const (
@@ -122,7 +123,7 @@ func createWebhookDeployment(context *clusterd.Context, admissionImage string) e
secretVolumeMount := getSecretVolumeMount()
antiAffinity := csi.GetPodAntiAffinity(k8sutil.AppAttr, appName)
admissionControllerDeployment := getDeployment(secretVolume, antiAffinity, admissionImage, admission_parameters, secretVolumeMount)
admissionControllerDeployment := getDeployment(context, secretVolume, antiAffinity, admissionImage, admission_parameters, secretVolumeMount)
err := k8sutil.CreateDeployment(context.Clientset, appName, namespace, &admissionControllerDeployment)
if err != nil {
@@ -132,8 +133,17 @@ func createWebhookDeployment(context *clusterd.Context, admissionImage string) e
return nil
}
func getDeployment(secretVolume corev1.Volume, antiAffinity corev1.PodAntiAffinity, admissionImage string, admission_parameters []string, secretVolumeMount corev1.VolumeMount) v1.Deployment {
func getDeployment(context *clusterd.Context, secretVolume corev1.Volume, antiAffinity corev1.PodAntiAffinity,
admissionImage string, admission_parameters []string, secretVolumeMount corev1.VolumeMount) v1.Deployment {
var replicas int32 = 2
nodes, err := context.Clientset.CoreV1().Nodes().List(metav1.ListOptions{})
if err == nil {
if len(nodes.Items) == 1 {
replicas = 1
}
} else {
logger.Errorf("failed to get nodes. Defaulting the number of replicas of admission controller pods to 2. %v", err)
}
admissionControllerDeployment := v1.Deployment{
ObjectMeta: metav1.ObjectMeta{