From b0989ee1d281508232d7bde987903dde4c14126c Mon Sep 17 00:00:00 2001
From: Jiffin Tony Thottan
Date: Mon, 4 Dec 2023 19:17:43 +0530
Subject: [PATCH] object: add rgw dns names
The virtual hosting for bucket is provided with help of `rgw_dns_name`
Signed-off-by: Jiffin Tony Thottan
---
.../Object-Storage/ceph-object-store-crd.md | 10 ++
Documentation/CRDs/specification.md | 63 +++++++
.../Object-Storage-RGW/object-storage.md | 3 +
PendingReleaseNotes.md | 1 +
.../charts/rook-ceph/templates/resources.yaml | 9 +
deploy/examples/crds.yaml | 9 +
deploy/examples/object.yaml | 5 +
pkg/apis/ceph.rook.io/v1/types.go | 16 ++
.../ceph.rook.io/v1/zz_generated.deepcopy.go | 26 +++
pkg/operator/ceph/object/rgw.go | 19 ++-
pkg/operator/ceph/object/spec.go | 96 +++++++++++
pkg/operator/ceph/object/spec_test.go | 158 ++++++++++++++++++
12 files changed, 409 insertions(+), 6 deletions(-)
diff --git a/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md b/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md
index 83c6fffc2..1575ad302 100644
--- a/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md
+++ b/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md
@@ -64,6 +64,10 @@ spec:
# memory: "1024Mi"
#zone:
#name: zone-a
+ #hosting:
+ # dnsName:
+ # - "mystore.example.com"
+ # - "mystore.example.org"
```
## Object Store Settings
@@ -149,6 +153,12 @@ The [zone](../../Storage-Configuration/Object-Storage-RGW/ceph-object-multisite.
* `name`: the name of the ceph-object-zone the object store will be in.
+## Hosting Settings
+
+The hosting settings allow you to host buckets in the object store on a custom DNS name, enabling virtual-hosted-style access to buckets similar to AWS S3 (https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html).
+
+* `dnsNames`: a list of DNS names to host buckets on. These names need to valid according RFC-1123. Otherwise it will fail. Each endpoint requires wildcard support like [ingress loadbalancer](https://kubernetes.io/docs/concepts/services-networking/ingress/#hostname-wildcards). Do not include the wildcard itself in the list of hostnames (e.g., use "mystore.example.com" instead of "*.mystore.example.com"). Add all the hostnames like openshift routes otherwise access will be denied, but if the hostname does not support wild card then virtual host style won't work those hostname. By default cephobjectstore service endpoint and custom endpoints from cephobjectzone is included. The feature is supported only for Ceph v18 and later versions.
+
## Runtime settings
### MIME types
diff --git a/Documentation/CRDs/specification.md b/Documentation/CRDs/specification.md
index c88f883d1..f3795b822 100644
--- a/Documentation/CRDs/specification.md
+++ b/Documentation/CRDs/specification.md
@@ -1955,6 +1955,20 @@ to be created in their own namespace, where neither OBCs nor COSI
is being used to create buckets. The default is empty.
+
+
+hosting
+
+
+ObjectStoreHostingSpec
+
+
+ |
+
+(Optional)
+ Hosting settings for the object store
+ |
+
@@ -8938,6 +8952,41 @@ PullSpec
+ObjectStoreHostingSpec
+
+
+(Appears on:ObjectStoreSpec)
+
+
+
ObjectStoreHostingSpec represents the hosting settings for the object store
+
+
+
+
+| Field |
+Description |
+
+
+
+
+
+dnsNames
+
+[]string
+
+ |
+
+(Optional)
+ A list of DNS names in which bucket can be accessed via virtual host path. These names need to valid according RFC-1123.
+Each domain requires wildcard support like ingress loadbalancer.
+Do not include the wildcard itself in the list of hostnames (e.g. use “mystore.example.com” instead of “*.mystore.example.com”).
+Add all hostnames including user-created Kubernetes Service endpoints to the list.
+CephObjectStore Service Endpoints and CephObjectZone customEndpoints are automatically added to the list.
+The feature is supported only for Ceph v18 and later versions.
+ |
+
+
+
ObjectStoreSecuritySpec
@@ -9112,6 +9161,20 @@ to be created in their own namespace, where neither OBCs nor COSI
is being used to create buckets. The default is empty.
+
+
+hosting
+
+
+ObjectStoreHostingSpec
+
+
+ |
+
+(Optional)
+ Hosting settings for the object store
+ |
+
ObjectStoreStatus
diff --git a/Documentation/Storage-Configuration/Object-Storage-RGW/object-storage.md b/Documentation/Storage-Configuration/Object-Storage-RGW/object-storage.md
index 01b2bd6df..41b120fcb 100644
--- a/Documentation/Storage-Configuration/Object-Storage-RGW/object-storage.md
+++ b/Documentation/Storage-Configuration/Object-Storage-RGW/object-storage.md
@@ -180,6 +180,9 @@ export AWS_ACCESS_KEY_ID=$(kubectl -n default get secret ceph-bucket -o jsonpath
export AWS_SECRET_ACCESS_KEY=$(kubectl -n default get secret ceph-bucket -o jsonpath='{.data.AWS_SECRET_ACCESS_KEY}' | base64 --decode)
```
+If any `hosting.dnsNames` are set in the `CephObjectStore` CRD, S3 clients can access buckets in [virtual-host-style](https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html).
+Otherwise, S3 clients must be configured to use path-style access.
+
## Consume the Object Storage
Now that you have the object store configured and a bucket created, you can consume the
diff --git a/PendingReleaseNotes.md b/PendingReleaseNotes.md
index 4ca3fbd82..8379ded52 100644
--- a/PendingReleaseNotes.md
+++ b/PendingReleaseNotes.md
@@ -13,3 +13,4 @@ read affinity setting in cephCluster CR (CSIDriverOptions section) in [PR](https
- Kubernetes versions **v1.25** through **v1.29** are supported.
- Ceph daemon pods using the `default` service account now use a new `rook-ceph-default` service account.
- The feature support for VolumeSnapshotGroup has been added to the RBD and CephFS CSI driver.
+- Support for virtual style hosting for s3 buckets in the CephObjectStore.
diff --git a/deploy/charts/rook-ceph/templates/resources.yaml b/deploy/charts/rook-ceph/templates/resources.yaml
index 572c5e57a..77336f3d1 100644
--- a/deploy/charts/rook-ceph/templates/resources.yaml
+++ b/deploy/charts/rook-ceph/templates/resources.yaml
@@ -9880,6 +9880,15 @@ spec:
type: object
type: object
type: object
+ hosting:
+ description: Hosting settings for the object store
+ properties:
+ dnsNames:
+ description: A list of DNS names in which bucket can be accessed via virtual host path. These names need to valid according RFC-1123. Each domain requires wildcard support like ingress loadbalancer. Do not include the wildcard itself in the list of hostnames (e.g. use "mystore.example.com" instead of "*.mystore.example.com"). Add all hostnames including user-created Kubernetes Service endpoints to the list. CephObjectStore Service Endpoints and CephObjectZone customEndpoints are automatically added to the list. The feature is supported only for Ceph v18 and later versions.
+ items:
+ type: string
+ type: array
+ type: object
metadataPool:
description: The metadata pool settings
nullable: true
diff --git a/deploy/examples/crds.yaml b/deploy/examples/crds.yaml
index e08ce43bb..6889c429e 100644
--- a/deploy/examples/crds.yaml
+++ b/deploy/examples/crds.yaml
@@ -9871,6 +9871,15 @@ spec:
type: object
type: object
type: object
+ hosting:
+ description: Hosting settings for the object store
+ properties:
+ dnsNames:
+ description: A list of DNS names in which bucket can be accessed via virtual host path. These names need to valid according RFC-1123. Each domain requires wildcard support like ingress loadbalancer. Do not include the wildcard itself in the list of hostnames (e.g. use "mystore.example.com" instead of "*.mystore.example.com"). Add all hostnames including user-created Kubernetes Service endpoints to the list. CephObjectStore Service Endpoints and CephObjectZone customEndpoints are automatically added to the list. The feature is supported only for Ceph v18 and later versions.
+ items:
+ type: string
+ type: array
+ type: object
metadataPool:
description: The metadata pool settings
nullable: true
diff --git a/deploy/examples/object.yaml b/deploy/examples/object.yaml
index 3755fb069..ba22f3a94 100644
--- a/deploy/examples/object.yaml
+++ b/deploy/examples/object.yaml
@@ -108,6 +108,11 @@ spec:
disabled: false
readinessProbe:
disabled: false
+ # hosting:
+ # The list of subdomain names for virtual hosting of buckets.
+ # dnsNames:
+ # - "mystore.example.com"
+
# If a CephObjectStoreUser is created in a namespace other than the Rook cluster namespace,
# the namespace must be added to the list of allowed namespaces, or specify "*" to allow all namespaces.
# allowUsersInNamespaces:
diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go
index 3b7d93c97..d0c661d5a 100755
--- a/pkg/apis/ceph.rook.io/v1/types.go
+++ b/pkg/apis/ceph.rook.io/v1/types.go
@@ -1463,6 +1463,10 @@ type ObjectStoreSpec struct {
// is being used to create buckets. The default is empty.
// +optional
AllowUsersInNamespaces []string `json:"allowUsersInNamespaces,omitempty"`
+
+ // Hosting settings for the object store
+ // +optional
+ Hosting *ObjectStoreHostingSpec `json:"hosting,omitempty"`
}
// ObjectHealthCheckSpec represents the health check of an object store
@@ -1621,6 +1625,18 @@ type ObjectEndpoints struct {
Secure []string `json:"secure"`
}
+// ObjectStoreHostingSpec represents the hosting settings for the object store
+type ObjectStoreHostingSpec struct {
+ // A list of DNS names in which bucket can be accessed via virtual host path. These names need to valid according RFC-1123.
+ // Each domain requires wildcard support like ingress loadbalancer.
+ // Do not include the wildcard itself in the list of hostnames (e.g. use "mystore.example.com" instead of "*.mystore.example.com").
+ // Add all hostnames including user-created Kubernetes Service endpoints to the list.
+ // CephObjectStore Service Endpoints and CephObjectZone customEndpoints are automatically added to the list.
+ // The feature is supported only for Ceph v18 and later versions.
+ // +optional
+ DNSNames []string `json:"dnsNames,omitempty"`
+}
+
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
diff --git a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go
index d70a304f2..fee2022a0 100644
--- a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go
@@ -3474,6 +3474,27 @@ func (in *ObjectRealmSpec) DeepCopy() *ObjectRealmSpec {
return out
}
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *ObjectStoreHostingSpec) DeepCopyInto(out *ObjectStoreHostingSpec) {
+ *out = *in
+ if in.DNSNames != nil {
+ in, out := &in.DNSNames, &out.DNSNames
+ *out = make([]string, len(*in))
+ copy(*out, *in)
+ }
+ return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectStoreHostingSpec.
+func (in *ObjectStoreHostingSpec) DeepCopy() *ObjectStoreHostingSpec {
+ if in == nil {
+ return nil
+ }
+ out := new(ObjectStoreHostingSpec)
+ in.DeepCopyInto(out)
+ return out
+}
+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ObjectStoreSecuritySpec) DeepCopyInto(out *ObjectStoreSecuritySpec) {
*out = *in
@@ -3510,6 +3531,11 @@ func (in *ObjectStoreSpec) DeepCopyInto(out *ObjectStoreSpec) {
*out = make([]string, len(*in))
copy(*out, *in)
}
+ if in.Hosting != nil {
+ in, out := &in.Hosting, &out.Hosting
+ *out = new(ObjectStoreHostingSpec)
+ (*in).DeepCopyInto(*out)
+ }
return
}
diff --git a/pkg/operator/ceph/object/rgw.go b/pkg/operator/ceph/object/rgw.go
index 5e2f3d637..f41ecff1f 100644
--- a/pkg/operator/ceph/object/rgw.go
+++ b/pkg/operator/ceph/object/rgw.go
@@ -341,18 +341,25 @@ func GetStableDomainName(s *cephv1.CephObjectStore) string {
}
func getDomainName(s *cephv1.CephObjectStore, returnRandomDomainIfMultiple bool) string {
+ endpoints := []string{}
if s.Spec.IsExternal() {
// if the store is external, pick a random endpoint to use. if the endpoint is down, this
// reconcile may fail, but a future reconcile will eventually pick a different endpoint to try
- endpoints := s.Spec.Gateway.ExternalRgwEndpoints
- idx := 0
- if returnRandomDomainIfMultiple {
- idx = rand.Intn(len(endpoints)) //nolint:gosec // G404: cryptographically weak RNG is fine here
+ for _, e := range s.Spec.Gateway.ExternalRgwEndpoints {
+ endpoints = append(endpoints, e.String())
}
- return endpoints[idx].String()
+ } else if s.Spec.Hosting != nil && len(s.Spec.Hosting.DNSNames) > 0 {
+ // if the store is internal and has DNS names, pick a random DNS name to use
+ endpoints = s.Spec.Hosting.DNSNames
+ } else {
+ return domainNameOfService(s)
}
- return domainNameOfService(s)
+ idx := 0
+ if returnRandomDomainIfMultiple {
+ idx = rand.Intn(len(endpoints)) //nolint:gosec // G404: cryptographically weak RNG is fine here
+ }
+ return endpoints[idx]
}
func domainNameOfService(s *cephv1.CephObjectStore) string {
diff --git a/pkg/operator/ceph/object/spec.go b/pkg/operator/ceph/object/spec.go
index 95e3f81ea..60cab390f 100644
--- a/pkg/operator/ceph/object/spec.go
+++ b/pkg/operator/ceph/object/spec.go
@@ -20,6 +20,7 @@ import (
"bytes"
_ "embed"
"fmt"
+ "net/url"
"path"
"strings"
"text/template"
@@ -37,6 +38,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
+ "k8s.io/apimachinery/pkg/util/validation"
)
const (
@@ -418,6 +420,14 @@ func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) (v1.Container,
vaultVolMount := v1.VolumeMount{Name: rgwVaultVolumeName, MountPath: rgwVaultDirName}
container.VolumeMounts = append(container.VolumeMounts, vaultVolMount)
}
+
+ hostingOptions, err := c.addDNSNamesToRGWServer()
+ if err != nil {
+ return v1.Container{}, err
+ }
+ if hostingOptions != "" {
+ container.Args = append(container.Args, hostingOptions)
+ }
return container, nil
}
@@ -912,3 +922,89 @@ func renderProbe(cfg rgwProbeConfig) (string, error) {
return writer.String(), nil
}
+
+func (c *clusterConfig) addDNSNamesToRGWServer() (string, error) {
+ if (c.store.Spec.Hosting == nil) || len(c.store.Spec.Hosting.DNSNames) <= 0 {
+ return "", nil
+ }
+ if !c.clusterInfo.CephVersion.IsAtLeastReef() {
+ return "", errors.New("rgw dns names are supported from ceph v18 onwards")
+ }
+
+ // add default RGW service name to dns names
+ dnsNames := c.store.Spec.Hosting.DNSNames
+ dnsNames = append(dnsNames, domainNameOfService(c.store))
+
+ // add custom endpoints from zone spec if exists
+ if c.store.Spec.Zone.Name != "" {
+ zone, err := c.context.RookClientset.CephV1().CephObjectZones(c.store.Namespace).Get(c.clusterInfo.Context, c.store.Spec.Zone.Name, metav1.GetOptions{})
+ if err != nil {
+ return "", err
+ }
+ dnsNames = append(dnsNames, zone.Spec.CustomEndpoints...)
+ }
+
+ // validate dns names
+ var hostNames []string
+ for _, dnsName := range dnsNames {
+ hostName, err := GetHostnameFromEndpoint(dnsName)
+ if err != nil {
+ return "", errors.Wrap(err,
+ "failed to interpret endpoint from one of the following sources: CephObjectStore.spec.hosting.dnsNames, CephObjectZone.spec.customEndpoints")
+ }
+ hostNames = append(hostNames, hostName)
+ }
+
+ // remove duplicate host names
+ checkDuplicate := make(map[string]bool)
+ removeDuplicateHostNames := []string{}
+ for _, hostName := range hostNames {
+ if _, ok := checkDuplicate[hostName]; !ok {
+ checkDuplicate[hostName] = true
+ removeDuplicateHostNames = append(removeDuplicateHostNames, hostName)
+ }
+ }
+
+ return cephconfig.NewFlag("rgw dns name", strings.Join(removeDuplicateHostNames, ",")), nil
+}
+
+func GetHostnameFromEndpoint(endpoint string) (string, error) {
+ if len(endpoint) == 0 {
+ return "", fmt.Errorf("endpoint cannot be empty string")
+ }
+
+ // if endpoint doesn't end in '/', Ceph adds it
+ // Rook can do this also to get more accurate error results from this function
+ if !strings.HasSuffix(endpoint, "/") {
+ endpoint = endpoint + "/"
+ }
+
+ // url.Parse() requires a protocol to parse the host name correctly
+ if !strings.Contains(endpoint, "://") {
+ endpoint = "http://" + endpoint
+ }
+
+ // "net/url".Parse() assumes that a URL is a "path" with optional things surrounding it.
+ // For Ceph RGWs, we assume an endpoint is a "hostname" with optional things surrounding it.
+ // Because of this difference in fundamental assumption, Rook needs to adjust some endpoints
+ // used as input to url.Parse() to allow the function to extract a hostname reliably. Also,
+ // Rook needs to look at several parts of the url.Parse() output to identify more failure scenarios
+ parsedURL, err := url.Parse(endpoint)
+ if err != nil {
+ return "", err
+ }
+
+ // error in this case: url.Parse("https://http://hostname") parses without error with `Host = "http:"`
+ // also catches issue where user adds colon but no port number after
+ if strings.HasSuffix(parsedURL.Host, ":") {
+ return "", fmt.Errorf("host %q parsed from endpoint %q has invalid colon (:) placement", parsedURL.Host, endpoint)
+ }
+
+ hostname := parsedURL.Hostname()
+ dnsErrs := validation.IsDNS1123Subdomain(parsedURL.Hostname())
+ if len(dnsErrs) > 0 {
+ return "", fmt.Errorf("hostname %q parsed from endpoint %q is not a valid DNS-1123 subdomain: %v", hostname, endpoint, strings.Join(dnsErrs, ", "))
+ }
+
+ return hostname, nil
+}
diff --git a/pkg/operator/ceph/object/spec_test.go b/pkg/operator/ceph/object/spec_test.go
index d9583624c..5665fc090 100644
--- a/pkg/operator/ceph/object/spec_test.go
+++ b/pkg/operator/ceph/object/spec_test.go
@@ -23,6 +23,7 @@ import (
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
+ rookclient "github.com/rook/rook/pkg/client/clientset/versioned/fake"
"github.com/rook/rook/pkg/clusterd"
"github.com/rook/rook/pkg/daemon/ceph/client"
clienttest "github.com/rook/rook/pkg/daemon/ceph/client/test"
@@ -876,3 +877,160 @@ func TestAWSServerSideEncryption(t *testing.T) {
assert.True(t, checkRGWOptions(rgwContainer.Args, c.sseS3VaultTLSOptions(true)))
})
}
+
+func TestAddDNSNamesToRGWPodSpec(t *testing.T) {
+ setupTest := func(zoneName string, cephvers cephver.CephVersion, dnsNames, customEndpoints []string) *clusterConfig {
+ store := simpleStore()
+ info := clienttest.CreateTestClusterInfo(1)
+ data := cephconfig.NewStatelessDaemonDataPathMap(cephconfig.RgwType, "default", "rook-ceph", "/var/lib/rook/")
+ ctx := &clusterd.Context{RookClientset: rookclient.NewSimpleClientset()}
+ info.CephVersion = cephvers
+ store.Spec.Hosting = &cephv1.ObjectStoreHostingSpec{
+ DNSNames: dnsNames,
+ }
+ if zoneName != "" {
+ store.Spec.Zone.Name = zoneName
+ zone := &cephv1.CephObjectZone{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: zoneName,
+ Namespace: store.Namespace,
+ },
+ Spec: cephv1.ObjectZoneSpec{},
+ }
+ if len(customEndpoints) > 0 {
+ zone.Spec.CustomEndpoints = customEndpoints
+ }
+ _, err := ctx.RookClientset.CephV1().CephObjectZones(store.Namespace).Create(context.TODO(), zone, metav1.CreateOptions{})
+ assert.NoError(t, err)
+ }
+ return &clusterConfig{
+ clusterInfo: info,
+ store: store,
+ context: ctx,
+ rookVersion: "rook/rook:myversion",
+ clusterSpec: &cephv1.ClusterSpec{
+ CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:v18"},
+ },
+ DataPathMap: data,
+ }
+ }
+ tests := []struct {
+ name string
+ dnsNames []string
+ expectedDNSArg string
+ cephvers cephver.CephVersion
+ zoneName string
+ CustomEndpoints []string
+ wantErr bool
+ }{
+ {"no dns names ceph v18", []string{}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"no dns names with zone ceph v18", []string{}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "myzone", []string{}, false},
+ {"no dns names with zone and custom endpoints ceph v18", []string{}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint1:80", "http://my.custom.endpoint2:80"}, false},
+ {"one dns name ceph v18", []string{"my.dns.name"}, "--rgw-dns-name=my.dns.name,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"multiple dns names ceph v18", []string{"my.dns.name1", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"duplicate dns names ceph v18", []string{"my.dns.name1", "my.dns.name2", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"invalid dns name ceph v18", []string{"!my.invalid-dns.com"}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"mixed invalid and valid dns names ceph v18", []string{"my.dns.name", "!my.invalid-dns.name"}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"dns name with zone without custom endpoints ceph v18", []string{"my.dns.name1", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "myzone", []string{}, false},
+ {"dns name with zone with custom endpoints ceph v18", []string{"my.dns.name1", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc,my.custom.endpoint1,my.custom.endpoint2", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint1:80", "http://my.custom.endpoint2:80"}, false},
+ {"dns name with zone with custom invalid endpoints ceph v18", []string{"my.dns.name1", "my.dns.name2"}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint:80", "http://!my.invalid-custom.endpoint:80"}, true},
+ {"dns name with zone with mixed invalid and valid dnsnames/custom endpoint ceph v18", []string{"my.dns.name", "!my.dns.name"}, "", cephver.CephVersion{Major: 18, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint1:80", "http://my.custom.endpoint2:80:80"}, true},
+ {"no dns names ceph v17", []string{}, "", cephver.CephVersion{Major: 17, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"one dns name ceph v17", []string{"my.dns.name"}, "", cephver.CephVersion{Major: 17, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"multiple dns names ceph v17", []string{"my.dns.name1", "my.dns.name2"}, "", cephver.CephVersion{Major: 17, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"duplicate dns names ceph v17", []string{"my.dns.name1", "my.dns.name2", "my.dns.name2"}, "", cephver.CephVersion{Major: 17, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"invalid dns name ceph v17", []string{"!my.invalid-dns.name"}, "", cephver.CephVersion{Major: 17, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"mixed invalid and valid dns names ceph v17", []string{"my.dns.name", "!my.invalid-dns.name"}, "", cephver.CephVersion{Major: 17, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"no dns names ceph v19", []string{}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"no dns names with zone ceph v19", []string{}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "myzone", []string{}, false},
+ {"no dns names with zone and custom endpoints ceph v19", []string{}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint1:80", "http://my.custom.endpoint2:80"}, false},
+ {"one dns name ceph v19", []string{"my.dns.name"}, "--rgw-dns-name=my.dns.name,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"multiple dns names ceph v19", []string{"my.dns.name1", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"duplicate dns names ceph v19", []string{"my.dns.name1", "my.dns.name2", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "", []string{}, false},
+ {"invalid dns name ceph v19", []string{"!my.invalid-dns.name"}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"mixed invalid and valid dns names ceph v19", []string{"my.dns.name", "!my.invalid-dns.name"}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "", []string{}, true},
+ {"dns name with zone without custom endpoints ceph v19", []string{"my.dns.name1", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "myzone", []string{}, false},
+ {"dns name with zone with custom endpoints ceph v19", []string{"my.dns.name1", "my.dns.name2"}, "--rgw-dns-name=my.dns.name1,my.dns.name2,rook-ceph-rgw-default.mycluster.svc,my.custom.endpoint1,my.custom.endpoint2", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint1:80", "http://my.custom.endpoint2:80"}, false},
+ {"dns name with zone with custom invalid endpoints ceph v19", []string{"my.dns.name1", "my.dns.name2"}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint:80", "http://!my.custom.invalid-endpoint:80"}, true},
+ {"dns with zone with mixed invalid and valid dnsnames/custom endpoint ceph v19", []string{"my.dns.name", "!my.invalid-dns.name"}, "", cephver.CephVersion{Major: 19, Minor: 0, Extra: 0}, "myzone", []string{"http://my.custom.endpoint1:80", "http://!my.custom.invalid-endpoint:80"}, true},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ c := setupTest(tt.zoneName, tt.cephvers, tt.dnsNames, tt.CustomEndpoints)
+ res, err := c.addDNSNamesToRGWServer()
+ if tt.wantErr {
+ assert.Error(t, err)
+ } else {
+ assert.NoError(t, err)
+ }
+ assert.Equal(t, tt.expectedDNSArg, res)
+
+ })
+ }
+}
+
+func TestGetHostnameFromEndpoint(t *testing.T) {
+ tests := []struct {
+ name string
+ endpoint string
+ expected string
+ wantErr bool
+ }{
+ {"empty endpoint", "", "", true},
+ {"http endpoint", "http://my.custom.endpoint1:80", "my.custom.endpoint1", false},
+ {"https endpoint", "https://my.custom.endpoint1:80", "my.custom.endpoint1", false},
+ {"http endpoint without port", "http://my.custom.endpoint1", "my.custom.endpoint1", false},
+ {"https endpoint without port", "https://my.custom.endpoint1", "my.custom.endpoint1", false},
+ {"multiple portocol endpoint case 1", "http://https://my.custom.endpoint1:80", "", true},
+ {"multiple portocol endpoint case 2", "https://http://my.custom.endpoint1:80", "", true},
+ {"ftp endpoint", "ftp://my.custom.endpoint1:80", "my.custom.endpoint1", false},
+ {"custom protocol endpoint", "custom://my.custom.endpoint1:80", "my.custom.endpoint1", false},
+ {"custom protocol endpoint without port", "custom://my.custom.endpoint1", "my.custom.endpoint1", false},
+ {"invalid endpoint", "http://!my.custom.endpoint1:80", "", true},
+ {"invalid endpoint multiple ports", "http://my.custom.endpoint1:80:80", "", true},
+ {"invalid http endpoint with upper case", "http://MY.CUSTOM.ENDPOINT1:80", "", true},
+ {"invalid http endpoint with upper case without port", "http://MY.CUSTOM.ENDPOINT1", "", true},
+ {"invalid https endpoint with upper case", "https://MY.CUSTOM.ENDPOINT1:80", "", true},
+ {"invalid https endpoint with upper case without port", "https://MY.CUSTOM.ENDPOINT1", "", true},
+ {"invalid http endpoint with camel case", "http://myCustomEndpoint1:80", "", true},
+ {"invalid http endpoint with camel case without port", "http://myCustomEndpoint1", "", true},
+ {"invalid https endpoint with camel case", "https://myCustomEndpoint1:80", "", true},
+ {"invalid https endpoint with camel case without port", "https://myCustomEndpoint1", "", true},
+ {"endpoint without protocol", "my.custom.endpoint1:80", "my.custom.endpoint1", false},
+ {"endpoint without protocol without port", "my.custom.endpoint1", "my.custom.endpoint1", false},
+ {"invalid endpoint without protocol with upper case", "MY.CUSTOM.ENDPOINT1:80", "", true},
+ {"invalid endpoint without protocol with upper case without port", "MY.CUSTOM.ENDPOINT1", "", true},
+ {"invalid endpoint without protocol with camel case", "myCustomEndpoint1:80", "", true},
+ {"invalid endpoint without protocol with camel case without port", "myCustomEndpoint1", "", true},
+ {"invalid endpoint without protocol ending :", "my.custom.endpoint1:", "", true},
+ {"invalid endpoint without protocol and multiple ports", "my.custom.endpoint1:80:80", "", true},
+ {"http endpoint containing ip address", "http://1.1.1.1:80", "1.1.1.1", false},
+ {"http endpoint containing ip address without port", "http://1.1.1.1", "1.1.1.1", false},
+ {"https endpoint containing ip address", "https://1.1.1.1:80", "1.1.1.1", false},
+ {"https endpoint containing ip address without port", "https://1.1.1.1:80", "1.1.1.1", false},
+ {"invalid endpoint ending ://", "my.custom.endpoint1://", "", true},
+ {"invalid endpoint ending : without port", "http://my.custom.endpoint1:", "", true},
+ {"http endpoint with user and password", "http://user:password@mycustomendpoint1:80", "mycustomendpoint1", false},
+ {"http endpoint with user and password without port", "http://user:password@mycustomendpoint1", "mycustomendpoint1", false},
+ {"https endpoint with user and password", "https://user:password@mycustomendpoint1:80", "mycustomendpoint1", false},
+ {"https endpoint with user and password without port", "https://user:password@mycustomendpoint1", "mycustomendpoint1", false},
+ {"endpoint with user and password without protocol", "user:password@mycustomendpoint:80", "mycustomendpoint", false},
+ {"endpoint with user and password without protocol without port", "user:password@mycustomendpoint", "mycustomendpoint", false},
+ {"invalid endpoint with user and password ending ://", "user:password@mycustomendpoint1://", "", true},
+ {"invalid endpoint with user and password ending : without port", "user:password@mycustomendpoint1:", "", true},
+ {"invalid endpoint with user and password ending with multiple ports", "user:password@mycustomendpoint1:80:80", "", true},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ res, err := GetHostnameFromEndpoint(tt.endpoint)
+ if tt.wantErr {
+ assert.Error(t, err)
+ } else {
+ assert.NoError(t, err)
+ }
+ assert.Equal(t, tt.expected, res)
+
+ })
+ }
+}