Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into BZ-2251308
Browse files Browse the repository at this point in the history
  • Loading branch information
bernerhat committed Jan 29, 2024
2 parents eb64ba7 + 7cfec77 commit aff1032
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 1,353 deletions.
63 changes: 16 additions & 47 deletions controllers/operatorconfigmap_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ import (
"github.com/red-hat-storage/ocs-client-operator/pkg/csi"
"github.com/red-hat-storage/ocs-client-operator/pkg/templates"

csiaddonsv1alpha1 "github.com/csi-addons/kubernetes-csi-addons/apis/csiaddons/v1alpha1"
"github.com/go-logr/logr"
configv1 "github.com/openshift/api/config/v1"
secv1 "github.com/openshift/api/security/v1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -75,6 +73,7 @@ type OperatorConfigMapReconciler struct {
rbdDeployment *appsv1.Deployment
rbdDaemonSet *appsv1.DaemonSet
scc *secv1.SecurityContextConstraints
operatorConfigMap *corev1.ConfigMap
}

// SetupWithManager sets up the controller with the Manager.
Expand All @@ -97,7 +96,8 @@ func (c *OperatorConfigMapReconciler) SetupWithManager(mgr ctrl.Manager) error {
func(_ context.Context, client client.Object) []reconcile.Request {
return []reconcile.Request{{
NamespacedName: types.NamespacedName{
Name: operatorConfigMapName,
Name: operatorConfigMapName,
Namespace: client.GetNamespace(),
},
}}
},
Expand Down Expand Up @@ -131,19 +131,18 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
c.log = log.FromContext(ctx, "OperatorConfigMap", req)
c.log.Info("Reconciling OperatorConfigMap")

if err := c.ensureConsolePlugin(); err != nil {
c.log.Error(err, "unable to deploy client console")
c.operatorConfigMap = &corev1.ConfigMap{}
if err = c.Client.Get(c.ctx, req.NamespacedName, c.operatorConfigMap); err != nil {
return ctrl.Result{}, err
}

instance := corev1.ConfigMap{}
if err = c.Client.Get(context.TODO(), req.NamespacedName, &instance); err != nil {
if err := c.ensureConsolePlugin(); err != nil {
c.log.Error(err, "unable to deploy client console")
return ctrl.Result{}, err
}

clusterVersion := &configv1.ClusterVersion{}
err = c.Client.Get(c.ctx, types.NamespacedName{Name: clusterVersionName}, clusterVersion)
if err != nil {
if err := c.Client.Get(c.ctx, types.NamespacedName{Name: clusterVersionName}, clusterVersion); err != nil {
c.log.Error(err, "failed to get the clusterVersion version of the OCP cluster")
return reconcile.Result{}, err
}
Expand Down Expand Up @@ -185,8 +184,7 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
if err := c.own(monConfigMap); err != nil {
return ctrl.Result{}, err
}
err = c.create(monConfigMap)
if err != nil && !k8serrors.IsAlreadyExists(err) {
if err := c.create(monConfigMap); err != nil && !k8serrors.IsAlreadyExists(err) {
c.log.Error(err, "failed to create monitor configmap", "name", monConfigMap.Name)
return ctrl.Result{}, err
}
Expand All @@ -206,8 +204,7 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
if err := c.own(monConfigMap); err != nil {
return ctrl.Result{}, err
}
err = c.create(encConfigMap)
if err != nil && !k8serrors.IsAlreadyExists(err) {
if err := c.create(encConfigMap); err != nil && !k8serrors.IsAlreadyExists(err) {
c.log.Error(err, "failed to create monitor configmap", "name", encConfigMap.Name)
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -287,32 +284,29 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re
// Need to handle deletion of the csiDriver object, we cannot set
// ownerReference on it as its cluster scoped resource
cephfsCSIDriver := templates.CephFSCSIDriver.DeepCopy()
cephfsCSIDriver.ObjectMeta.Name = csi.GetCephFSDriverName(c.OperatorNamespace)
err = csi.CreateCSIDriver(c.ctx, c.Client, cephfsCSIDriver)
if err != nil {
cephfsCSIDriver.ObjectMeta.Name = csi.GetCephFSDriverName()
if err := csi.CreateCSIDriver(c.ctx, c.Client, cephfsCSIDriver); err != nil {
c.log.Error(err, "unable to create cephfs CSIDriver")
return ctrl.Result{}, err
}

rbdCSIDriver := templates.RbdCSIDriver.DeepCopy()
rbdCSIDriver.ObjectMeta.Name = csi.GetRBDDriverName(c.OperatorNamespace)
err = csi.CreateCSIDriver(c.ctx, c.Client, rbdCSIDriver)
if err != nil {
rbdCSIDriver.ObjectMeta.Name = csi.GetRBDDriverName()
if err := csi.CreateCSIDriver(c.ctx, c.Client, rbdCSIDriver); err != nil {
c.log.Error(err, "unable to create rbd CSIDriver")
return ctrl.Result{}, err
}

prometheusRule := &monitoringv1.PrometheusRule{}
err = k8sYAML.NewYAMLOrJSONDecoder(bytes.NewBufferString(string(pvcPrometheusRules)), 1000).Decode(prometheusRule)
if err != nil {
if err := k8sYAML.NewYAMLOrJSONDecoder(bytes.NewBufferString(string(pvcPrometheusRules)), 1000).Decode(prometheusRule); err != nil {
c.log.Error(err, "Unable to retrieve prometheus rules.", "prometheusRule", klog.KRef(prometheusRule.Namespace, prometheusRule.Name))
return ctrl.Result{}, err
}

prometheusRule.SetNamespace(c.OperatorNamespace)

err = c.createOrUpdate(prometheusRule, func() error {
applyLabels(instance.Data["OCS_METRICS_LABELS"], &prometheusRule.ObjectMeta)
applyLabels(c.operatorConfigMap.Data["OCS_METRICS_LABELS"], &prometheusRule.ObjectMeta)
return c.own(prometheusRule)
})
if err != nil {
Expand All @@ -322,34 +316,9 @@ func (c *OperatorConfigMapReconciler) Reconcile(ctx context.Context, req ctrl.Re

c.log.Info("prometheus rules deployed", "prometheusRule", klog.KRef(prometheusRule.Namespace, prometheusRule.Name))

// deletion phase
if !instance.GetDeletionTimestamp().IsZero() {
err = c.deletionPhase(&instance, &req)
if err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
}

func (c *OperatorConfigMapReconciler) deletionPhase(instance *corev1.ConfigMap, req *ctrl.Request) error {
csiAddonsNode := &csiaddonsv1alpha1.CSIAddonsNode{}
err := c.Client.Get(c.ctx, req.NamespacedName, csiAddonsNode)
if err != nil {
if apierrors.IsNotFound(err) {
// Request object not found, could have been deleted before reconcile request.
c.log.Info("CSIAddonsNode resource not found")
return nil
}
return err
}
csiAddonsNode.Finalizers = nil
if err := c.Client.Update(c.ctx, csiAddonsNode); err != nil {
c.log.Error(err, "Failed to remove finalizer from csiAddonsNode")
return err
}
return nil
}
func (c *OperatorConfigMapReconciler) createOrUpdate(obj client.Object, f controllerutil.MutateFn) error {
result, err := controllerutil.CreateOrUpdate(c.ctx, c.Client, obj, f)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions controllers/storageclassclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (r *StorageClassClaimReconciler) getCephFSStorageClass(data map[string]stri
},
ReclaimPolicy: &pvReclaimPolicy,
AllowVolumeExpansion: &allowVolumeExpansion,
Provisioner: fmt.Sprintf("%s.cephfs.csi.ceph.com", r.OperatorNamespace),
Provisioner: csi.GetCephFSDriverName(),
Parameters: data,
}
return storageClass
Expand All @@ -479,7 +479,7 @@ func (r *StorageClassClaimReconciler) getCephRBDStorageClass(data map[string]str
},
ReclaimPolicy: &pvReclaimPolicy,
AllowVolumeExpansion: &allowVolumeExpansion,
Provisioner: fmt.Sprintf("%s.rbd.csi.ceph.com", r.OperatorNamespace),
Provisioner: csi.GetRBDDriverName(),
Parameters: data,
}
return storageClass
Expand All @@ -490,7 +490,7 @@ func (r *StorageClassClaimReconciler) getCephFSVolumeSnapshotClass(data map[stri
ObjectMeta: metav1.ObjectMeta{
Name: r.storageClassClaim.Name,
},
Driver: fmt.Sprintf("%s.cephfs.csi.ceph.com", r.OperatorNamespace),
Driver: csi.GetCephFSDriverName(),
DeletionPolicy: snapapi.VolumeSnapshotContentDelete,
Parameters: data,
}
Expand All @@ -502,7 +502,7 @@ func (r *StorageClassClaimReconciler) getCephRBDVolumeSnapshotClass(data map[str
ObjectMeta: metav1.ObjectMeta{
Name: r.storageClassClaim.Name,
},
Driver: fmt.Sprintf("%s.rbd.csi.ceph.com", r.OperatorNamespace),
Driver: csi.GetRBDDriverName(),
DeletionPolicy: snapapi.VolumeSnapshotContentDelete,
Parameters: data,
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ replace (
exclude github.com/kubernetes-incubator/external-storage v0.20.4-openstorage-rc2

require (
github.com/csi-addons/kubernetes-csi-addons v0.8.0
github.com/go-logr/logr v1.3.0
github.com/kubernetes-csi/external-snapshotter/client/v6 v6.3.0
github.com/onsi/ginkgo v1.16.5
Expand Down Expand Up @@ -77,7 +76,7 @@ require (
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2y
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/csi-addons/kubernetes-csi-addons v0.8.0 h1:zvYGp4DM6KdQzEX3dQSYKykqJdLZlxpVBJjtpbaqFjs=
github.com/csi-addons/kubernetes-csi-addons v0.8.0/go.mod h1:dvinzoiXlqdOGDpKkYx8Jxl507BzVEEEO+SI0OmBaRI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
Expand Down Expand Up @@ -218,8 +216,8 @@ gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 h1:6GQBEOdGkX6MMTLT9V+TjtIRZCw9VPD5Z+yHY9wMgS0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97/go.mod h1:v7nGkzlmW8P3n/bKmWBn2WpBjpOEx8Q6gMueudAmKfY=
google.golang.org/grpc v1.60.0 h1:6FQAR0kM31P6MRdeluor2w2gPaS4SVNrD/DNTxrQ15k=
google.golang.org/grpc v1.60.0/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand Down
6 changes: 3 additions & 3 deletions pkg/csi/cephfsdaemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func GetCephFSDaemonSet(namespace string) *appsv1.DaemonSet {
driverRegistrar.Args,
fmt.Sprintf("--kubelet-registration-path=%s/plugins/%s/csi.sock",
templates.DefaultKubeletDirPath,
GetCephFSDriverName(namespace)),
GetCephFSDriverName()),
)
return &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -93,7 +93,7 @@ func GetCephFSDaemonSet(namespace string) *appsv1.DaemonSet {
"--pidlimit=-1",
"--type=cephfs",
"--nodeserver=true",
fmt.Sprintf("--drivername=%s", GetCephFSDriverName(namespace)),
fmt.Sprintf("--drivername=%s", GetCephFSDriverName()),
},
Resources: templates.CephFSPluginResourceRequirements,
Env: []corev1.EnvVar{
Expand Down Expand Up @@ -230,7 +230,7 @@ func GetCephFSDaemonSet(namespace string) *appsv1.DaemonSet {
Name: "plugin-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: fmt.Sprintf("%s/plugins/%s", templates.DefaultKubeletDirPath, GetCephFSDriverName(namespace)),
Path: fmt.Sprintf("%s/plugins/%s", templates.DefaultKubeletDirPath, GetCephFSDriverName()),
Type: &hostPathDirectoryorCreate,
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/cephfsdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func GetCephFSDeployment(namespace string) *appsv1.Deployment {
"--pidlimit=-1",
"--type=cephfs",
"--controllerserver=true",
fmt.Sprintf("--drivername=%s", GetCephFSDriverName(namespace)),
fmt.Sprintf("--drivername=%s", GetCephFSDriverName()),
},
Resources: templates.CephFSPluginResourceRequirements,
Env: []corev1.EnvVar{
Expand Down
8 changes: 4 additions & 4 deletions pkg/csi/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ func InitializeSidecars(ver string) error {
}

// GetCephFSDriverName returns the cephfs driver name
func GetCephFSDriverName(namespace string) string {
return fmt.Sprintf("%s.cephfs.csi.ceph.com", namespace)
func GetCephFSDriverName() string {
return "openshift-storage.cephfs.csi.ceph.com"
}

// GetRBDDriverName returns the rbd driver name
func GetRBDDriverName(namespace string) string {
return fmt.Sprintf("%s.rbd.csi.ceph.com", namespace)
func GetRBDDriverName() string {
return "openshift-storage.rbd.csi.ceph.com"
}
6 changes: 3 additions & 3 deletions pkg/csi/rbddaemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func GetRBDDaemonSet(namespace string) *appsv1.DaemonSet {
driverRegistrar.Args,
fmt.Sprintf("--kubelet-registration-path=%s/plugins/%s/csi.sock",
templates.DefaultKubeletDirPath,
GetRBDDriverName(namespace)),
GetRBDDriverName()),
)
return &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -106,7 +106,7 @@ func GetRBDDaemonSet(namespace string) *appsv1.DaemonSet {
"--pidlimit=-1",
"--type=rbd",
"--nodeserver=true",
fmt.Sprintf("--drivername=%s", GetRBDDriverName(namespace)),
fmt.Sprintf("--drivername=%s", GetRBDDriverName()),
fmt.Sprintf("--stagingpath=%s/plugins/kubernetes.io/csi/", templates.DefaultKubeletDirPath),
"--csi-addons-endpoint=$(CSIADDONS_ENDPOINT)",
},
Expand Down Expand Up @@ -327,7 +327,7 @@ func GetRBDDaemonSet(namespace string) *appsv1.DaemonSet {
Name: "plugin-dir",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: fmt.Sprintf("%s/plugins/%s", templates.DefaultKubeletDirPath, GetRBDDriverName(namespace)),
Path: fmt.Sprintf("%s/plugins/%s", templates.DefaultKubeletDirPath, GetRBDDriverName()),
Type: &hostPathDirectoryorCreate,
},
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/rbddeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func GetRBDDeployment(namespace string) *appsv1.Deployment {
"--pidlimit=-1",
"--type=rbd",
"--controllerserver=true",
fmt.Sprintf("--drivername=%s", GetRBDDriverName(namespace)),
fmt.Sprintf("--drivername=%s", GetRBDDriverName()),
},
Resources: templates.RBDPluginResourceRequirements,
Env: []corev1.EnvVar{
Expand Down
Loading

0 comments on commit aff1032

Please sign in to comment.