Skip to content

Commit

Permalink
feat(cdk8s): storageClassName injection (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh authored Jul 1, 2024
1 parent 60c7d23 commit 5f92ed5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/chainfile-cdk8s/src/chart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface CFChartProps {

spec: {
replicas?: number;
storageClassName?: string;

/**
* Ports to expose on the service.
Expand Down Expand Up @@ -81,6 +82,11 @@ export class CFChart extends Chart {
selector: {
matchLabels: labels,
},
volumeClaimTemplates: {
spec: {
storageClassName: props.spec.storageClassName,
},
},
},
});
}
Expand Down
8 changes: 8 additions & 0 deletions packages/chainfile-cdk8s/src/sts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ export interface CFStatefulSetProps {
readonly template?: Omit<PodTemplateSpec, 'spec'> & {
readonly spec?: Omit<PodSpec, 'hostAliases' | 'volumes' | 'containers'>;
};
readonly volumeClaimTemplates?: {
readonly metadata?: Omit<ObjectMeta, 'name'>;
readonly spec?: {
readonly storageClassName?: string;
};
};
};
}

Expand Down Expand Up @@ -72,9 +78,11 @@ export class CFStatefulSet extends KubeStatefulSet {
.map(([volumeName, volume]) => {
return {
metadata: {
...props.spec.volumeClaimTemplates?.metadata,
name: Names.toDnsLabel(scope, { extra: ['pvc', volumeName] }),
},
spec: CFPersistentVolumeClaimSpec({
storageClassName: props.spec.volumeClaimTemplates?.spec?.storageClassName,
volume: volume,
}),
};
Expand Down
6 changes: 5 additions & 1 deletion packages/chainfile-cdk8s/src/volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export function CFEphemeralVolume(props: { name: string; volume: schema.Volume }
};
}

export function CFPersistentVolumeClaimSpec(props: { volume: schema.Volume }): PersistentVolumeClaimSpec {
export function CFPersistentVolumeClaimSpec(props: {
storageClassName?: string;
volume: schema.Volume;
}): PersistentVolumeClaimSpec {
return {
accessModes: ['ReadWriteOnce'],
storageClassName: props.storageClassName,
resources: {
requests: {
storage: calculateStorage(props.volume, {
Expand Down

0 comments on commit 5f92ed5

Please sign in to comment.