Files
my-rook-config/pkg/operator/ceph/object/spec.go
T
Sébastien Han 20c302f72d ceph: use replicaset instead of deployments for rgw instances
Since Pacific, we can deploy multiple object gateway using the same
keying and they will appear in the service map separetly. So from now on
and on upgrades to Pacific Rook will remove all extra deployments to
only keep 1. In this single deployment the number of replica will be set
the desired `instances` count from the CRD spec.

You will now see gateways like this on Pacific:

```
rgw: 3 daemons active (1 hosts, 1 zones)
```

See an upgrade operator logs from Octopus to Pacific:

```
2021-04-14 10:05:16.883145 I | ceph-object-controller: setting multisite settings for object store "my-store"
2021-04-14 10:05:17.006492 I | ceph-object-controller: Multisite for object-store: realm=my-store, zonegroup=my-store, zone=my-store
2021-04-14 10:05:17.006516 I | ceph-object-controller: multisite configuration for object-store my-store is complete
2021-04-14 10:05:17.006523 I | ceph-object-controller: creating object store "my-store" in namespace "rook-ceph"
2021-04-14 10:05:17.006533 I | cephclient: getting or creating ceph auth key "client.rgw.my.store.a"
2021-04-14 10:05:17.298176 I | ceph-object-controller: object store "my-store" deployment "rook-ceph-rgw-my-store-a" started
2021-04-14 10:05:17.307913 I | ceph-object-controller: object store "my-store" deployment "rook-ceph-rgw-my-store-a" already exists. updating if needed
2021-04-14 10:05:17.317441 I | op-k8sutil: updating deployment "rook-ceph-rgw-my-store-a" after verifying it is safe to stop
2021-04-14 10:05:17.317463 I | op-mon: checking if we can stop the deployment rook-ceph-rgw-my-store-a
2021-04-14 10:05:25.552648 I | op-k8sutil: finished waiting for updated deployment "rook-ceph-mgr-a"
2021-04-14 10:05:25.552662 I | op-mon: checking if we can continue the deployment rook-ceph-mgr-a
2021-04-14 10:05:25.555077 I | op-mgr: setting services to point to mgr "a"
2021-04-14 10:05:25.608535 I | op-osd: start running osds in namespace "rook-ceph"
2021-04-14 10:05:25.608587 I | op-osd: wait timeout for healthy OSDs during upgrade or restart is "10m0s"
2021-04-14 10:05:25.618392 I | op-osd: start provisioning the OSDs on PVCs, if needed
2021-04-14 10:05:25.620512 I | op-osd: no storageClassDeviceSets or volumeSources are defined to configure OSDs on PVCs
2021-04-14 10:05:25.620542 I | op-osd: start provisioning the OSDs on nodes, if needed
2021-04-14 10:05:25.628416 I | op-osd: 1 of the 1 storage nodes are valid
2021-04-14 10:05:25.760702 I | op-k8sutil: Removing previous job rook-ceph-osd-prepare-minikube to start a new one
2021-04-14 10:05:25.773213 I | op-k8sutil: batch job rook-ceph-osd-prepare-minikube still exists
2021-04-14 10:05:26.595673 I | op-mgr: successful modules: prometheus
2021-04-14 10:05:27.129569 I | op-mgr: successful modules: mgr module(s) from the spec
2021-04-14 10:05:27.776720 I | op-k8sutil: batch job rook-ceph-osd-prepare-minikube deleted
2021-04-14 10:05:27.781881 I | op-osd: started OSD provisioning job for node "minikube"
2021-04-14 10:05:27.786693 I | op-osd: OSD orchestration status for node minikube is "starting"
2021-04-14 10:05:28.617937 I | op-mgr: successful modules: balancer
2021-04-14 10:05:28.706307 W | cephclient: all OSDs are running on the same host. not performing upgrade check. running in best-effort
2021-04-14 10:05:28.710245 I | op-osd: updating OSD 0 on node "minikube"
2021-04-14 10:05:31.596511 I | op-mgr: the dashboard secret was already generated
2021-04-14 10:05:31.926125 I | op-mgr: setting ceph dashboard "admin" login creds
2021-04-14 10:05:32.190343 E | op-mgr: failed modules: "dashboard". failed to initialize dashboard: failed to set login credentials for the ceph dashboard: failed to set login creds on mgr: failed to complete command for set dashboard creds: Invalid command: unused arguments: ["P.c(b6V$0pfK#)'70c5z"]
dashboard set-login-credentials <username> :  Set the login credentials. Password read from -i <file>
Traceback (most recent call last):
  File "/usr/bin/ceph", line 1310, in <module>
    retval = main()
  File "/usr/bin/ceph", line 1256, in main
    outf.write(outbuf)
TypeError: a bytes-like object is required, not 'str'
.
2021-04-14 10:05:35.665419 I | op-k8sutil: finished waiting for updated deployment "rook-ceph-rgw-my-store-a"
2021-04-14 10:05:35.665553 I | op-mon: checking if we can continue the deployment rook-ceph-rgw-my-store-a
2021-04-14 10:05:35.675293 I | ceph-object-controller: config map "rook-ceph-rgw-my-store-mime-types" for object store "my-store" already exists, not overwriting
2021-04-14 10:05:35.691549 I | ceph-object-controller: found more rgw deployments 3 than desired 3 in object store "my-store", scaling down
2021-04-14 10:05:35.691580 I | op-k8sutil: removing deployment rook-ceph-rgw-my-store-c if it exists
2021-04-14 10:05:35.698382 I | op-k8sutil: Removed deployment rook-ceph-rgw-my-store-c
2021-04-14 10:05:35.704568 I | op-k8sutil: "rook-ceph-rgw-my-store-c" still found. waiting...
2021-04-14 10:05:44.881129 I | op-osd: OSD orchestration status for node minikube is "orchestrating"
2021-04-14 10:05:44.882149 I | op-osd: OSD orchestration status for node minikube is "completed"
2021-04-14 10:05:45.756762 I | op-k8sutil: "rook-ceph-rgw-my-store-c" still found. waiting...
2021-04-14 10:05:45.782039 W | cephclient: all OSDs are running on the same host. not performing upgrade check. running in best-effort
2021-04-14 10:05:45.785188 I | op-osd: updating OSD 1 on node "minikube"
2021-04-14 10:05:54.768851 W | cephclient: all OSDs are running on the same host. not performing upgrade check. running in best-effort
2021-04-14 10:05:54.773191 I | op-osd: updating OSD 2 on node "minikube"
2021-04-14 10:05:55.843879 I | op-k8sutil: "rook-ceph-rgw-my-store-c" still found. waiting...
2021-04-14 10:06:05.255136 I | op-osd: finished running OSDs in namespace "rook-ceph"
2021-04-14 10:06:05.255155 I | ceph-cluster-controller: done reconciling ceph cluster in namespace "rook-ceph"
2021-04-14 10:06:05.560201 W | ceph-cluster-controller: upgrade orchestration completed but somehow we still have more than one Ceph version running. map[ceph version 15.2.9 (357616cbf726abb779ca75a551e8d02568e15b17) octopus (stable):3 ceph version 16.2.0 (0c2054e95bcd9b30fdd908a79ac1d8bbc3394442) pacific (stable):6]:
2021-04-14 10:06:05.885001 I | op-k8sutil: "rook-ceph-rgw-my-store-c" still found. waiting...
2021-04-14 10:06:08.321209 I | exec: timeout waiting for process radosgw-admin to return. Sending interrupt signal to the process
2021-04-14 10:06:10.645672 I | ceph-spec: object "rook-ceph-rgw-my-store-c" matched on delete, reconciling
2021-04-14 10:06:11.940994 I | op-k8sutil: confirmed rook-ceph-rgw-my-store-c does not exist
2021-04-14 10:06:11.972935 I | ceph-spec: object "rook-ceph-rgw-my-store-c-keyring" matched on delete, reconciling
2021-04-14 10:06:11.974394 I | ceph-object-controller: deleting rgw CephX key and configuration in centralized mon database for "rook-ceph-rgw-my-store-c"
2021-04-14 10:06:13.721964 I | ceph-object-controller: successfully deleted rgw config for "client.rgw.my.store.c" in mon configuration database
2021-04-14 10:06:13.721989 I | cephclient: deleting ceph auth "client.rgw.my.store.c"
2021-04-14 10:06:14.073700 I | ceph-object-controller: completed deleting rgw CephX key and configuration in centralized mon database for "rook-ceph-rgw-my-store-c"
2021-04-14 10:06:14.073724 I | op-k8sutil: removing deployment rook-ceph-rgw-my-store-b if it exists
2021-04-14 10:06:14.083950 I | op-k8sutil: Removed deployment rook-ceph-rgw-my-store-b
2021-04-14 10:06:14.090226 I | op-k8sutil: "rook-ceph-rgw-my-store-b" still found. waiting...
2021-04-14 10:06:24.174846 I | op-k8sutil: "rook-ceph-rgw-my-store-b" still found. waiting...
2021-04-14 10:06:30.505574 I | ceph-spec: object "rook-ceph-rgw-my-store-b" matched on delete, reconciling
2021-04-14 10:06:32.201263 I | op-k8sutil: confirmed rook-ceph-rgw-my-store-b does not exist
2021-04-14 10:06:32.219559 I | ceph-object-controller: deleting rgw CephX key and configuration in centralized mon database for "rook-ceph-rgw-my-store-b"
2021-04-14 10:06:32.220219 I | ceph-spec: object "rook-ceph-rgw-my-store-b-keyring" matched on delete, reconciling
2021-04-14 10:06:33.821969 I | ceph-object-controller: successfully deleted rgw config for "client.rgw.my.store.b" in mon configuration database
2021-04-14 10:06:33.821992 I | cephclient: deleting ceph auth "client.rgw.my.store.b"
2021-04-14 10:06:34.182091 I | ceph-object-controller: completed deleting rgw CephX key and configuration in centralized mon database for "rook-ceph-rgw-my-store-b"
2021-04-14 10:06:34.188659 I | ceph-object-controller: successfully scaled down rgw deployments to 1 in object store "my-store"
2021-04-14 10:06:34.188676 I | ceph-object-controller: enabling rgw dashboard
2021-04-14 10:06:49.487902 I | exec: timeout waiting for process radosgw-admin to return. Sending interrupt signal to the process
2021-04-14 10:06:49.494605 W | ceph-object-controller: failed to enable dashboard for rgw. failed to create user "dashboard-admin": failed to create s3 user: signal: interrupt
2021-04-14 10:06:49.494676 I | ceph-object-controller: created object store "my-store" in namespace "rook-ceph"
```

