From 6f6c26009c70d7f9f4a05ba77287fe0231772a10 Mon Sep 17 00:00:00 2001 From: zhucan Date: Thu, 30 Jun 2022 10:55:24 +0800 Subject: [PATCH 1/2] object: generated code Signed-off-by: zhucan --- deploy/charts/rook-ceph/templates/resources.yaml | 5 +++++ deploy/examples/crds.yaml | 5 +++++ pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/deploy/charts/rook-ceph/templates/resources.yaml b/deploy/charts/rook-ceph/templates/resources.yaml index c4361cc2e..4fc69d33e 100644 --- a/deploy/charts/rook-ceph/templates/resources.yaml +++ b/deploy/charts/rook-ceph/templates/resources.yaml @@ -8569,6 +8569,11 @@ spec: type: object type: object type: object + hostNetwork: + description: Whether host networking is enabled for the rgw daemon. If not set, the network settings from the cluster CR will be applied. + nullable: true + type: boolean + x-kubernetes-preserve-unknown-fields: true metadataPool: description: The metadata pool settings nullable: true diff --git a/deploy/examples/crds.yaml b/deploy/examples/crds.yaml index 89fb58595..2e34b99c5 100644 --- a/deploy/examples/crds.yaml +++ b/deploy/examples/crds.yaml @@ -8561,6 +8561,11 @@ spec: type: object type: object type: object + hostNetwork: + description: Whether host networking is enabled for the rgw daemon. If not set, the network settings from the cluster CR will be applied. + nullable: true + type: boolean + x-kubernetes-preserve-unknown-fields: true metadataPool: description: The metadata pool settings nullable: true 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 7c8622ee8..c3ecd6174 100644 --- a/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go +++ b/pkg/apis/ceph.rook.io/v1/zz_generated.deepcopy.go @@ -2988,6 +2988,11 @@ func (in *ObjectStoreSpec) DeepCopyInto(out *ObjectStoreSpec) { *out = new(SecuritySpec) (*in).DeepCopyInto(*out) } + if in.HostNetwork != nil { + in, out := &in.HostNetwork, &out.HostNetwork + *out = new(bool) + **out = **in + } return } From 5ee75d6652a4ac52ca3f716babbb6f262db1b45b Mon Sep 17 00:00:00 2001 From: zhucan Date: Thu, 30 Jun 2022 10:56:03 +0800 Subject: [PATCH 2/2] object: support separated network for objectstore Signed-off-by: zhucan --- .../Object-Storage/ceph-object-store-crd.md | 1 + pkg/apis/ceph.rook.io/v1/object.go | 7 +++ pkg/apis/ceph.rook.io/v1/types.go | 6 +++ pkg/operator/ceph/object/config.go | 2 +- pkg/operator/ceph/object/spec.go | 6 ++- pkg/operator/ceph/object/spec_test.go | 51 +++++++++++++++++++ 6 files changed, 70 insertions(+), 3 deletions(-) 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) + } + }) + } +}