Skip to content

Commit

Permalink
Merge pull request #74 from red-hat-storage/fusion-hci-4.14
Browse files Browse the repository at this point in the history
Bug 2263312: Backport fusion hci phase 2 related changes to 4.14 branch
  • Loading branch information
openshift-merge-bot[bot] authored Feb 8, 2024
2 parents c0935a9 + b7b33f2 commit 5e67773
Show file tree
Hide file tree
Showing 21 changed files with 345 additions and 242 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ spec:
- get
- patch
- update
- apiGroups:
- operators.coreos.com
resources:
- clusterserviceversions
verbs:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
Expand Down
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ rules:
- get
- patch
- update
- apiGroups:
- operators.coreos.com
resources:
- clusterserviceversions
verbs:
- get
- list
- watch
- apiGroups:
- security.openshift.io
resources:
Expand Down
6 changes: 3 additions & 3 deletions controllers/clusterversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (c *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, err
}

if err := csi.InitializeSidecars(instance.Status.Desired.Version); err != nil {
if err := csi.InitializeSidecars(c.log, instance.Status.Desired.Version); err != nil {
c.log.Error(err, "unable to initialize sidecars")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -278,15 +278,15 @@ func (c *ClusterVersionReconciler) Reconcile(ctx context.Context, req ctrl.Reque
// 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)
cephfsCSIDriver.ObjectMeta.Name = csi.GetCephFSDriverName()
err = csi.CreateCSIDriver(c.ctx, c.Client, cephfsCSIDriver)
if 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)
rbdCSIDriver.ObjectMeta.Name = csi.GetRBDDriverName()
err = csi.CreateCSIDriver(c.ctx, c.Client, rbdCSIDriver)
if err != nil {
c.log.Error(err, "unable to create rbd CSIDriver")
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
36 changes: 29 additions & 7 deletions controllers/storageclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"time"

"github.com/red-hat-storage/ocs-client-operator/api/v1alpha1"
"github.com/red-hat-storage/ocs-client-operator/pkg/utils"

configv1 "github.com/openshift/api/config/v1"
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
providerClient "github.com/red-hat-storage/ocs-operator/v4/services/provider/client"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -59,6 +61,8 @@ const (
storageClientNameLabel = "ocs.openshift.io/storageclient.name"
storageClientNamespaceLabel = "ocs.openshift.io/storageclient.namespace"
storageClientFinalizer = "storageclient.ocs.openshift.io"

csvPrefix = "ocs-client-operator"
)

// StorageClientReconciler reconciles a StorageClient object
Expand Down Expand Up @@ -110,6 +114,7 @@ func (s *StorageClientReconciler) SetupWithManager(mgr ctrl.Manager) error {
//+kubebuilder:rbac:groups=ocs.openshift.io,resources=storageclients/finalizers,verbs=update
//+kubebuilder:rbac:groups=config.openshift.io,resources=clusterversions,verbs=get;list;watch
//+kubebuilder:rbac:groups=batch,resources=cronjobs,verbs=get;list;create;update;watch;delete
//+kubebuilder:rbac:groups=operators.coreos.com,resources=clusterserviceversions,verbs=get;list;watch

func (s *StorageClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var err error
Expand Down Expand Up @@ -266,9 +271,23 @@ func (s *StorageClientReconciler) onboardConsumer(instance *v1alpha1.StorageClie
return reconcile.Result{}, fmt.Errorf("failed to get the clusterVersion version of the OCP cluster: %v", err)
}

// TODO Have a version file corresponding to the release
csvList := opv1a1.ClusterServiceVersionList{}
if err = s.list(&csvList, client.InNamespace(s.OperatorNamespace)); err != nil {
return reconcile.Result{}, fmt.Errorf("failed to list csv resources in ns: %v, err: %v", s.OperatorNamespace, err)
}
csv := utils.Find(csvList.Items, func(csv *opv1a1.ClusterServiceVersion) bool {
return strings.HasPrefix(csv.Name, csvPrefix)
})
if csv == nil {
return reconcile.Result{}, fmt.Errorf("unable to find csv with prefix %q", csvPrefix)
}
name := fmt.Sprintf("storageconsumer-%s", clusterVersion.Spec.ClusterID)
response, err := externalClusterClient.OnboardConsumer(
s.ctx, instance.Spec.OnboardingTicket, name)
onboardRequest := providerClient.NewOnboardConsumerRequest().
SetConsumerName(name).
SetOnboardingTicket(instance.Spec.OnboardingTicket).
SetClientOperatorVersion(csv.Spec.Version.String())
response, err := externalClusterClient.OnboardConsumer(s.ctx, onboardRequest)
if err != nil {
if st, ok := status.FromError(err); ok {
s.logGrpcErrorAndReportEvent(instance, OnboardConsumer, err, st.Code())
Expand Down Expand Up @@ -436,17 +455,16 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a
var podDeadLineSeconds int64 = 120
jobDeadLineSeconds := podDeadLineSeconds + 35
var keepJobResourceSeconds int32 = 600
var reducedKeptSuccecsful int32 = 1

var reducedKeptSuccecsful int32 = 1

_, err := controllerutil.CreateOrUpdate(s.ctx, s.Client, cronJob, func() error {
cronJob.Spec = batchv1.CronJobSpec{
Schedule: "* * * * *",
ConcurrencyPolicy: batchv1.ForbidConcurrent,
Schedule: "* * * * *",
ConcurrencyPolicy: batchv1.ForbidConcurrent,
SuccessfulJobsHistoryLimit: &reducedKeptSuccecsful,
JobTemplate: batchv1.JobTemplateSpec{
Spec: batchv1.JobSpec{
ActiveDeadlineSeconds: &jobDeadLineSeconds,
ActiveDeadlineSeconds: &jobDeadLineSeconds,
TTLSecondsAfterFinished: &keepJobResourceSeconds,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Expand Down Expand Up @@ -488,3 +506,7 @@ func (s *StorageClientReconciler) reconcileClientStatusReporterJob(instance *v1a
}
return reconcile.Result{}, nil
}

func (s *StorageClientReconciler) list(obj client.ObjectList, listOptions ...client.ListOption) error {
return s.Client.List(s.ctx, obj, listOptions...)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/operator-framework/api v0.17.7-0.20230626210316-aa3e49803e7b
github.com/pkg/errors v0.9.1
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.67.1
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231031112628-5ea7bff99378
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20240208112023-4f8a8f86e11a
github.com/stretchr/testify v1.8.4
google.golang.org/grpc v1.56.2
gopkg.in/yaml.v2 v2.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdO
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231031112628-5ea7bff99378 h1:D6Dzl7Iqutsk23uDS3d8cb5Vtq7K1LcaltMjkiBKsKE=
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20231031112628-5ea7bff99378/go.mod h1:qdnaB1VUiUiZsImuBXbYlbmasj645HxINdCoa43DoNY=
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20240208112023-4f8a8f86e11a h1:2pp+q0mD7TRfp5d8gXssXsSd2TDWi0ohgF1A7NNh2zk=
github.com/red-hat-storage/ocs-operator/v4 v4.0.0-20240208112023-4f8a8f86e11a/go.mod h1:ws8mb7rA9PKxPggnL/Zavw+cWXF73GAMs/K922pqx6E=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
consolev1alpha1 "github.com/openshift/api/console/v1alpha1"
secv1 "github.com/openshift/api/security/v1"
opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -58,6 +59,7 @@ func init() {
utilruntime.Must(apiv1alpha1.AddToScheme(scheme))
utilruntime.Must(monitoringv1.AddToScheme(scheme))
utilruntime.Must(consolev1alpha1.AddToScheme(scheme))
utilruntime.Must(opv1a1.AddToScheme(scheme))
//+kubebuilder:scaffold:scheme
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var (
pluginBasePath = "/"

NginxConfigMapName = fmt.Sprintf("%s-nginx-conf", DeploymentName)
pluginName = "odf-client-console"

pluginDisplayName = "OCS Client Console"
pluginDisplayName = "ODF Client Console"

servicePortName = "console-port"
serviceSecretAnnotation = "service.alpha.openshift.io/serving-cert-secret-name"
Expand Down Expand Up @@ -53,7 +54,7 @@ func GetService(port int32, namespace string) *apiv1.Service {
func GetConsolePlugin(consolePort int32, serviceNamespace string) *consolev1alpha1.ConsolePlugin {
return &consolev1alpha1.ConsolePlugin{
ObjectMeta: metav1.ObjectMeta{
Name: DeploymentName,
Name: pluginName,
},
Spec: consolev1alpha1.ConsolePluginSpec{
DisplayName: pluginDisplayName,
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
46 changes: 31 additions & 15 deletions pkg/csi/csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"

"github.com/go-logr/logr"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/util/version"
)
Expand All @@ -43,9 +44,9 @@ type SidecarImages struct {
ContainerImages containerImages `yaml:"containerImages"`
}

var sidecarImages = new(SidecarImages)
var sidecarImages *SidecarImages

func InitializeSidecars(ver string) error {
func InitializeSidecars(log logr.Logger, ver string) error {
// ready yaml files and yaml unmarshal to SidecarImages
// and set to csiSidecarImages
si := []SidecarImages{}
Expand All @@ -58,28 +59,43 @@ func InitializeSidecars(ver string) error {
return err
}

sv := version.MustParseGeneric(ver)

for _, image := range si {
v := version.MustParseGeneric(image.Version)
if sv.Major() == v.Major() && sv.Minor() == v.Minor() {
sidecarImages = &image
break
pltVersion := version.MustParseGeneric(ver)

closestMinor := int64(-1)
for idx := range si {
siVersion := version.MustParseGeneric(si[idx].Version)
log.Info("searching for the most compatible CSI image version", "CSI", siVersion, "Platform", pltVersion)

// only check sidecar image versions that are not higher than platform
if siVersion.Major() == pltVersion.Major() && siVersion.Minor() <= pltVersion.Minor() {
// filter sidecar closest to platform version
if int64(siVersion.Minor()) > closestMinor {
sidecarImages = &si[idx]
closestMinor = int64(siVersion.Minor())
}
if closestMinor == int64(pltVersion.Minor()) { // exact match and early exit
break
}
} else {
log.Info("skipping sidecar images: version greater than platform version")
}
}
if sidecarImages.Version == "" {
return fmt.Errorf("failed to find container details for %v version in %v", sv.String(), sidecarImages)
if sidecarImages == nil {
// happens only if all sidecars image versions are greater than platform
return fmt.Errorf("failed to find container details suitable for %v platform version", pltVersion)
}

log.Info("selected sidecar images", "version", sidecarImages.Version)

return nil
}

// 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 5e67773

Please sign in to comment.