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
Changes from 2 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
49 changes: 22 additions & 27 deletions controllers/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,28 @@ 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)
}

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

// 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)}
}

purgePaths := []string{}
// Loop through the frontend purge paths and append them to the purge host
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)
} else {
purgePath = fmt.Sprintf("%s/%s", purgeHost, path)
// 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://")), "/")

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

// If custom paths are provided, construct the purge paths list
if frontend.Spec.AkamaiCacheBustPaths != nil {
adamrdrew marked this conversation as resolved.
Show resolved Hide resolved
purgePaths = make([]string, 0, len(frontend.Spec.AkamaiCacheBustPaths))
for _, path := range frontend.Spec.AkamaiCacheBustPaths {
// 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 {
// 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 +297,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
Loading