Merge pull request #10491 from zhucan/feat-10451

object: network mode can be set separately for cephcluster and rgw
This commit is contained in:
Travis Nielsen authored and GitHub committed 2022-07-14 11:21:26 -06:00
commit 37a4d9e959
9 files changed
+85 -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.
@@ -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
+5
View File
@@ -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
+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
@@ -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
}
+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
@@ -99,6 +99,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),
@@ -109,7 +111,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,
}
@@ -194,7 +196,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)
}
})
}
}