-
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 #59
base: main
Are you sure you want to change the base?
Conversation
@@ -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?
One question: you made the owner value updatable for some cases. Why is that necessary? Shouldn't that be immutable? |
Could you please mention which coding location you are referring to? |
UpdateSpace(ctx context.Context, guid string, name string, generation int64) error | ||
DeleteSpace(ctx context.Context, guid string) error | ||
UpdateSpace(ctx context.Context, guid string, name string, owner string, generation int64) error | ||
DeleteSpace(ctx context.Context, guid string, owner string) error | ||
AddAuditor(ctx context.Context, guid string, username string) error | ||
AddDeveloper(ctx context.Context, guid string, username string) error | ||
AddManager(ctx context.Context, guid string, username string) error | ||
} | ||
|
||
type OrganizationClientBuilder func(string, string, string, string) (OrganizationClient, error) | ||
type OrganizationClientBuilder func(string, string, string, string, *config.Config) (OrganizationClient, error) | ||
|
||
//counterfeiter:generate . SpaceClient | ||
type SpaceClient interface { | ||
GetInstance(ctx context.Context, instanceOpts map[string]string) (*Instance, error) | ||
CreateInstance(ctx context.Context, name string, servicePlanGuid string, parameters map[string]interface{}, tags []string, owner string, generation int64) error | ||
UpdateInstance(ctx context.Context, guid string, name string, servicePlanGuid string, parameters map[string]interface{}, tags []string, generation int64) error | ||
DeleteInstance(ctx context.Context, guid string) error | ||
UpdateInstance(ctx context.Context, guid string, name string, owner string, servicePlanGuid string, parameters map[string]interface{}, tags []string, generation int64) error | ||
DeleteInstance(ctx context.Context, guid string, owner string) error | ||
|
||
GetBinding(ctx context.Context, bindingOpts map[string]string) (*Binding, error) | ||
CreateBinding(ctx context.Context, name string, serviceInstanceGuid string, parameters map[string]interface{}, owner string, generation int64) error | ||
UpdateBinding(ctx context.Context, guid string, generation int64, parameters map[string]interface{}) error | ||
DeleteBinding(ctx context.Context, guid string) error | ||
UpdateBinding(ctx context.Context, guid string, owner string, generation int64, parameters map[string]interface{}) error | ||
DeleteBinding(ctx context.Context, guid string, owner string) error |
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 changes about adding the owner.
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.