-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In-Memory Cache for CF Resources (Service Instances) #59
base: main
Are you sure you want to change the base?
Conversation
serviceBinding.SetReadyCondition(cfv1alpha1.ConditionUnknown, string(cfbinding.State), cfbinding.StateDescription) | ||
return ctrl.Result{Requeue: true}, nil | ||
//return the reconcile function to not reconcile and error message | ||
return ctrl.Result{}, fmt.Errorf("orphaned instance is not ready to be adopted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be orphaned binding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right
internal/cf/resourcecache.go
Outdated
|
||
// TODO: document which keys are used for the maps | ||
// TODO: check if the keys for resources like spaces are unique across all CF organziations | ||
// Scenario: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The keys used for the maps are the label owner which is constructed this way, "service-operator.cf.cs.sap.com/owner": "K8s UID".
This applies to the bindings, spaces, and instances. Not sure if that answers these two TODOs.
// getCachedInstances retrieves all instances from the cache | ||
func (c *resourceCache) getCachedInstances() map[string]*facade.Instance { | ||
return c.instances | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that if another reconciliation tries to modify the cache by adding or deleting instances we can have a race condition. I would add an RLock() so we are sure that it is safe to access when retrieving instances.
I think the same about the spaces and bindings.
@@ -210,5 +254,257 @@ func NewSpaceHealthChecker(spaceGuid string, url string, username string, passwo | |||
} | |||
} | |||
|
|||
if config.IsResourceCacheEnabled && client.resourceCache == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@TheBigElmo
It assigns the resourceCache
created by the organization unit client and space client and will use the spaceCache
populated by the organization unit client in the cf/health.go
.
Currently the health.go
uses the spaceClient to call the CF API. Is this OK to use the cache populated by the organization client?
Summary
We want to introduce a mechanism for batching and caching CF resources. By storing the CF resources in memory, we aim to reduce the number of requests to the CF API and avoid reaching the rate limit.
Approach
The cache feature is optional and can be enabled via the environment variable
RESOURCE_CACHE_ENABLED
, which can have values oftrue
orfalse
.Another environment variable,
CACHE_TIMEOUT
, is introduced to control the refresh of the cached resources, based on alastCacheTime
attribute of the Cache instance.At the start of the operator, an instance of a Config object is created. This config object has two attributes with values of the environment variables described above.
The first time the' spaceClient' is created, an instance of the Cache object is created and populated.
The Cache instance will be refreshed every time the cache time-out is reached.