Skip to content

Commit

Permalink
Fixed Conversations
Browse files Browse the repository at this point in the history
Signed-off-by: satakshigarg <satakshi@civo.com>
  • Loading branch information
satakshigarg committed Sep 12, 2022
1 parent 86b2ca6 commit 622a241
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
37 changes: 22 additions & 15 deletions internal/controller/civoObjectStore/civoobjectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,28 +209,31 @@ func (e *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
}

var createObjectStoreRequest civogo.CreateObjectStoreRequest
specifiedObjectStore, err := FindObjectStoreViaKey(e.civoGoClient, cr.Spec.AccessKey)
if specifiedObjectStore != nil {
cred, err := FindObjectStoreCreds(e.civoGoClient, cr.Spec.AccessKey)
if err != nil {
createObjectStoreRequest = civogo.CreateObjectStoreRequest{
Name: specifiedObjectStore.Name,
MaxSizeGB: int64(specifiedObjectStore.MaxSize),
AccessKeyID: specifiedObjectStore.OwnerInfo.AccessKeyID,
Name: cred.Name,
MaxSizeGB: int64(cred.MaxSize),
AccessKeyID: cred.OwnerInfo.AccessKeyID,
Region: e.civoGoClient.Region,
}
} else {
createObjectStoreRequest = civogo.CreateObjectStoreRequest{
Name: specifiedObjectStore.Name,
MaxSizeGB: int64(specifiedObjectStore.MaxSize),
AccessKeyID: "",
Region: e.civoGoClient.Region,
Name: cred.Name,
MaxSizeGB: int64(cred.MaxSize),
Region: e.civoGoClient.Region,
}
}
e.civoGoClient.NewObjectStore(&createObjectStoreRequest)
_, err = e.civoGoClient.NewObjectStore(&createObjectStoreRequest)
cr.SetConditions(xpv1.Creating())
if err != nil {
return managed.ExternalCreation{}, err
return managed.ExternalCreation{
ExternalNameAssigned: true,
}, err
}
return managed.ExternalCreation{}, nil
return managed.ExternalCreation{
ExternalNameAssigned: true,
}, nil
}

func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.ExternalUpdate, error) {
Expand All @@ -242,10 +245,14 @@ func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
if err != nil {
return managed.ExternalUpdate{}, err
}
if civoObjectStore.MaxSize == int(cr.Status.AtProvider.MaxSize) {
return managed.ExternalUpdate{}, nil
updateObjectStoreRequest := civogo.UpdateObjectStoreRequest{
MaxSizeGB: int64(cr.Status.AtProvider.MaxSize),
Region: e.civoGoClient.Region,
}
_, err = e.civoGoClient.UpdateObjectStore(civoObjectStore.ID, &updateObjectStoreRequest)
if err != nil {
return managed.ExternalUpdate{}, err
}
civoObjectStore.MaxSize = cr.Status.AtProvider.MaxSize
return managed.ExternalUpdate{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/civoObjectStore/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func FindObjectStore(c *civogo.Client, search string) (*civogo.ObjectStore, erro

}

func FindObjectStoreViaKey(c *civogo.Client, search string) (*civogo.ObjectStore, error) {
func FindObjectStoreCreds(c *civogo.Client, search string) (*civogo.ObjectStore, error) {
objectstores, err := c.ListObjectStores()
if err != nil {
return nil, err
Expand Down

0 comments on commit 622a241

Please sign in to comment.