pod populates a PodSpec with the container and volumes needed to run pgAdmin.
( inPGAdmin *v1beta1.PGAdmin, inConfigMap *corev1.ConfigMap, outPod *corev1.PodSpec, pgAdminVolume *corev1.PersistentVolumeClaim, )
| 46 | |
| 47 | // pod populates a PodSpec with the container and volumes needed to run pgAdmin. |
| 48 | func pod( |
| 49 | inPGAdmin *v1beta1.PGAdmin, |
| 50 | inConfigMap *corev1.ConfigMap, |
| 51 | outPod *corev1.PodSpec, |
| 52 | pgAdminVolume *corev1.PersistentVolumeClaim, |
| 53 | ) { |
| 54 | // create the projected volume of config maps for use in |
| 55 | // 1. dynamic server discovery |
| 56 | // 2. adding the config variables during pgAdmin startup |
| 57 | configVolume := corev1.Volume{Name: "pgadmin-config"} |
| 58 | configVolume.VolumeSource = corev1.VolumeSource{ |
| 59 | Projected: &corev1.ProjectedVolumeSource{ |
| 60 | Sources: podConfigFiles(inConfigMap, *inPGAdmin), |
| 61 | }, |
| 62 | } |
| 63 | |
| 64 | // create the data volume for the persistent database |
| 65 | dataVolume := corev1.Volume{Name: "pgadmin-data"} |
| 66 | dataVolume.VolumeSource = corev1.VolumeSource{ |
| 67 | PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ |
| 68 | ClaimName: pgAdminVolume.Name, |
| 69 | ReadOnly: false, |
| 70 | }, |
| 71 | } |
| 72 | |
| 73 | // Volume used to write a custom config_system.py file in the initContainer |
| 74 | // which then loads the configs found in the `configVolume` |
| 75 | scriptVolume := corev1.Volume{Name: "pgadmin-config-system"} |
| 76 | scriptVolume.VolumeSource = corev1.VolumeSource{ |
| 77 | EmptyDir: &corev1.EmptyDirVolumeSource{ |
| 78 | Medium: corev1.StorageMediumMemory, |
| 79 | |
| 80 | // When this volume is too small, the Pod will be evicted and recreated |
| 81 | // by the StatefulSet controller. |
| 82 | // - https://kubernetes.io/docs/concepts/storage/volumes/#emptydir |
| 83 | // NOTE: tmpfs blocks are PAGE_SIZE, usually 4KiB, and size rounds up. |
| 84 | SizeLimit: resource.NewQuantity(32<<10, resource.BinarySI), |
| 85 | }, |
| 86 | } |
| 87 | |
| 88 | // pgadmin container |
| 89 | container := corev1.Container{ |
| 90 | Name: naming.ContainerPGAdmin, |
| 91 | Command: startupScript(inPGAdmin), |
| 92 | Image: config.StandalonePGAdminContainerImage(inPGAdmin), |
| 93 | ImagePullPolicy: inPGAdmin.Spec.ImagePullPolicy, |
| 94 | Resources: inPGAdmin.Spec.Resources, |
| 95 | SecurityContext: initialize.RestrictedSecurityContext(), |
| 96 | Ports: []corev1.ContainerPort{{ |
| 97 | Name: naming.PortPGAdmin, |
| 98 | ContainerPort: int32(pgAdminPort), |
| 99 | Protocol: corev1.ProtocolTCP, |
| 100 | }}, |
| 101 | Env: []corev1.EnvVar{ |
| 102 | { |
| 103 | Name: "PGADMIN_SETUP_EMAIL", |
| 104 | Value: fmt.Sprintf("admin@%s.%s.svc", inPGAdmin.Name, inPGAdmin.Namespace), |
| 105 | }, |