Skip to content

Commit

Permalink
feat: default to PullZone namespace if storageZoneRef does not provid…
Browse files Browse the repository at this point in the history
…e namespace
  • Loading branch information
paulrostorp committed Feb 1, 2022
1 parent a598283 commit 371187c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion manifests/crds/PullZone.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ spec:
type: string
required:
- "name"
- "namespace"
zoneType:
type: string
pattern: "^(premium|volume)"
Expand Down
19 changes: 10 additions & 9 deletions src/managePullZone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios, { AxiosResponse } from "axios";
import { logger } from "./logger";
import { getStorageZoneCrStatusId } from "./manageStorageZone";
import { bunnyAPIHeaders } from "./operator";
import { PullZone, PullZoneSpec } from "./types";
import { PullZone } from "./types";
import { backOff } from "exponential-backoff";
import { StorageZoneNotReadyError } from "./utils/misc";
import { createK8Secret } from "./utils/k8Secret";
Expand Down Expand Up @@ -61,11 +61,12 @@ const getOrCreatePullZone = async (config: ICreatePullZoneProps): Promise<IPullZ
};

const getOriginConfig = async (
spec: PullZoneSpec,
object: PullZone,
customObjectsAPIClient: CustomObjectsApi
): Promise<{ StorageZoneId: number } | { OriginUrl: string }> => {
const { spec, metadata } = object;
if (spec.storageZoneRef) {
const { name, namespace } = spec.storageZoneRef;
const { name, namespace = metadata.namespace } = spec.storageZoneRef;

const id = await backOff(() => getStorageZoneCrStatusId(name, namespace, customObjectsAPIClient), {
retry: (e, attempt) => {
Expand Down Expand Up @@ -100,13 +101,13 @@ const updatePullZone = async (id: number, config: IUpdatePullZoneProps): Promise
};

const getOrCreatePullZoneConfig = async (
name: string,
spec: PullZoneSpec,
object: PullZone,
customObjectsAPIClient: CustomObjectsApi
): Promise<{ createConfig: ICreatePullZoneProps; updateConfig: IUpdatePullZoneProps }> => {
const originConfig = await getOriginConfig(spec, customObjectsAPIClient);
const { spec, metadata } = object;
const originConfig = await getOriginConfig(object, customObjectsAPIClient);
const createConfig: ICreatePullZoneProps = {
Name: name,
Name: metadata.name,
Type: spec.zoneType.trim() == "premium" ? 0 : 1,
...originConfig,
};
Expand All @@ -131,8 +132,8 @@ export const handlePullZoneModification = async (
k8sApiClient: CoreV1Api
): Promise<IPullZoneCreationStatus> => {
try {
const { metadata, spec } = object;
const { createConfig, updateConfig } = await getOrCreatePullZoneConfig(metadata.name, spec, customObjectsAPIClient);
const { metadata } = object;
const { createConfig, updateConfig } = await getOrCreatePullZoneConfig(object, customObjectsAPIClient);
const { Id } = await getOrCreatePullZone(createConfig);
const zone = await updatePullZone(Id, updateConfig);
await createK8Secret(
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export interface PullZoneSpec {
storageZoneId?: number;
storageZoneRef?: {
name: string;
namespace: string;
namespace?: string;
};
zoneType: "premium" | "volume"; // defaults to volume
zoneSecurityEnabled: boolean; // defaults to true
Expand Down

0 comments on commit 371187c

Please sign in to comment.