CreatePodEnvConfig returns the hash of pod env configuration
(cluster apiv1.Cluster, podName string)
| 124 | |
| 125 | // CreatePodEnvConfig returns the hash of pod env configuration |
| 126 | func CreatePodEnvConfig(cluster apiv1.Cluster, podName string) EnvConfig { |
| 127 | // When adding an environment variable here, remember to change the `IsReservedEnvironmentVariable` |
| 128 | // function in `pkg/postgres/environment.go` too. |
| 129 | config := EnvConfig{ |
| 130 | EnvVars: []corev1.EnvVar{ |
| 131 | { |
| 132 | Name: "PGDATA", |
| 133 | Value: PgDataPath, |
| 134 | }, |
| 135 | { |
| 136 | Name: "POD_NAME", |
| 137 | Value: podName, |
| 138 | }, |
| 139 | { |
| 140 | Name: "NAMESPACE", |
| 141 | Value: cluster.Namespace, |
| 142 | }, |
| 143 | { |
| 144 | Name: "CLUSTER_NAME", |
| 145 | Value: cluster.Name, |
| 146 | }, |
| 147 | { |
| 148 | Name: "PSQL_HISTORY", |
| 149 | Value: path.Join(postgres.TemporaryDirectory, ".psql_history"), |
| 150 | }, |
| 151 | { |
| 152 | Name: "PGPORT", |
| 153 | Value: strconv.Itoa(postgres.ServerPort), |
| 154 | }, |
| 155 | { |
| 156 | Name: "PGHOST", |
| 157 | Value: postgres.SocketDirectory, |
| 158 | }, |
| 159 | { |
| 160 | Name: "TMPDIR", |
| 161 | Value: postgres.TemporaryDirectory, |
| 162 | }, |
| 163 | }, |
| 164 | EnvFrom: cluster.Spec.EnvFrom, |
| 165 | } |
| 166 | config.EnvVars = append(config.EnvVars, cluster.Spec.Env...) |
| 167 | |
| 168 | if configuration.Current.StandbyTCPUserTimeout != nil { |
| 169 | config.EnvVars = append( |
| 170 | config.EnvVars, |
| 171 | corev1.EnvVar{ |
| 172 | Name: "CNPG_STANDBY_TCP_USER_TIMEOUT", |
| 173 | Value: strconv.Itoa(*configuration.Current.StandbyTCPUserTimeout), |
| 174 | }, |
| 175 | ) |
| 176 | } |
| 177 | |
| 178 | hashValue, _ := hash.ComputeHash(config) |
| 179 | config.Hash = hashValue |
| 180 | return config |
| 181 | } |
| 182 | |
| 183 | // createClusterPodSpec computes the PodSpec corresponding to a cluster |
no test coverage detected