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

Extend pre-cache-bust delay and add support for arbitrary URLs #206

Merged
merged 7 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,29 @@ func makeAkamaiEdgercFileFromSecret(secret *v1.Secret) string {
}

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://") {
purgeHost = frontendEnvironment.Spec.AkamaiCacheBustURL
} else {
purgeHost = fmt.Sprintf("https://%s", frontendEnvironment.Spec.AkamaiCacheBustURL)
}
// Set purgeHost by ensuring the URL begins with https:// and has no trailing /
purgeHost := strings.TrimSuffix(fmt.Sprintf("https://%s", strings.TrimPrefix(frontendEnvironment.Spec.AkamaiCacheBustURL, "https://")), "/")

// If purgeHost ends with a / then remove it
purgeHost = strings.TrimSuffix(purgeHost, "/")
// Initialize with a default path if AkamaiCacheBustPaths is nil
purgePaths := []string{fmt.Sprintf("%s/apps/%s/fed-mods.json", purgeHost, frontend.Name)}

// If there is no purge list return the default
if frontend.Spec.AkamaiCacheBustPaths == nil {
return []string{fmt.Sprintf("%s/apps/%s/fed-mods.json", purgeHost, frontend.Name)}
return purgePaths
}

purgePaths := []string{}
// Loop through the frontend purge paths and append them to the purge host
purgePaths = make([]string, 0, len(frontend.Spec.AkamaiCacheBustPaths))
for _, path := range frontend.Spec.AkamaiCacheBustPaths {
var purgePath string
// If the path doesn't begin with a / then add it
if strings.HasPrefix(path, "/") {
purgePath = fmt.Sprintf("%s%s", purgeHost, path)
// Check if path is a full URL (starts with "http://" or "https://")
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
// Add full URL path directly
purgePaths = append(purgePaths, path)
} else {
purgePath = fmt.Sprintf("%s/%s", purgeHost, path)
// Ensure each path has a leading slash but no double slashes
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
purgePaths = append(purgePaths, purgeHost+path)
}
purgePaths = append(purgePaths, purgePath)
}
return purgePaths
}
Expand Down Expand Up @@ -302,7 +298,7 @@ func (r *FrontendReconciliation) populateCacheBustContainer(j *batchv1.Job) erro
pathsToCacheBust := createCachePurgePathList(r.Frontend, r.FrontendEnvironment)

// Construct the akamai cache bust command
command := fmt.Sprintf("sleep 60; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete %s", strings.Join(pathsToCacheBust, " "))
command := fmt.Sprintf("sleep 120; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete %s", strings.Join(pathsToCacheBust, " "))

// Modify the obejct to set the things we care about
cacheBustContainer := v1.Container{
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/cachebust/01-create-resources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
akamaiCacheBustPaths:
- /config/chrome/fed-modules.json
- apps/chrome/index.html
- https://app.company.com
deploymentRepo: https://github.com/RedHatInsights/insights-chrome
envName: test-cachebust-environment
image: quay.io/cloudservices/insights-chrome-frontend:720317c
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/cachebust/02-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
command:
- /bin/bash
- '-c'
- 'sleep 60; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/config/chrome/fed-modules.json https://console.doesntexist.redhat.com/apps/chrome/index.html'
- 'sleep 120; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/config/chrome/fed-modules.json https://console.doesntexist.redhat.com/apps/chrome/index.html https://app.company.com'
resources: {}
volumeMounts:
- name: akamai-edgerc
Expand Down Expand Up @@ -148,7 +148,7 @@ spec:
command:
- /bin/bash
- '-c'
- 'sleep 60; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/apps/chrome-test-defaults/fed-mods.json'
- 'sleep 120; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/apps/chrome-test-defaults/fed-mods.json'
resources: {}
volumeMounts:
- name: akamai-edgerc
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/cachebust/04-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
command:
- /bin/bash
- '-c'
- 'sleep 60; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/config/chrome/fed-modules.json https://console.doesntexist.redhat.com/apps/chrome/index.html'
- 'sleep 120; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/config/chrome/fed-modules.json https://console.doesntexist.redhat.com/apps/chrome/index.html'
resources: {}
volumeMounts:
- name: akamai-edgerc
Expand Down Expand Up @@ -148,7 +148,7 @@ spec:
command:
- /bin/bash
- '-c'
- 'sleep 60; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/apps/chrome-test-defaults/fed-mods.json'
- 'sleep 120; /cli/.akamai-cli/src/cli-purge/bin/akamai-purge --edgerc /opt/app-root/edgerc delete https://console.doesntexist.redhat.com/apps/chrome-test-defaults/fed-mods.json'
resources: {}
volumeMounts:
- name: akamai-edgerc
Expand Down
Loading