object: support separated network for objectstore

Signed-off-by: zhucan <zhucan.k8s@gmail.com>
This commit is contained in:
zhucan committed 2022-06-30 10:56:03 +08:00
1 parent 6f6c26009c
commit 5ee75d6652
6 files changed
+70 -3

No files matched your search

@@ -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.
+7
View File
@@ -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 != ""
}
+6
View File
@@ -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
+1 -1
View File
@@ -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)))
+4 -2
View File
@@ -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 {
+51
View File
@@ -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)
}
})
}
}