Skip to content

Commit

Permalink
more updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-smart committed May 8, 2023
1 parent c7ff78c commit 18578dd
Show file tree
Hide file tree
Showing 7 changed files with 897 additions and 579 deletions.
5 changes: 4 additions & 1 deletion packages/core/src/internal/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ type TContentsMapResolved<M> = { [K in keyof M]: TExtractContentType<M[K]> };
/**
* Turn functions/promises etc. into the actual configuration.
*/
export function resolveContents<T>(context: any, contents: TContents<T>) {
export function resolveContents<T extends Record<string, any>>(
context: any,
contents: TContents<T>,
) {
if (typeof contents === "function") {
const fn = contents as TContentsFn<T>;
const retContents = fn(context);
Expand Down
4 changes: 2 additions & 2 deletions packages/k8s/src/hpa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
HorizontalPodAutoscaler,
MetricSpec,
MetricTarget,
} from "kubernetes-types/autoscaling/v2beta2";
} from "kubernetes-types/autoscaling/v2";
import * as R from "ramda";
import { DeepPartial } from "./common";
import { maybeMergeResource, resource } from "./resources";
Expand All @@ -16,7 +16,7 @@ export const hpa = (
): HorizontalPodAutoscaler =>
maybeMergeResource<HorizontalPodAutoscaler>(
resource<HorizontalPodAutoscaler>(
"autoscaling/v2beta2",
"autoscaling/v2",
"HorizontalPodAutoscaler",
name,
{ spec: { scaleTargetRef: targetRef, maxReplicas: 1 } },
Expand Down
54 changes: 27 additions & 27 deletions packages/k8s/src/podTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ export const viewPodPath = <R = unknown>(
* Returns the metadata labels for the given resource pod
* template.
*/
export const viewPodLabels: TResourceViewer<
NonNullable<ObjectMeta["labels"]>
> = F.flow(
viewPodPath(["metadata", "labels"]),
O.getOrElse<NonNullable<ObjectMeta["labels"]>>(() => ({})),
);
export const viewPodLabels: TResourceViewer<NonNullable<ObjectMeta["labels"]>> =
F.flow(
viewPodPath(["metadata", "labels"]),
O.getOrElse<NonNullable<ObjectMeta["labels"]>>(() => ({})),
);

/**
* Returns the metadata annotations for the given resource pod
Expand Down Expand Up @@ -100,16 +99,16 @@ export const viewPodPorts: TResourceViewer<ContainerPort[]> = F.flow(
* setEmptyContainers(cronjob)
* ```
*/
export const overPodTemplate = (
fn: (pod: PodTemplateSpec) => PodTemplateSpec,
): TResourceTransformer => (object) =>
F.pipe(
podTemplateLens(object),
O.fold(
() => object,
(lens) => R.over(lens, fn, object),
),
);
export const overPodTemplate =
(fn: (pod: PodTemplateSpec) => PodTemplateSpec): TResourceTransformer =>
(object) =>
F.pipe(
podTemplateLens(object),
O.fold(
() => object,
(lens) => R.over(lens, fn, object),
),
);

/**
* Returns a function that concats a list of containers to the given resource.
Expand Down Expand Up @@ -166,9 +165,10 @@ export const appendInitContainer = (container: Container) =>
/**
* Return a function that runs the transform function over the given path.
*/
export const overPodTemplatePath = <R>(path: string[]) => (
fn: (input: R) => R,
) => overPodTemplate(R.over(R.lensPath(path), fn));
export const overPodTemplatePath =
<R>(path: string[]) =>
(fn: (input: R) => R) =>
overPodTemplate(R.over(R.lensPath(path), fn));

/**
* Returns a function that runs the given containers transformer in a resource.
Expand All @@ -182,10 +182,10 @@ export const overContainers = (fn: (containers: Container[]) => Container[]) =>
* Returns a function that finds a container by name, and runs the transformer
* over it in a resource.
*/
export const overContainer = (name: string) => (
fn: (container: Container) => Container,
): TResourceTransformer =>
overContainers(R.map(R.when(R.propEq("name", name), fn)));
export const overContainer =
(name: string) =>
(fn: (container: Container) => Container): TResourceTransformer =>
overContainers(R.map(R.when(R.propEq("name", name), fn)));

/**
* Returns a function that finds the first container, and runs the transformer
Expand All @@ -209,9 +209,9 @@ export const overInitContainers = (
* Returns a function that finds an init container by name, and runs the
* transformer over it in a resource.
*/
export const overInitContainer = (name: string) => (
fn: (container: Container) => Container,
) => overInitContainers(R.map(R.when(R.propEq("name", name), fn)));
export const overInitContainer =
(name: string) => (fn: (container: Container) => Container) =>
overInitContainers(R.map(R.when(R.propEq("name", name), fn)));

/**
* Returns a function that finds the first init container, and runs the
Expand All @@ -231,7 +231,7 @@ export const appendVolume = (volume: Volume) =>

export type TContainerSelector = (
fn: (c: Container) => Container,
) => <R>(resource: R) => R;
) => TResourceTransformer;

/**
* Returns a function that adds a volume and mounts it to a container.
Expand Down
2 changes: 1 addition & 1 deletion packages/k8s/src/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as O from "fp-ts/Option";
import * as R from "ramda";
import { ObjectMeta } from "kubernetes-types/meta/v1";
import { DeepPartial } from "./common";
import { CrossVersionObjectReference } from "kubernetes-types/autoscaling/v2beta2";
import { CrossVersionObjectReference } from "kubernetes-types/autoscaling/v2";

export interface IResource {
apiVersion?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/k8s/test/hpa.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as K from "../src/index";
import { describe } from "mocha";
import { runCases } from "./helpers";
import { HorizontalPodAutoscaler } from "kubernetes-types/autoscaling/v2beta2";
import { HorizontalPodAutoscaler } from "kubernetes-types/autoscaling/v2";

describe("hpa", () =>
runCases([
Expand All @@ -27,7 +27,7 @@ describe("hpa", () =>
},
),
diff: {
apiVersion: "autoscaling/v2beta2",
apiVersion: "autoscaling/v2",
kind: "HorizontalPodAutoscaler",
metadata: {
name: "myhpa",
Expand Down
2 changes: 1 addition & 1 deletion packages/k8s/test/resources.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as K from "../src/index";
import { describe } from "mocha";
import { runCases } from "./helpers";
import { CrossVersionObjectReference } from "kubernetes-types/autoscaling/v2beta2";
import { CrossVersionObjectReference } from "kubernetes-types/autoscaling/v2";
import { Deployment } from "kubernetes-types/apps/v1";

describe("label", () =>
Expand Down
Loading

0 comments on commit 18578dd

Please sign in to comment.