-
Notifications
You must be signed in to change notification settings - Fork 18
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
[RHCLOUD-25111] Akamai Cache Bust Init Container #105
Conversation
controllers/reconcile.go
Outdated
// None there so set the default | ||
return []string{"/fed-mods.json"} | ||
} | ||
filesToCacheBust := []string{} |
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.
Make sure fed-mods is always there
… a redundant guard.
It works! Or, at least I think it does based on testing!
AFAICT this does what it says on the tin: you can run a cachebust initcontainer, it will pass some opts to the entrypoint; it is configured at the env level but individual frontends can opt out. I will fix whatever the linter is mad about this and flip it to ready to review. |
Oh I see a couple of problems I need to test for
|
OK, as far as I can tell this is ready for review. The kuttl tests really helped me develop this and I feel much more confident in it than I would have before. @psav if you could give this a look Monday that would be awesome |
my one open question here is whether or not the command we want to run in the initcontainer will actually work when we use the real cache busting image. I should be able to safely run it with the real image considering we're using fake URLs / paths. We wouldn't want that in automated tests like in a PR check or something, but I could try it locally |
|
||
// constructAkamaiEdgercFileFromSecret constructs the akamai edgerc file from the secret | ||
func makeAkamaiEdgercFileFromSecret(secret *v1.Secret) string { | ||
edgercFile := "[default]\n" |
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.
At the risk of just asking for work for works sake, which I would never do, a part of me sees it would be nice to have a function that takes a key, value as args and spits out the line. Better yet a function that takes a map[string]string
and just spits them all out, writing just the section and that then doesn't feel so bad, but I'm open to ignoring that. I know I would do it if it were my PR, but I honestly don't mind either way.
func createCachePurgePathList(frontend *crd.Frontend, frontendEnvironment *crd.FrontendEnvironment) []string { | ||
var purgeHost string | ||
// If the cache bust URL doesn't begin with https:// then add it | ||
if strings.HasPrefix(frontendEnvironment.Spec.AkamaiCacheBustURL, "https://") { |
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.
Is this to deal with a secret that already exists and doesn't have the https://
in front of it. It feels needless in a sense of - if we ask for a URL, please supply a URL. Thoughts?
controllers/reconcile.go
Outdated
// If purgeHost ends with a / then remove it | ||
purgeHost = strings.TrimSuffix(purgeHost, "/") | ||
|
||
frontendName := frontend.Name |
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.
Necessary for a single use?
controllers/reconcile.go
Outdated
|
||
// If there is no purge list return the default | ||
if frontend.Spec.AkamaiCacheBustPaths == nil { | ||
defaultPurgePath := fmt.Sprintf("%s/apps/%s/fed-mods.json", purgeHost, frontendName) |
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.
Did we speak before about ALWAYS having this in the list, in which case, the default purgePaths []string{}
could be prepopulated and we could remove this block entirely?
labler := utils.GetCustomLabeler(labels, nn, r.FrontendEnvironment) | ||
labler(configMap) | ||
|
||
configMap.SetOwnerReferences([]metav1.OwnerReference{r.FrontendEnvironment.MakeOwnerReference()}) |
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 there is a make owner references function that does this part for you, please let me know if you dont' find it or if it doesn't do what you need. It should.
pathsToCacheBust := createCachePurgePathList(frontend, frontendEnvironment) | ||
|
||
// Construct the akamai cache bust command | ||
command := fmt.Sprintf("/cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc invalidate %s", strings.Join(pathsToCacheBust, " ")) |
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.
These can't be supplied by ENV VAR? I guess this is because we need to use the vanilla image. I was going to suggest putting a script to do the work, and make the list of paths an ENV VAR but I think I understand why we can't.
I'm going to merge this. The couple of things outstanding were small - nothing architectural. I did change some of what was suggested - thanks! |
This patch adds an initcontainer to frontend deployments that busts akamai cache, along with a lot of config options to control how and where cache busting happens.