ceph: expose endpoint in the CephObjectStoreUser

Now, when an S3 user gets created, Rook will add the S3 endpoint to the
Secret along with the credentials.

Signed-off-by: Sébastien Han <seb@redhat.com>
This commit is contained in:
Sébastien Han committed 2020-07-10 15:59:47 +02:00
1 parent 5c5008e27c
commit 07c7dd457f
8 files changed
+49 -22

No files matched your search

+5 -3
View File
@@ -18,9 +18,11 @@
- OBC changes:
- Updated lib bucket provisioner version to support multithread and required change can be found in [operator.yaml](cluster/examples/kubernetes/ceph/operator.yaml#L449)
- Can be extended to add support for other providers
- The Rook operator reflects the health of the CephObjectStore in its status field
- The CephObjectStore CR supports connecting to external Ceph Rados Gateways, refer to the [external object section](Documentation/ceph-object.html#connect-to-external-object-store)
- The CephObjectStore CR runs health checks on the object store endpoint, refer to the [health check section](Documentation/ceph-object-store-crd.html#health-settings)
- CephObjectStore CRD changes:
- Health displayed in the Status field
- Supports connecting to external Ceph Rados Gateways, refer to the [external object section](Documentation/ceph-object.html#connect-to-external-object-store)
- The CephObjectStore CR runs health checks on the object store endpoint, refer to the [health check section](Documentation/ceph-object-store-crd.html#health-settings)
- The endpoint is now displayed in the Status field
### EdgeFS
@@ -165,6 +165,7 @@ func TestCephObjectStoreController(t *testing.T) {
TypeMeta: controllerTypeMeta,
}
cephCluster := &cephv1.CephCluster{}
objectStore.Spec.Gateway.Port = 80
// Objects to track in the fake client.
object := []runtime.Object{
@@ -329,5 +330,7 @@ func TestCephObjectStoreController(t *testing.T) {
err = r.client.Get(context.TODO(), req.NamespacedName, objectStore)
assert.NoError(t, err)
assert.Equal(t, cephv1.ConditionReady, objectStore.Status.Phase, objectStore)
assert.NotEmpty(t, objectStore.Status.Info["endpoint"], objectStore)
assert.Equal(t, "http://rook-ceph-rgw-my-store.rook-ceph:80", objectStore.Status.Info["endpoint"], objectStore)
logger.Info("PHASE 3 DONE")
}
+6 -2
View File
@@ -367,6 +367,10 @@ func BuildDomainName(name, namespace string) string {
}
// buildDNSEndpoint build the dns name to reach out the service endpoint
func buildDNSEndpoint(domainName string, port int32) string {
return fmt.Sprintf("http://%s:%d", domainName, port)
func buildDNSEndpoint(domainName string, port int32, secure bool) string {
httpPrefix := "http"
if secure {
httpPrefix = "https"
}
return fmt.Sprintf("%s://%s:%d", httpPrefix, domainName, port)
}
+9 -1
View File
@@ -24,6 +24,7 @@ import (
cephv1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1"
"github.com/rook/rook/pkg/client/clientset/versioned/scheme"
"github.com/rook/rook/pkg/clusterd"
config "github.com/rook/rook/pkg/daemon/ceph/config"
cephconfig "github.com/rook/rook/pkg/operator/ceph/config"
testop "github.com/rook/rook/pkg/operator/test"
@@ -160,7 +161,14 @@ func TestBuildDomainNameAndEndpoint(t *testing.T) {
ns := "rook-ceph"
dns := BuildDomainName(name, ns)
assert.Equal(t, "rook-ceph-rgw-my-store.rook-ceph", dns)
// non-secure endpoint
var port int32 = 80
ep := buildDNSEndpoint(dns, port)
ep := buildDNSEndpoint(dns, port, false)
assert.Equal(t, "http://rook-ceph-rgw-my-store.rook-ceph:80", ep)
// Secure endpoint
var securePort int32 = 443
ep = buildDNSEndpoint(dns, securePort, true)
assert.Equal(t, "https://rook-ceph-rgw-my-store.rook-ceph:443", ep)
}
+7 -4
View File
@@ -49,9 +49,8 @@ func updateStatus(client client.Client, namespacedName types.NamespacedName, sta
}
objectStore.Status.Phase = status
if len(info) != 0 {
objectStore.Status.Info = info
}
objectStore.Status.Info = info
if err := opcontroller.UpdateStatus(client, objectStore); err != nil {
logger.Errorf("failed to set object store %q status to %q. %v", namespacedName, status, err)
return
@@ -82,7 +81,11 @@ func updateStatusBucket(client client.Client, name types.NamespacedName, phase c
func buildStatusInfo(cephObjectStore *cephv1.CephObjectStore) map[string]string {
m := make(map[string]string)
m["endpoint"] = buildDNSEndpoint(BuildDomainName(cephObjectStore.Name, cephObjectStore.Namespace), cephObjectStore.Spec.Gateway.Port)
m["endpoint"] = buildDNSEndpoint(BuildDomainName(cephObjectStore.Name, cephObjectStore.Namespace), cephObjectStore.Spec.Gateway.Port, false)
if cephObjectStore.Spec.Gateway.SecurePort != 0 {
m["secureEndpoint"] = buildDNSEndpoint(BuildDomainName(cephObjectStore.Name, cephObjectStore.Namespace), cephObjectStore.Spec.Gateway.SecurePort, true)
}
return m
}
+13 -12
View File
@@ -194,7 +194,7 @@ func (r *ReconcileObjectStoreUser) reconcile(request reconcile.Request) (reconci
r.clusterInfo = clusterInfo
// validate isObjectStoreInitialized
objContext, err := r.isObjectStoreInitialized(cephObjectStoreUser)
err = r.isObjectStoreInitialized(cephObjectStoreUser)
if err != nil {
if !cephObjectStoreUser.GetDeletionTimestamp().IsZero() {
// Remove finalizer
@@ -211,8 +211,6 @@ func (r *ReconcileObjectStoreUser) reconcile(request reconcile.Request) (reconci
updateStatus(r.client, request.NamespacedName, k8sutil.ReconcileFailedStatus)
return opcontroller.WaitForRequeueIfCephClusterNotReady, nil
}
// Set the object store context
r.objContext = objContext
// Generate user config
userConfig := generateUserConfig(cephObjectStoreUser)
@@ -306,21 +304,16 @@ func (r *ReconcileObjectStoreUser) createCephUser(u *cephv1.CephObjectStoreUser)
return nil
}
func (r *ReconcileObjectStoreUser) isObjectStoreInitialized(u *cephv1.CephObjectStoreUser) (*object.Context, error) {
func (r *ReconcileObjectStoreUser) isObjectStoreInitialized(u *cephv1.CephObjectStoreUser) error {
objContext := object.NewContext(r.context, u.Spec.Store, u.Namespace)
// If the cluster is external just return
// we don't need to validate u.Spec.Store
if r.cephClusterSpec.External.Enable {
return objContext, nil
}
r.objContext = objContext
err := r.objectStoreInitialized(u)
if err != nil {
return objContext, errors.Wrap(err, "failed to detect if object store is initialized")
return errors.Wrap(err, "failed to detect if object store is initialized")
}
return objContext, nil
return nil
}
func generateUserConfig(user *cephv1.CephObjectStoreUser) object.ObjectUser {
@@ -344,6 +337,7 @@ func (r *ReconcileObjectStoreUser) generateCephUserSecret(u *cephv1.CephObjectSt
secrets := map[string]string{
"AccessKey": *r.userConfig.AccessKey,
"SecretKey": *r.userConfig.SecretKey,
"Endpoint": r.objContext.Endpoint,
}
secretName := fmt.Sprintf("rook-ceph-object-user-%s-%s", u.Spec.Store, u.Name)
@@ -392,6 +386,12 @@ func (r *ReconcileObjectStoreUser) objectStoreInitialized(cephObjectStoreUser *c
}
logger.Debug("CephObjectStore exists")
// If the cluster is external just return
// since there are no pods running
if r.cephClusterSpec.External.Enable {
return nil
}
// There are no pods running when the cluster is external
// Unless you pass the admin key...
pods, err := r.getRgwPodList(cephObjectStoreUser)
@@ -422,6 +422,7 @@ func (r *ReconcileObjectStoreUser) getObjectStore(storeName string) error {
for _, store := range objectStores.Items {
if store.Name == storeName {
logger.Infof("CephObjectStore %q found", storeName)
r.objContext.Endpoint = store.Status.Info["endpoint"]
return nil
}
}
@@ -253,6 +253,9 @@ func TestCephObjectStoreUserController(t *testing.T) {
TypeMeta: metav1.TypeMeta{
Kind: "CephObjectStore",
},
Status: &cephv1.ObjectStoreStatus{
Info: map[string]string{"endpoint": "http://rook-ceph-rgw-my-store.rook-ceph:80"},
},
}
s.AddKnownTypes(cephv1.SchemeGroupVersion, &cephv1.CephObjectStore{})
s.AddKnownTypes(cephv1.SchemeGroupVersion, &cephv1.CephObjectStoreList{})
@@ -85,6 +85,9 @@ func runObjectE2ETest(helper *clients.TestClient, k8sh *utils.K8sHelper, s suite
objectStore, err := k8sh.RookClientset.CephV1().CephObjectStores(namespace).Get(storeName, metav1.GetOptions{})
assert.Nil(s.T(), err)
assert.Equal(s.T(), cephv1.ConditionHealthy, objectStore.Status.BucketStatus.Health)
// Info field has the endpoint in it
assert.NotEmpty(s.T(), objectStore.Status.Info)
assert.NotEmpty(s.T(), objectStore.Status.Info["endpoint"])
assert.True(s.T(), helper.ObjectUserClient.UserSecretExists(namespace, storeName, userid))
userInfo, err := helper.ObjectUserClient.GetUser(namespace, storeName, userid)