validator.ts 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import * as k8s from '@pulumi/kubernetes'
  2. import * as k8stypes from '@pulumi/kubernetes/types/input'
  3. import * as pulumi from '@pulumi/pulumi'
  4. /**
  5. * ValidatorServiceDeployment is an example abstraction that uses a class to fold together the common pattern of a
  6. * Kubernetes Deployment and its associated Service object.
  7. */
  8. export class ValidatorServiceDeployment extends pulumi.ComponentResource {
  9. public readonly deployment: k8s.apps.v1.Deployment
  10. public readonly service: k8s.core.v1.Service
  11. public readonly ipAddress?: pulumi.Output<string>
  12. constructor(name: string, args: ServiceDeploymentArgs, opts?: pulumi.ComponentResourceOptions) {
  13. super('k8sjs:service:ValidatorServiceDeployment', name, {}, opts)
  14. const labels = { app: name }
  15. const container: k8stypes.core.v1.Container = {
  16. name: `joystream-node-${args.index}`,
  17. image: args.nodeImage,
  18. args: [
  19. '--chain',
  20. args.chainSpecPath,
  21. '--pruning',
  22. 'archive',
  23. '--node-key-file',
  24. `${args.dataPath}/privatekey${args.index}`,
  25. '--keystore-path',
  26. `${args.dataPath}/data/auth-${args.index - 1}`,
  27. '--validator',
  28. '--log',
  29. 'runtime,txpool,transaction-pool,trace=sync',
  30. ],
  31. volumeMounts: [
  32. {
  33. name: 'config-data',
  34. mountPath: args.dataPath,
  35. },
  36. ],
  37. }
  38. this.deployment = new k8s.apps.v1.Deployment(
  39. name,
  40. {
  41. metadata: {
  42. namespace: args.namespace,
  43. labels: labels,
  44. },
  45. spec: {
  46. selector: { matchLabels: labels },
  47. replicas: 1,
  48. template: {
  49. metadata: { labels: labels },
  50. spec: {
  51. containers: [container],
  52. volumes: [
  53. {
  54. name: 'config-data',
  55. persistentVolumeClaim: {
  56. claimName: args.pvc,
  57. },
  58. },
  59. ],
  60. },
  61. },
  62. },
  63. },
  64. { parent: this }
  65. )
  66. this.service = new k8s.core.v1.Service(
  67. name,
  68. {
  69. metadata: {
  70. name: name,
  71. namespace: args.namespace,
  72. labels: this.deployment.metadata.labels,
  73. },
  74. spec: {
  75. ports: [{ name: 'port-1', port: 30333 }],
  76. selector: this.deployment.spec.template.metadata.labels,
  77. },
  78. },
  79. { parent: this }
  80. )
  81. }
  82. }
  83. export interface ServiceDeploymentArgs {
  84. namespace: pulumi.Output<string>
  85. index: number
  86. chainSpecPath: string
  87. dataPath: string
  88. nodeImage: string
  89. pvc: pulumi.OutputInstance<any>
  90. }