ceph: report secret in cephobjectstoreuser status field
adding method to generate secret name in cephobjectstoreuser status field in order to programmatically retrieve the secret name generated by the cephobjectstoreuser crd. Also added unit test for the method. Signed-off-by: subhamkrai <subhamkumarrai03@gmail.com>
This commit is contained in:
1 parent
4a72875089
commit
3e33fc55a3
4 files changed
+38
-8
No files matched your search
@@ -503,8 +503,13 @@ type BucketStatus struct {
|
||||
type CephObjectStoreUser struct {
|
||||
metav1.TypeMeta `json:",inline"`
|
||||
metav1.ObjectMeta `json:"metadata"`
|
||||
Spec ObjectStoreUserSpec `json:"spec"`
|
||||
Status *Status `json:"status"`
|
||||
Spec ObjectStoreUserSpec `json:"spec"`
|
||||
Status *ObjectStoreUserStatus `json:"status"`
|
||||
}
|
||||
|
||||
type ObjectStoreUserStatus struct {
|
||||
Phase string `json:"phase,omitempty"`
|
||||
Info map[string]string `json:"info"`
|
||||
}
|
||||
|
||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
|
||||
|
||||
@@ -561,7 +561,7 @@ func (in *CephObjectStoreUser) DeepCopyInto(out *CephObjectStoreUser) {
|
||||
out.Spec = in.Spec
|
||||
if in.Status != nil {
|
||||
in, out := &in.Status, &out.Status
|
||||
*out = new(Status)
|
||||
*out = new(ObjectStoreUserStatus)
|
||||
**out = **in
|
||||
}
|
||||
return
|
||||
|
||||
@@ -332,6 +332,16 @@ func generateUserConfig(user *cephv1.CephObjectStoreUser) object.ObjectUser {
|
||||
return userConfig
|
||||
}
|
||||
|
||||
func generateCephUserSecretName(u *cephv1.CephObjectStoreUser) string {
|
||||
return fmt.Sprintf("rook-ceph-object-user-%s-%s", u.Spec.Store, u.Name)
|
||||
}
|
||||
|
||||
func generateStatusInfo(u *cephv1.CephObjectStoreUser) map[string]string {
|
||||
m := make(map[string]string)
|
||||
m["secretName"] = generateCephUserSecretName(u)
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *ReconcileObjectStoreUser) generateCephUserSecret(u *cephv1.CephObjectStoreUser) *v1.Secret {
|
||||
// Store the keys in a secret
|
||||
secrets := map[string]string{
|
||||
@@ -339,11 +349,9 @@ func (r *ReconcileObjectStoreUser) generateCephUserSecret(u *cephv1.CephObjectSt
|
||||
"SecretKey": *r.userConfig.SecretKey,
|
||||
"Endpoint": r.objContext.Endpoint,
|
||||
}
|
||||
|
||||
secretName := fmt.Sprintf("rook-ceph-object-user-%s-%s", u.Spec.Store, u.Name)
|
||||
secret := &v1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: secretName,
|
||||
Name: generateCephUserSecretName(u),
|
||||
Namespace: u.Namespace,
|
||||
Labels: map[string]string{
|
||||
"app": appName,
|
||||
@@ -355,7 +363,6 @@ func (r *ReconcileObjectStoreUser) generateCephUserSecret(u *cephv1.CephObjectSt
|
||||
StringData: secrets,
|
||||
Type: k8sutil.RookType,
|
||||
}
|
||||
|
||||
return secret
|
||||
}
|
||||
|
||||
@@ -494,10 +501,13 @@ func updateStatus(client client.Client, name types.NamespacedName, status string
|
||||
return
|
||||
}
|
||||
if user.Status == nil {
|
||||
user.Status = &cephv1.Status{}
|
||||
user.Status = &cephv1.ObjectStoreUserStatus{}
|
||||
}
|
||||
|
||||
user.Status.Phase = status
|
||||
if user.Status.Phase == k8sutil.ReadyStatus {
|
||||
user.Status.Info = generateStatusInfo(user)
|
||||
}
|
||||
if err := opcontroller.UpdateStatus(client, user); err != nil {
|
||||
logger.Errorf("failed to set object store user %q status to %q. %v", name, status, err)
|
||||
return
|
||||
|
||||
@@ -296,3 +296,18 @@ func TestCephObjectStoreUserController(t *testing.T) {
|
||||
assert.Equal(t, "Ready", objectUser.Status.Phase, objectUser)
|
||||
logger.Info("PHASE 5 DONE")
|
||||
}
|
||||
|
||||
func TestBuildUpdateStatusInfo(t *testing.T) {
|
||||
cephObjectStoreUser := &cephv1.CephObjectStoreUser{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: cephv1.ObjectStoreUserSpec{
|
||||
Store: store,
|
||||
},
|
||||
}
|
||||
|
||||
statusInfo := generateStatusInfo(cephObjectStoreUser)
|
||||
assert.NotEmpty(t, statusInfo["secretName"])
|
||||
assert.Equal(t, "rook-ceph-object-user-my-store-my-user", statusInfo["secretName"])
|
||||
}
|
||||
Reference in new issue
Block a user