Running pods:

```
...
...
rook-ceph-rgw-my-store-a-6756bdbbd4-7265v            1/1     Running     1          41m
rook-ceph-rgw-my-store-a-6756bdbbd4-l5ccr            1/1     Running     1          41m
rook-ceph-rgw-my-store-a-6756bdbbd4-m679c            1/1     Running     1          41m
...
...
```

Signed-off-by: Sébastien Han <seb@redhat.com>
2021-04-14 13:38:29 +02:00

450 lines
16 KiB
Go

/*
Copyright 2018 The Rook Authors. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package object
import (
"fmt"
"path"
"strings"
"github.com/hashicorp/vault/api"
"github.com/libopenstorage/secrets/vault"
"github.com/pkg/errors"
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/daemon/ceph/osd/kms"
cephconfig "github.com/rook/rook/pkg/operator/ceph/config"
"github.com/rook/rook/pkg/operator/ceph/controller"
"github.com/rook/rook/pkg/operator/k8sutil"
apps "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
const (
livenessProbePath = "/swift/healthcheck"
// #nosec G101 since this is not leaking any hardcoded details
setupVaultTokenFile = `
set -e
VAULT_TOKEN_OLD_PATH=%s
VAULT_TOKEN_NEW_PATH=%s
cp --verbose $VAULT_TOKEN_OLD_PATH $VAULT_TOKEN_NEW_PATH
chmod --verbose 400 $VAULT_TOKEN_NEW_PATH
chown --verbose ceph:ceph $VAULT_TOKEN_NEW_PATH
`
)
func (c *clusterConfig) createDeployment(rgwConfig *rgwConfig) (*apps.Deployment, error) {
pod, err := c.makeRGWPodSpec(rgwConfig)
if err != nil {
return nil, err
}
replicas := int32(1)
// On Pacific, we can use the same keyring and have dedicated rgw instances reflected in the service map
if c.clusterInfo.CephVersion.IsAtLeastPacific() {
replicas = c.store.Spec.Gateway.Instances
}
d := &apps.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: rgwConfig.ResourceName,
Namespace: c.store.Namespace,
Labels: getLabels(c.store.Name, c.store.Namespace, true),
},
Spec: apps.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: getLabels(c.store.Name, c.store.Namespace, false),
},
Template: pod,
Replicas: &replicas,
Strategy: apps.DeploymentStrategy{
Type: apps.RecreateDeploymentStrategyType,
},
},
}
k8sutil.AddRookVersionLabelToDeployment(d)
c.store.Spec.Gateway.Annotations.ApplyToObjectMeta(&d.ObjectMeta)
c.store.Spec.Gateway.Labels.ApplyToObjectMeta(&d.ObjectMeta)
controller.AddCephVersionLabelToDeployment(c.clusterInfo.CephVersion, d)
return d, nil
}
func (c *clusterConfig) makeRGWPodSpec(rgwConfig *rgwConfig) (v1.PodTemplateSpec, error) {
podSpec := v1.PodSpec{
InitContainers: []v1.Container{
c.makeChownInitContainer(rgwConfig),
},
Containers: []v1.Container{c.makeDaemonContainer(rgwConfig)},
RestartPolicy: v1.RestartPolicyAlways,
Volumes: append(
controller.DaemonVolumes(c.DataPathMap, rgwConfig.ResourceName),
c.mimeTypesVolume(),
),
HostNetwork: c.clusterSpec.Network.IsHost(),
PriorityClassName: c.store.Spec.Gateway.PriorityClassName,
}
// If the log collector is enabled we add the side-car container
if c.clusterSpec.LogCollector.Enabled {
shareProcessNamespace := true
podSpec.ShareProcessNamespace = &shareProcessNamespace
podSpec.Containers = append(podSpec.Containers, *controller.LogCollectorContainer(strings.TrimPrefix(generateCephXUser(fmt.Sprintf("ceph-client.%s", rgwConfig.ResourceName)), "client."), c.clusterInfo.Namespace, *c.clusterSpec))
}
// Replace default unreachable node toleration
k8sutil.AddUnreachableNodeToleration(&podSpec)
// Set the ssl cert if specified
if c.store.Spec.Gateway.SSLCertificateRef != "" {
// Keep the SSL secret as secure as possible in the container. Give only user read perms.
// Because the Secret mount is owned by "root" and fsGroup breaks on OCP since we cannot predict it
// Also, we don't want to change the SCC for fsGroup to RunAsAny since it has a major broader impact
// Let's open the permissions a bit more so that everyone can read the cert.
userReadOnly := int32(0444)
certVol := v1.Volume{
Name: certVolumeName,
VolumeSource: v1.VolumeSource{
Secret: &v1.SecretVolumeSource{
SecretName: c.store.Spec.Gateway.SSLCertificateRef,
Items: []v1.KeyToPath{
{Key: certKeyName, Path: certFilename, Mode: &userReadOnly},
}}}}
podSpec.Volumes = append(podSpec.Volumes, certVol)
}
if c.clusterSpec.Security.KeyManagementService.IsEnabled() {
if c.clusterSpec.Security.KeyManagementService.IsTokenAuthEnabled() {
podSpec.Volumes = append(podSpec.Volumes,
kms.VaultTokenFileVolume(c.clusterSpec.Security.KeyManagementService.TokenSecretName))
podSpec.InitContainers = append(podSpec.InitContainers,
c.vaultTokenInitContainer(rgwConfig))
}
}
c.store.Spec.Gateway.Placement.ApplyToPodSpec(&podSpec)
// If host networking is not enabled, preferred pod anti-affinity is added to the rgw daemons
labels := getLabels(c.store.Name, c.store.Namespace, false)
k8sutil.SetNodeAntiAffinityForPod(&podSpec, c.clusterSpec.Network.IsHost(), v1.LabelHostname, labels, nil)
podTemplateSpec := v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Name: rgwConfig.ResourceName,
Labels: getLabels(c.store.Name, c.store.Namespace, true),
},
Spec: podSpec,
}
c.store.Spec.Gateway.Annotations.ApplyToObjectMeta(&podTemplateSpec.ObjectMeta)
c.store.Spec.Gateway.Labels.ApplyToObjectMeta(&podTemplateSpec.ObjectMeta)
if c.clusterSpec.Network.IsHost() {
podTemplateSpec.Spec.DNSPolicy = v1.DNSClusterFirstWithHostNet
} else if c.clusterSpec.Network.IsMultus() {
if err := k8sutil.ApplyMultus(c.clusterSpec.Network.NetworkSpec, &podTemplateSpec.ObjectMeta); err != nil {
return podTemplateSpec, err
}
}
return podTemplateSpec, nil
}
// The vault token is passed as Secret for rgw container. So it is mounted as read only.
// RGW has restrictions over vault token file, it should owned by same user(ceph) which
// rgw daemon runs and all other permission should be nil or zero. Here ownership can be
// changed with help of FSGroup but in openshift environments for security reasons it has
// predefined value, so it won't work there. Hence the token file is copied to containerDataDir
// from mounted secret then ownership/permissions are changed accordingly with help of a
// init container.
func (c *clusterConfig) vaultTokenInitContainer(rgwConfig *rgwConfig) v1.Container {
_, volMount := kms.VaultVolumeAndMount(c.clusterSpec.Security.KeyManagementService.ConnectionDetails)
return v1.Container{
Name: "vault-initcontainer-token-file-setup",
Command: []string{
"/bin/bash",
"-c",
fmt.Sprintf(setupVaultTokenFile,
path.Join(kms.EtcVaultDir, kms.VaultFileName), path.Join(c.DataPathMap.ContainerDataDir, kms.VaultFileName)),
},
Image: c.clusterSpec.CephVersion.Image,
VolumeMounts: append(
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName), volMount),
Resources: c.store.Spec.Gateway.Resources,
SecurityContext: controller.PodSecurityContext(),
}
}
func (c *clusterConfig) makeChownInitContainer(rgwConfig *rgwConfig) v1.Container {
return controller.ChownCephDataDirsInitContainer(
*c.DataPathMap,
c.clusterSpec.CephVersion.Image,
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName),
c.store.Spec.Gateway.Resources,
controller.PodSecurityContext(),
)
}
func (c *clusterConfig) makeDaemonContainer(rgwConfig *rgwConfig) v1.Container {
// start the rgw daemon in the foreground
container := v1.Container{
Name: "rgw",
Image: c.clusterSpec.CephVersion.Image,
Command: []string{
"radosgw",
},
Args: append(
controller.DaemonFlags(c.clusterInfo, c.clusterSpec,
strings.TrimPrefix(generateCephXUser(rgwConfig.ResourceName), "client.")),
"--foreground",
cephconfig.NewFlag("rgw frontends", fmt.Sprintf("%s %s", rgwFrontendName, c.portString())),
cephconfig.NewFlag("host", controller.ContainerEnvVarReference(k8sutil.PodNameEnvVar)),
cephconfig.NewFlag("rgw-mime-types-file", mimeTypesMountPath()),
cephconfig.NewFlag("rgw realm", rgwConfig.Realm),
cephconfig.NewFlag("rgw zonegroup", rgwConfig.ZoneGroup),
cephconfig.NewFlag("rgw zone", rgwConfig.Zone),
),
VolumeMounts: append(
controller.DaemonVolumeMounts(c.DataPathMap, rgwConfig.ResourceName),
c.mimeTypesVolumeMount(),
),
Env: controller.DaemonEnvVars(c.clusterSpec.CephVersion.Image),
Resources: c.store.Spec.Gateway.Resources,
LivenessProbe: c.generateLiveProbe(),
SecurityContext: controller.PodSecurityContext(),
WorkingDir: cephconfig.VarLogCephDir,
}
// If the liveness probe is enabled
configureLivenessProbe(&container, c.store.Spec.HealthCheck)
if c.store.Spec.Gateway.SSLCertificateRef != "" {
// Add a volume mount for the ssl certificate
mount := v1.VolumeMount{Name: certVolumeName, MountPath: certDir, ReadOnly: true}
container.VolumeMounts = append(container.VolumeMounts, mount)
}
if c.clusterSpec.Security.KeyManagementService.IsEnabled() {
container.Args = append(container.Args,
cephconfig.NewFlag("rgw crypt s3 kms backend",
c.clusterSpec.Security.KeyManagementService.ConnectionDetails[kms.Provider]),
cephconfig.NewFlag("rgw crypt vault addr",
c.clusterSpec.Security.KeyManagementService.ConnectionDetails[api.EnvVaultAddress]),
)
if c.clusterSpec.Security.KeyManagementService.IsTokenAuthEnabled() {
container.Args = append(container.Args,
cephconfig.NewFlag("rgw crypt vault auth", kms.KMSTokenSecretNameKey),
cephconfig.NewFlag("rgw crypt vault token file",
path.Join(c.DataPathMap.ContainerDataDir, kms.VaultFileName)),
cephconfig.NewFlag("rgw crypt vault prefix", c.vaultPrefixRGW()),
cephconfig.NewFlag("rgw crypt vault secret engine",
c.clusterSpec.Security.KeyManagementService.ConnectionDetails[kms.VaultSecretEngineKey]),
)
}
}
return container
}
// configureLivenessProbe returns the desired liveness probe for a given daemon
func configureLivenessProbe(container *v1.Container, healthCheck cephv1.BucketHealthCheckSpec) {
if ok := healthCheck.LivenessProbe; ok != nil {
if !healthCheck.LivenessProbe.Disabled {
probe := healthCheck.LivenessProbe.Probe
// If the spec value is empty, let's use a default
if probe != nil {
// Set the liveness probe on the container to overwrite the default probe created by Rook
container.LivenessProbe = cephconfig.GetLivenessProbeWithDefaults(probe, container.LivenessProbe)
}
} else {
container.LivenessProbe = nil
}
}
}
func (c *clusterConfig) generateLiveProbe() *v1.Probe {
return &v1.Probe{
Handler: v1.Handler{
HTTPGet: &v1.HTTPGetAction{
Path: livenessProbePath,
Port: c.generateLiveProbePort(),
Scheme: c.generateLiveProbeScheme(),
},
},
InitialDelaySeconds: 10,
}
}
func (c *clusterConfig) generateLiveProbeScheme() v1.URIScheme {
// Default to HTTP
uriScheme := v1.URISchemeHTTP
// If rgw is configured to use a secured port we need get on https://
// Only do this when the Non-SSL port is not used
if c.store.Spec.Gateway.Port == 0 && c.store.Spec.Gateway.SecurePort != 0 && c.store.Spec.Gateway.SSLCertificateRef != "" {
uriScheme = v1.URISchemeHTTPS
}
return uriScheme
}
func (c *clusterConfig) generateLiveProbePort() intstr.IntOrString {
// The port the liveness probe needs to probe
// Assume we run on SDN by default
port := intstr.FromInt(int(rgwPortInternalPort))
// If Host Networking is enabled, the port from the spec must be reflected
if c.clusterSpec.Network.IsHost() {
port = intstr.FromInt(int(c.store.Spec.Gateway.Port))
}
if c.store.Spec.Gateway.Port == 0 && c.store.Spec.Gateway.SecurePort != 0 && c.store.Spec.Gateway.SSLCertificateRef != "" {
port = intstr.FromInt(int(c.store.Spec.Gateway.SecurePort))
}
return port
}
func (c *clusterConfig) generateService(cephObjectStore *cephv1.CephObjectStore) *v1.Service {
svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: instanceName(cephObjectStore.Name),
Namespace: cephObjectStore.Namespace,
Labels: getLabels(cephObjectStore.Name, cephObjectStore.Namespace, true),
},
}
if c.clusterSpec.Network.IsHost() {
svc.Spec.ClusterIP = v1.ClusterIPNone
}
destPort := c.generateLiveProbePort()
// When the cluster is external we must use the same one as the gateways are listening on
if cephObjectStore.Spec.IsExternal() {
destPort.IntVal = cephObjectStore.Spec.Gateway.Port
} else {
// If the cluster is not external we add the Selector
svc.Spec = v1.ServiceSpec{
Selector: getLabels(cephObjectStore.Name, cephObjectStore.Namespace, false),
}
}
addPort(svc, "http", cephObjectStore.Spec.Gateway.Port, destPort.IntVal)
addPort(svc, "https", cephObjectStore.Spec.Gateway.SecurePort, cephObjectStore.Spec.Gateway.SecurePort)
return svc
}
func (c *clusterConfig) generateEndpoint(cephObjectStore *cephv1.CephObjectStore) *v1.Endpoints {
labels := getLabels(cephObjectStore.Name, cephObjectStore.Namespace, true)
endpoints := &v1.Endpoints{
ObjectMeta: metav1.ObjectMeta{
Name: instanceName(cephObjectStore.Name),
Namespace: cephObjectStore.Namespace,
Labels: labels,
},
Subsets: []v1.EndpointSubset{
{
Addresses: cephObjectStore.Spec.Gateway.ExternalRgwEndpoints,
},
},
}
addPortToEndpoint(endpoints, "http", cephObjectStore.Spec.Gateway.Port)
addPortToEndpoint(endpoints, "https", cephObjectStore.Spec.Gateway.SecurePort)
return endpoints
}
func (c *clusterConfig) reconcileExternalEndpoint(cephObjectStore *cephv1.CephObjectStore) error {
logger.Info("reconciling external object store service")
endpoint := c.generateEndpoint(cephObjectStore)
// Set owner ref to the parent object
err := c.ownerInfo.SetControllerReference(endpoint)
if err != nil {
return errors.Wrapf(err, "failed to set owner reference to ceph object store endpoint %q", endpoint.Name)
}
_, err = k8sutil.CreateOrUpdateEndpoint(c.context.Clientset, cephObjectStore.Namespace, endpoint)
if err != nil {
return errors.Wrapf(err, "failed to create or update object store %q endpoint", cephObjectStore.Name)
}
return nil
}
func (c *clusterConfig) reconcileService(cephObjectStore *cephv1.CephObjectStore) (string, error) {
service := c.generateService(cephObjectStore)
// Set owner ref to the parent object
err := c.ownerInfo.SetControllerReference(service)
if err != nil {
return "", errors.Wrapf(err, "failed to set owner reference to ceph object store service %q", service.Name)
}
svc, err := k8sutil.CreateOrUpdateService(c.context.Clientset, cephObjectStore.Namespace, service)
if err != nil {
return "", errors.Wrapf(err, "failed to create or update object store %q service", cephObjectStore.Name)
}
logger.Infof("ceph object store gateway service running at %s", svc.Spec.ClusterIP)
return svc.Spec.ClusterIP, nil
}
func (c *clusterConfig) vaultPrefixRGW() string {
secretEngine := c.clusterSpec.Security.KeyManagementService.ConnectionDetails[kms.VaultSecretEngineKey]
vaultPrefixPath := "/v1/"
switch secretEngine {
case kms.VaultKVSecretEngineKey:
vaultPrefixPath = path.Join(vaultPrefixPath,
c.clusterSpec.Security.KeyManagementService.ConnectionDetails[vault.VaultBackendPathKey])
case kms.VaultTransitSecretEngineKey:
vaultPrefixPath = path.Join(vaultPrefixPath, secretEngine, "/export/encryption-key")
}
return vaultPrefixPath
}
func addPort(service *v1.Service, name string, port, destPort int32) {
if port == 0 || destPort == 0 {
return
}
service.Spec.Ports = append(service.Spec.Ports, v1.ServicePort{
Name: name,
Port: port,
TargetPort: intstr.FromInt(int(destPort)),
Protocol: v1.ProtocolTCP,
})
}
func addPortToEndpoint(endpoints *v1.Endpoints, name string, port int32) {
if port == 0 {
return
}
endpoints.Subsets[0].Ports = append(endpoints.Subsets[0].Ports, v1.EndpointPort{
Name: name,
Port: port,
Protocol: v1.ProtocolTCP,
},
)
}
func getLabels(name, namespace string, includeNewLabels bool) map[string]string {
labels := controller.CephDaemonAppLabels(AppName, namespace, "rgw", name, includeNewLabels)
labels["rook_object_store"] = name
return labels
}