From 1098627b49fbccc194a0bfe4dc3196efa40c793c Mon Sep 17 00:00:00 2001 From: Jiffin Tony Thottan Date: Fri, 15 Mar 2024 17:29:02 +0530 Subject: [PATCH] rgw: add vhost style support for rgw in ocs-op Signed-off-by: Jiffin Tony Thottan --- api/v1/storagecluster_types.go | 3 ++- api/v1/zz_generated.deepcopy.go | 5 ++++ .../ocs.openshift.io_storageclusters.yaml | 4 ++++ .../storagecluster/cephobjectstores.go | 23 +++++++++++++++++++ .../ocs/ocs.openshift.io_storageclusters.yaml | 4 ++++ .../manifests/storagecluster.crd.yaml | 4 ++++ .../api/v4/v1/storagecluster_types.go | 3 ++- .../api/v4/v1/zz_generated.deepcopy.go | 5 ++++ 8 files changed, 49 insertions(+), 2 deletions(-) diff --git a/api/v1/storagecluster_types.go b/api/v1/storagecluster_types.go index d96fc775d6..7bf1c6f2cd 100644 --- a/api/v1/storagecluster_types.go +++ b/api/v1/storagecluster_types.go @@ -249,7 +249,8 @@ type ManageCephObjectStores struct { // StorageClassName specifies the name of the storage class created for ceph obc's // +kubebuilder:validation:MaxLength=253 // +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - StorageClassName string `json:"storageClassName,omitempty"` + StorageClassName string `json:"storageClassName,omitempty"` + VirtualHostnames []string `json:"virtualHostnames,omitempty"` } // ManageCephObjectStoreUsers defines how to reconcile CephObjectStoreUsers diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 621ae5c27c..a29543c461 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -372,6 +372,11 @@ func (in *ManageCephObjectStores) DeepCopyInto(out *ManageCephObjectStores) { *out = new(bool) **out = **in } + if in.VirtualHostnames != nil { + in, out := &in.VirtualHostnames, &out.VirtualHostnames + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManageCephObjectStores. diff --git a/config/crd/bases/ocs.openshift.io_storageclusters.yaml b/config/crd/bases/ocs.openshift.io_storageclusters.yaml index 998f47c8c5..40976bfb25 100644 --- a/config/crd/bases/ocs.openshift.io_storageclusters.yaml +++ b/config/crd/bases/ocs.openshift.io_storageclusters.yaml @@ -1318,6 +1318,10 @@ spec: maxLength: 253 pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string + virtualHostnames: + items: + type: string + type: array type: object cephRBDMirror: description: ManageCephRBDMirror defines how to reconcile Ceph diff --git a/controllers/storagecluster/cephobjectstores.go b/controllers/storagecluster/cephobjectstores.go index f579b9732f..7c1cb252ee 100644 --- a/controllers/storagecluster/cephobjectstores.go +++ b/controllers/storagecluster/cephobjectstores.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + routev1 "github.com/openshift/api/route/v1" ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1" "github.com/red-hat-storage/ocs-operator/v4/controllers/defaults" "github.com/red-hat-storage/ocs-operator/v4/controllers/platform" @@ -201,6 +202,28 @@ func (r *StorageClusterReconciler) newCephObjectStoreInstances(initData *ocsv1.S return nil, err } + if len(initData.Spec.ManagedResources.CephObjectStores.VirtualHostnames) > 0 { + obj.Spec.Hosting.DNSNames = initData.Spec.ManagedResources.CephObjectStores.VirtualHostnames + route := &routev1.Route{} + err := r.Client.Get(context.TODO(), types.NamespacedName{Name: obj.Name, Namespace: obj.Namespace}, route) + if err != nil { + if errors.IsNotFound(err) { + r.Log.Info("Ceph RGW Route not found.", "CephRGWRoute", klog.KRef(obj.Namespace, obj.Name)) + } + } else { + obj.Spec.Hosting.DNSNames = append(obj.Spec.Hosting.DNSNames, route.Spec.Host) + } + secureRoute := &routev1.Route{} + err = r.Client.Get(context.TODO(), types.NamespacedName{Name: obj.Name + "-secure", Namespace: obj.Namespace}, secureRoute) + if err != nil { + if errors.IsNotFound(err) { + r.Log.Info("Ceph RGW Route not found.", "CephRGWRoute", klog.KRef(obj.Namespace, obj.Name+"-secure")) + } + } else { + obj.Spec.Hosting.DNSNames = append(obj.Spec.Hosting.DNSNames, secureRoute.Spec.Host) + } + } + if initData.Spec.ManagedResources.CephObjectStores.HostNetwork != nil { obj.Spec.Gateway.HostNetwork = initData.Spec.ManagedResources.CephObjectStores.HostNetwork } diff --git a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml index 998f47c8c5..40976bfb25 100644 --- a/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml +++ b/deploy/csv-templates/crds/ocs/ocs.openshift.io_storageclusters.yaml @@ -1318,6 +1318,10 @@ spec: maxLength: 253 pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string + virtualHostnames: + items: + type: string + type: array type: object cephRBDMirror: description: ManageCephRBDMirror defines how to reconcile Ceph diff --git a/deploy/ocs-operator/manifests/storagecluster.crd.yaml b/deploy/ocs-operator/manifests/storagecluster.crd.yaml index acf33c7356..218b72dee3 100644 --- a/deploy/ocs-operator/manifests/storagecluster.crd.yaml +++ b/deploy/ocs-operator/manifests/storagecluster.crd.yaml @@ -1317,6 +1317,10 @@ spec: maxLength: 253 pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string + virtualHostnames: + items: + type: string + type: array type: object cephRBDMirror: description: ManageCephRBDMirror defines how to reconcile Ceph diff --git a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go index d96fc775d6..7bf1c6f2cd 100644 --- a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go +++ b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/storagecluster_types.go @@ -249,7 +249,8 @@ type ManageCephObjectStores struct { // StorageClassName specifies the name of the storage class created for ceph obc's // +kubebuilder:validation:MaxLength=253 // +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - StorageClassName string `json:"storageClassName,omitempty"` + StorageClassName string `json:"storageClassName,omitempty"` + VirtualHostnames []string `json:"virtualHostnames,omitempty"` } // ManageCephObjectStoreUsers defines how to reconcile CephObjectStoreUsers diff --git a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/zz_generated.deepcopy.go b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/zz_generated.deepcopy.go index 621ae5c27c..a29543c461 100644 --- a/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/zz_generated.deepcopy.go +++ b/vendor/github.com/red-hat-storage/ocs-operator/api/v4/v1/zz_generated.deepcopy.go @@ -372,6 +372,11 @@ func (in *ManageCephObjectStores) DeepCopyInto(out *ManageCephObjectStores) { *out = new(bool) **out = **in } + if in.VirtualHostnames != nil { + in, out := &in.VirtualHostnames, &out.VirtualHostnames + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ManageCephObjectStores.