volume.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import * as k8s from '@pulumi/kubernetes'
  2. import * as pulumi from '@pulumi/pulumi'
  3. /**
  4. * This is an abstraction that uses a class to fold together the common pattern of a
  5. * Kubernetes Deployment and its associated Service object.
  6. * This class creates a Persistent Volume
  7. */
  8. export class CustomPersistentVolume extends pulumi.ComponentResource {
  9. public readonly pvc: k8s.core.v1.PersistentVolumeClaim
  10. constructor(name: string, args: ServiceDeploymentArgs, opts?: pulumi.ComponentResourceOptions) {
  11. super('volume:service:CustomPersistentVolume', name, {}, opts)
  12. const volumeLabels = { app: name }
  13. const pvcName = `${name}-pvc`
  14. this.pvc = new k8s.core.v1.PersistentVolumeClaim(
  15. pvcName,
  16. {
  17. metadata: {
  18. labels: volumeLabels,
  19. namespace: args.namespaceName,
  20. name: pvcName,
  21. },
  22. spec: {
  23. accessModes: ['ReadWriteOnce'],
  24. resources: {
  25. requests: {
  26. storage: `${args.storage}Gi`,
  27. },
  28. },
  29. },
  30. },
  31. { parent: this }
  32. )
  33. }
  34. }
  35. export interface ServiceDeploymentArgs {
  36. namespaceName: pulumi.Output<string>
  37. storage: Number
  38. }