Files
my-rook-config/pkg/operator/ceph/csi/operator_config.go
T
Sonny Sasaka dff04494fe csi: fix swapped provisionerPriorityClassName with pluginPriorityClassName
Previously provisionerPriorityClassName config is applied to node plugin
but pluginPriorityClassName is applied to controller plugin. This causes
a misconfiguration since the default values for
provisionerPriorityClassName is system-cluster-critical and
pluginPriorityClassName is system-node-critical.

The default priority for node plugin ought to be system-node-critical so
we can leverage this information to kill the pods in this priority last,
allowing other pods that may mount RBD-backed volume to unmount cleanly
first, otherwise the shutdown sequence may hang due to failure
unmounting RBD-backed volume when the node plugin pod is already killed.

Signed-off-by: Sonny Sasaka <sonnysasaka@gmail.com>
2026-04-16 08:30:28 -07:00

182 lines
6.4 KiB
Go

/*
Copyright 2024 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 csi
import (
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
opcontroller "github.com/rook/rook/pkg/operator/ceph/controller"
csiopv1 "github.com/ceph/ceph-csi-operator/api/v1"
"github.com/pkg/errors"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
k8scsiv1 "k8s.io/api/storage/v1"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
const (
opConfigCRName = "ceph-csi-operator-config"
)
func (r *ReconcileCSI) createOrUpdateOperatorConfig(cluster cephv1.CephCluster) error {
logger.Info("Creating ceph-CSI operator config CR")
opConfig := &csiopv1.OperatorConfig{}
opConfig.Name = opConfigCRName
opConfig.Namespace = r.opConfig.OperatorNamespace
imageSetCmName, err := r.createImageSetConfigmap()
if err != nil {
return errors.Wrapf(err, "failed to create ceph-CSI operator config ImageSetConfigmap for CR %s", opConfigCRName)
}
spec := r.generateCSIOpConfigSpec(cluster, opConfig, imageSetCmName)
err = r.client.Get(r.opManagerContext, types.NamespacedName{Name: opConfigCRName, Namespace: r.opConfig.OperatorNamespace}, opConfig)
if err != nil {
if kerrors.IsNotFound(err) {
opConfig.Spec = spec
err = r.client.Create(r.opManagerContext, opConfig)
if err != nil {
return errors.Wrapf(err, "failed to create ceph-CSI operator operator config CR %q", opConfig.Name)
}
logger.Infof("Successfully created ceph-CSI operator config CR %q", opConfig.Name)
return nil
}
return errors.Wrapf(err, "failed to get ceph-CSI operator operator config CR %q", opConfigCRName)
}
opConfig.Spec = spec
err = r.client.Update(r.opManagerContext, opConfig)
if err != nil {
return errors.Wrapf(err, "failed to update ceph-CSI operator operator config CR %q", opConfig.Name)
}
logger.Infof("Successfully updated ceph-CSI operator config CR %q", opConfig.Name)
return nil
}
func (r *ReconcileCSI) generateCSIOpConfigSpec(cluster cephv1.CephCluster, opConfig *csiopv1.OperatorConfig, imageSetCmName string) csiopv1.OperatorConfigSpec {
controllerPluginHostNetwork := opcontroller.EnforceHostNetwork() || CSIParam.EnableCSIHostNetwork
cephfsClientType := csiopv1.KernelCephFsClient
if CSIParam.ForceCephFSKernelClient == "false" {
cephfsClientType = csiopv1.AutoDetectCephFsClient
}
opConfig.Spec = csiopv1.OperatorConfigSpec{
DriverSpecDefaults: &csiopv1.DriverSpec{
Log: &csiopv1.LogSpec{
Verbosity: int(CSIParam.LogLevel),
},
ImageSet: &v1.LocalObjectReference{
Name: imageSetCmName,
},
ClusterName: &cluster.Name,
EnableMetadata: &CSIParam.CSIEnableMetadata,
GenerateOMapInfo: &CSIParam.EnableOMAPGenerator,
FsGroupPolicy: k8scsiv1.FileFSGroupPolicy,
NodePlugin: &csiopv1.NodePluginSpec{
PodCommonSpec: csiopv1.PodCommonSpec{
PrioritylClassName: &CSIParam.PluginPriorityClassName,
Affinity: &v1.Affinity{
NodeAffinity: getNodeAffinity(pluginNodeAffinityEnv, &v1.NodeAffinity{}),
},
Tolerations: getToleration(pluginTolerationsEnv, []v1.Toleration{}),
ImagePullPolicy: v1.PullPolicy(CSIParam.ImagePullPolicy),
},
Resources: csiopv1.NodePluginResourcesSpec{},
KubeletDirPath: CSIParam.KubeletDirPath,
EnableSeLinuxHostMount: &CSIParam.EnablePluginSelinuxHostMount,
},
ControllerPlugin: &csiopv1.ControllerPluginSpec{
DeploymentStrategy: &appsv1.DeploymentStrategy{
Type: appsv1.RecreateDeploymentStrategyType,
},
HostNetwork: &controllerPluginHostNetwork,
PodCommonSpec: csiopv1.PodCommonSpec{
PrioritylClassName: &CSIParam.ProvisionerPriorityClassName,
Affinity: &v1.Affinity{
NodeAffinity: getNodeAffinity(provisionerNodeAffinityEnv, &v1.NodeAffinity{}),
},
Tolerations: getToleration(provisionerTolerationsEnv, []v1.Toleration{}),
ImagePullPolicy: v1.PullPolicy(CSIParam.ImagePullPolicy),
},
Replicas: &CSIParam.ProvisionerReplicas,
Resources: csiopv1.ControllerPluginResourcesSpec{},
},
DeployCsiAddons: &CSIParam.EnableCSIAddonsSideCar,
CephFsClientType: cephfsClientType,
},
}
if CSIParam.EnableCSIEncryption {
opConfig.Spec.DriverSpecDefaults.Encryption = &csiopv1.EncryptionSpec{
ConfigMapRef: v1.LocalObjectReference{
Name: "rook-ceph-csi-kms-config",
},
}
}
return opConfig.Spec
}
func (r *ReconcileCSI) createImageSetConfigmap() (string, error) {
data := map[string]string{
"provisioner": CSIParam.ProvisionerImage,
"attacher": CSIParam.AttacherImage,
"resizer": CSIParam.ResizerImage,
"snapshotter": CSIParam.SnapshotterImage,
"registrar": CSIParam.RegistrarImage,
"plugin": CSIParam.CSIPluginImage,
"addons": CSIParam.CSIAddonsImage,
}
cm := &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "rook-csi-operator-image-set-configmap",
Namespace: r.opConfig.OperatorNamespace,
},
Data: data,
}
err := r.client.Get(r.opManagerContext, types.NamespacedName{Name: cm.Name, Namespace: r.opConfig.OperatorNamespace}, cm)
if err != nil {
if kerrors.IsNotFound(err) {
err = r.client.Create(r.opManagerContext, cm)
if err != nil {
return "", errors.Wrapf(err, "failed to create imageSet cm %q for ceph-CSI operator-config CR %q", cm.Name, opConfigCRName)
}
logger.Infof("Successfully create imageSet cm %s for ceph-CSI operator-config CR %q", cm.Name, opConfigCRName)
return cm.Name, nil
}
return "", errors.Wrapf(err, "failed to get imageSet cm %q for ceph-CSI operator-config CR %q", cm.Name, opConfigCRName)
}
cm.Data = data
err = r.client.Update(r.opManagerContext, cm)
if err != nil {
return "", errors.Wrapf(err, "failed to updated imageSet cm %q ceph-CSI operator-config CR %q", cm.Name, opConfigCRName)
}
logger.Infof("Successfully updated imageSet cm %s for ceph-CSI operator-config CR %q", cm.Name, opConfigCRName)
return cm.Name, nil
}