diff --git a/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md b/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md index 1105dff53..5c7115683 100644 --- a/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md +++ b/Documentation/CRDs/Object-Storage/ceph-object-store-crd.md @@ -104,6 +104,7 @@ The gateway settings correspond to the RGW daemon settings. * `caBundleRef`: If specified, this is the name of the Kubernetes secret (type `opaque`) that contains additional custom ca-bundle to use. The secret must be in the same namespace as the Rook cluster. Rook will look in the secret provided at the `cabundle` key name. +* `hostNetwork`: Whether host networking is enabled for the rgw daemon. If not set, the network settings from the cluster CR will be applied. * `port`: The port on which the Object service will be reachable. If host networking is enabled, the RGW daemons will also listen on that port. If running on SDN, the RGW daemon listening port will be 8080 internally. * `securePort`: The secure port on which RGW pods will be listening. A TLS certificate must be specified either via `sslCerticateRef` or `service.annotations` * `instances`: The number of pods that will be started to load balance this object store. diff --git a/pkg/apis/ceph.rook.io/v1/object.go b/pkg/apis/ceph.rook.io/v1/object.go index 51201404d..3d815df80 100644 --- a/pkg/apis/ceph.rook.io/v1/object.go +++ b/pkg/apis/ceph.rook.io/v1/object.go @@ -49,6 +49,13 @@ func (s *ObjectStoreSpec) IsExternal() bool { return len(s.Gateway.ExternalRgwEndpoints) != 0 } +func (s *ObjectStoreSpec) IsHostNetwork(c *ClusterSpec) bool { + if s.HostNetwork != nil { + return *s.HostNetwork + } + return c.Network.IsHost() +} + func (s *ObjectRealmSpec) IsPullRealm() bool { return s.Pull.Endpoint != "" } diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index 81de692ad..d0c113e98 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -1321,6 +1321,12 @@ type ObjectStoreSpec struct { // +optional // +nullable Security *SecuritySpec `json:"security,omitempty"` + + // Whether host networking is enabled for the rgw daemon. If not set, the network settings from the cluster CR will be applied. + // +kubebuilder:pruning:PreserveUnknownFields + // +nullable + // +optional + HostNetwork *bool `json:"hostNetwork,omitempty"` } // BucketHealthCheckSpec represents the health check of an object store diff --git a/pkg/operator/ceph/object/config.go b/pkg/operator/ceph/object/config.go index f4884579b..c34c453d2 100644 --- a/pkg/operator/ceph/object/config.go +++ b/pkg/operator/ceph/object/config.go @@ -65,7 +65,7 @@ func (c *clusterConfig) portString() string { port := c.store.Spec.Gateway.Port if port != 0 { - if !c.clusterSpec.Network.IsHost() { + if !c.store.Spec.IsHostNetwork(c.clusterSpec) { port = rgwPortInternalPort } portString = fmt.Sprintf("port=%s", strconv.Itoa(int(port))) diff --git a/pkg/operator/ceph/object/spec.go b/pkg/operator/ceph/object/spec.go index 4d8002e0d..d2395de42 100644 --- a/pkg/operator/ceph/object/spec.go +++ b/pkg/operator/ceph/object/spec.go @@ -103,6 +103,8 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec if reflect.DeepEqual(rgwDaemonContainer, v1.Container{}) { return v1.PodTemplateSpec{}, errors.New("got empty container for RGW daemon") } + + hostNetwork := c.store.Spec.IsHostNetwork(c.clusterSpec) podSpec := v1.PodSpec{ InitContainers: []v1.Container{ c.makeChownInitContainer(rgwConfig), @@ -113,7 +115,7 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec controller.DaemonVolumes(c.DataPathMap, rgwConfig.ResourceName), c.mimeTypesVolume(), ), - HostNetwork: c.clusterSpec.Network.IsHost(), + HostNetwork: hostNetwork, PriorityClassName: c.store.Spec.Gateway.PriorityClassName, ServiceAccountName: serviceAccountName, } @@ -198,7 +200,7 @@ func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec c.store.Spec.Gateway.Annotations.ApplyToObjectMeta(&podTemplateSpec.ObjectMeta) c.store.Spec.Gateway.Labels.ApplyToObjectMeta(&podTemplateSpec.ObjectMeta) - if c.clusterSpec.Network.IsHost() { + if hostNetwork { podTemplateSpec.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet } else if c.clusterSpec.Network.IsMultus() { if err := k8sutil.ApplyMultus(c.clusterSpec.Network, &podTemplateSpec.ObjectMeta); err != nil { diff --git a/pkg/operator/ceph/object/spec_test.go b/pkg/operator/ceph/object/spec_test.go index 9afa5b475..31fa47d8f 100644 --- a/pkg/operator/ceph/object/spec_test.go +++ b/pkg/operator/ceph/object/spec_test.go @@ -597,3 +597,54 @@ func TestGetDaemonName(t *testing.T) { }) } } + +func TestMakeRGWPodSpec(t *testing.T) { + store := simpleStore() + info := clienttest.CreateTestClusterInfo(1) + data := cephconfig.NewStatelessDaemonDataPathMap(cephconfig.RgwType, "default", "rook-ceph", "/var/lib/rook/") + c := &clusterConfig{ + store: store, + rookVersion: "rook/rook:myversion", + clusterSpec: &cephv1.ClusterSpec{ + CephVersion: cephv1.CephVersionSpec{Image: "quay.io/ceph/ceph:v15"}, + Network: cephv1.NetworkSpec{ + HostNetwork: true, + }, + }, + clusterInfo: info, + DataPathMap: data, + } + + resourceName := fmt.Sprintf("%s-%s", AppName, c.store.Name) + rgwConfig := &rgwConfig{ + ResourceName: resourceName, + DaemonID: "default", + } + tests := []struct { + name string + isSet bool + enabled bool + }{ + {"host networking is not set to rgw daemon", false, false}, + {"host networking is set to rgw daemon but not enabled", true, false}, + {"host networking is enabled for the rgw daemon", true, true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if tt.isSet { + if tt.enabled { + c.store.Spec.HostNetwork = func(hostNetwork bool) *bool { return &hostNetwork }(true) + } else { + c.store.Spec.HostNetwork = new(bool) + } + } + podTemplateSpec, _ := c.makeRGWPodSpec(rgwConfig) + + if tt.isSet { + assert.Equal(t, *c.store.Spec.HostNetwork, podTemplateSpec.Spec.HostNetwork) + } else { + assert.Equal(t, c.clusterSpec.Network.IsHost(), podTemplateSpec.Spec.HostNetwork) + } + }) + } +}