Skip to content
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

Merged
merged 15 commits into from
Apr 20, 2023

Conversation

adamrdrew
Copy link
Collaborator

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.

// None there so set the default
return []string{"/fed-mods.json"}
}
filesToCacheBust := []string{}
Copy link
Collaborator Author

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

@adamrdrew
Copy link
Collaborator Author

It works! Or, at least I think it does based on testing!

--- PASS: kuttl (328.40s)
    --- PASS: kuttl/harness (0.00s)
        --- PASS: kuttl/harness/basic-frontend (17.47s)
        --- PASS: kuttl/harness/networking (17.50s)
        --- PASS: kuttl/harness/whitelist (17.53s)
        --- PASS: kuttl/harness/storage (17.50s)
        --- PASS: kuttl/harness/ssl (183.04s)
        --- PASS: kuttl/harness/frontend-paths (17.51s)
        --- PASS: kuttl/harness/generate-nav-json (17.50s)
        --- PASS: kuttl/harness/cachebust (17.69s)
        --- PASS: kuttl/harness/bundles (17.53s)

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.

@adamrdrew adamrdrew marked this pull request as ready for review April 13, 2023 19:14
@adamrdrew
Copy link
Collaborator Author

Oh I see a couple of problems I need to test for

  • Make sure the akamai purge command is right
  • Make sure specific files works

@adamrdrew
Copy link
Collaborator Author

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

@adamrdrew
Copy link
Collaborator Author

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"
Copy link
Collaborator

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://") {
Copy link
Collaborator

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?

// If purgeHost ends with a / then remove it
purgeHost = strings.TrimSuffix(purgeHost, "/")

frontendName := frontend.Name
Copy link
Collaborator

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?


// 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)
Copy link
Collaborator

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()})
Copy link
Collaborator

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, " "))
Copy link
Collaborator

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.

@adamrdrew
Copy link
Collaborator Author

I'm going to merge this. The couple of things outstanding were small - nothing architectural. I did change some of what was suggested - thanks!

@adamrdrew adamrdrew merged commit 9ae24ea into main Apr 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants