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

Added Pull Zone features based on the Bunny CDN user interface. #8

Merged
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
71 changes: 69 additions & 2 deletions manifests/crds/PullZone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ spec:
openAPIV3Schema:
type: object
properties:
metadata:
type: object
properties:
name:
type: string
pattern: "^[a-z]([a-z0-9\\-]{0,61}[a-z0-9])?$"
spec:
type: object
x-kubernetes-validations:
- rule: "has(self.storageZoneRef) || has(self.originUrl)"
message: "Either storageZoneRef or originUrl needs to be set."
- rule: "! has(self.storageZoneRef) || ! has(self.originUrl)"
message: "storageZoneRef and originUrl cannot both be set."
properties:
originUrl:
type: string
Expand Down Expand Up @@ -54,6 +65,62 @@ spec:
type: string
pattern: "^(delete|retain)"
default: "retain"
enableSmartCache:
type: boolean
default: false
cacheExpirationTime:
type: integer
minimum: -1
default: -1
browserCacheExpirationTime:
type: integer
minimum: -1
default: -1
enableQueryStringSort:
type: boolean
default: true
cacheErrorResponses:
type: boolean
default: false
enableQueryStringVary:
type: boolean
default: false
queryStringVaryParameters:
type: array
items:
type: string
pattern: "^[A-Za-z0-9]+$"
default: []
enableWebpVary:
type: boolean
default: false
enableAvifVary:
type: boolean
default: false
enableMobileVary:
type: boolean
default: false
enableCountryCodeVary:
type: boolean
default: false
enableHostnameVary:
type: boolean
default: false
cookieVaryNames:
type: array
items:
type: string
pattern: "^[A-Za-z0-9]+$"
default: []
stripResponseCookies:
type: boolean
default: true
useStaleWhileOffline:
type: boolean
default: false
useStaleWhileUpdating:
type: boolean
default: false
status:
type: object
properties:
Expand All @@ -72,7 +139,7 @@ spec:
additionalPrinterColumns:
- name: Ready
type: boolean
jsonPath: .status.ready
jsonPath: .status.ready
- name: Message
type: string
jsonPath: .status.message
Expand All @@ -91,4 +158,4 @@ spec:
kind: PullZone
# shortNames allow shorter string to match your resource on the CLI
shortNames:
- "plz"
- "plz"
40 changes: 37 additions & 3 deletions src/managePullZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,29 @@ interface IPullZone {
OriginUrl: string;
StorageZoneId: number;
Hostnames: Array<IHostname>;
MonthlyBandwidthLimit: number;
MonthlyBandwidthLimit: number; // Sets the monthly limit of bandwidth in bytes that the pullzone is allowed to use
Type: 0 | 1; // The type of the pull zone. Premium = 0, Volume = 1
ErrorPageWhitelabel: boolean;
ZoneSecurityEnabled: boolean;
ErrorPageWhitelabel: boolean; // Determines if the error pages should be whitelabel or not
ZoneSecurityEnabled: boolean; // Determines if the zone token authentication security should be enabled
ZoneSecurityKey: string;
EnableCacheSlice: boolean; // Determines if cache slicing (Optimize for video) should be enabled for this zone
EnableSmartCache: boolean; // Dynamically selects if a request should be cached based on the file extension and MIME type to allow easy full-site acceleration. If the request is cacheable, the Cache Expiration Time setting will be applied.
CacheControlMaxAgeOverride: number; // Sets the cache control override setting for this zone
CacheControlBrowserMaxAgeOverride: number; // Sets the browser cache control override setting for this zone
EnableQueryStringOrdering: boolean; // Determines if the query string ordering should be enabled.
CacheErrorResponses: boolean; // Determines if the cache error responses should be enabled on the zone
IgnoreQueryStrings: boolean; // Determines if the Pull Zone should ignore query strings when serving cached objects (Vary by Query String)
QueryStringVaryParameters: string[]; // Contains the list of vary parameters that will be used for vary cache by query string. If empty, all parameters will be used to construct the key
EnableWebpVary: boolean; // Determines if the WebP Vary feature should be enabled.
EnableAvifVary: boolean; // Determines if the AVIF Vary feature should be enabled.
EnableMobileVary: boolean; // Determines if the Mobile Vary feature is enabled.
EnableCountryCodeVary: boolean; // Determines if the Country Code Vary feature should be enabled.
EnableHostnameVary: boolean; // Determines if the Hostname Vary feature should be enabled.
EnableCookieVary: boolean; // Determines if the Cookie Vary feature is enabled.
CookieVaryParameters: string[]; // Contains the list of vary parameters that will be used for vary cache by cookie string. If empty, cookie vary will not be used.
DisableCookies: boolean; // Determines if the Pull Zone should automatically remove cookies from the responses
UseStaleWhileOffline: boolean; // Determines if we should use stale cache while the origin is offline
UseStaleWhileUpdating: boolean; // Determines if we should use stale cache while cache is updating
}

const getPullZones = async (): Promise<Array<IPullZone>> => {
Expand Down Expand Up @@ -120,6 +137,23 @@ const getOrCreatePullZoneConfig = async (
ErrorPageWhitelabel: spec.errorPageWhiteLabel,
MonthlyBandwidthLimit: spec.monthlyBandwidthLimit,
ZoneSecurityEnabled: spec.zoneSecurityEnabled,
EnableSmartCache: spec.enableSmartCache,
CacheControlMaxAgeOverride: spec.cacheExpirationTime,
CacheControlBrowserMaxAgeOverride: spec.browserCacheExpirationTime,
EnableQueryStringOrdering: spec.enableQueryStringSort,
CacheErrorResponses: spec.cacheErrorResponses,
IgnoreQueryStrings: !spec.enableQueryStringVary,
QueryStringVaryParameters: spec.queryStringVaryParameters,
EnableWebpVary: spec.enableWebpVary,
EnableAvifVary: spec.enableAvifVary,
EnableMobileVary: spec.enableMobileVary,
EnableCountryCodeVary: spec.enableCountryCodeVary,
EnableHostnameVary: spec.enableHostnameVary,
EnableCookieVary: spec.cookieVaryNames.length > 0,
CookieVaryParameters: spec.cookieVaryNames,
DisableCookies: spec.stripResponseCookies,
UseStaleWhileOffline: spec.useStaleWhileOffline,
UseStaleWhileUpdating: spec.useStaleWhileUpdating,
};
return { createConfig, updateConfig };
};
Expand Down
20 changes: 18 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,28 @@ export interface PullZoneSpec {
name: string;
namespace?: string;
};
zoneType: "premium" | "volume"; // defaults to volume
zoneType: "premium" | "volume"; // defaults to 'volume'
zoneSecurityEnabled: boolean; // defaults to true
errorPageWhiteLabel: boolean; // defaults to true
enabledCacheSlice: boolean; // defaults to true
monthlyBandwidthLimit: number; // defaults to 0 a.k.a unlimited
deletionPolicy: "delete" | "retain";
deletionPolicy: "delete" | "retain"; // defaults to 'retain'
enableSmartCache: boolean; // defaults to false
cacheExpirationTime: number; // defaults to -1 (Respect Origin Cache-Control)
browserCacheExpirationTime: number; // defaults to -1 (Match Server Cache Expiration)
enableQueryStringSort: boolean; // defaults to true
cacheErrorResponses: boolean; // defaults to false
enableQueryStringVary: boolean; // defaults to false
queryStringVaryParameters: string[]; // defaults to []
enableWebpVary: boolean; // defaults to false
enableAvifVary: boolean; // defaults to false
enableMobileVary: boolean; // defaults to false
enableCountryCodeVary: boolean; // defaults to false
enableHostnameVary: boolean; // defaults to false
cookieVaryNames: string[]; // defaults to []
stripResponseCookies: boolean; // defaults to true
useStaleWhileOffline: boolean; // defaults to false
useStaleWhileUpdating: boolean; // defaults to false
}

export interface PullZoneStatus {
Expand Down
31 changes: 30 additions & 1 deletion test-cr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,36 @@ spec:
monthlyBandwidthLimit: 1000
---
apiVersion: bunny-cdn-operator.com/v1alpha1
kind: PullZone
metadata:
name: testing-url-pz
namespace: default
spec:
originUrl: https://acme.org.uk/
zoneType: premium
zoneSecurityEnabled: true
errorPageWhiteLabel: true
enabledCacheSlice: true
monthlyBandwidthLimit: 0
deletionPolicy: retain
enableSmartCache: false
cacheExpirationTime: -1
browserCacheExpirationTime: -1
enableQueryStringSort: true
cacheErrorResponses: false
enableQueryStringVary: false
queryStringVaryParameters: []
enableWebpVary: false
enableAvifVary: false
enableMobileVary: false
enableCountryCodeVary: false
enableHostnameVary: false
cookieVaryNames: []
stripResponseCookies: true
useStaleWhileOffline: false
useStaleWhileUpdating: false
---
apiVersion: bunny-cdn-operator.com/v1alpha1
kind: EdgeRule
metadata:
name: testing-edge-rule
Expand All @@ -38,4 +68,3 @@ spec:
description: testing operator rule
enabled: true
deletionPolicy: delete

Loading