Skip to content

Commit 141eb63

Browse files
jmckulkandrewlecuyer
authored andcommitted
Update label for policy
The policy logic uses the service name and role label to determine which pod is the primary and where to run SQL. This change uses the pg-cluster label instead of the service name label.
1 parent ee10409 commit 141eb63

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

internal/apiserver/policyservice/policyimpl.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func ApplyPolicy(request *msgs.ApplyPolicyRequest, ns, pgouser string) msgs.Appl
203203

204204
if request.DryRun {
205205
for _, d := range allDeployments {
206-
log.Debugf("deployment : %s", d.ObjectMeta.Name)
206+
log.Debugf("deployment: %s", d.ObjectMeta.Name)
207207
resp.Name = append(resp.Name, d.ObjectMeta.Name)
208208
}
209209
return resp
@@ -223,15 +223,15 @@ func ApplyPolicy(request *msgs.ApplyPolicyRequest, ns, pgouser string) msgs.Appl
223223

224224
cl, err := apiserver.Clientset.
225225
CrunchydataV1().Pgclusters(ns).
226-
Get(d.ObjectMeta.Labels[config.LABEL_SERVICE_NAME], metav1.GetOptions{})
226+
Get(d.ObjectMeta.Labels[config.LABEL_PG_CLUSTER], metav1.GetOptions{})
227227
if err != nil {
228228
resp.Status.Code = msgs.Error
229229
resp.Status.Msg = err.Error()
230230
return resp
231231
}
232232

233233
if err := util.ExecPolicy(apiserver.Clientset, apiserver.RESTConfig,
234-
ns, request.Name, d.ObjectMeta.Labels[config.LABEL_SERVICE_NAME], cl.Spec.Port); err != nil {
234+
ns, request.Name, d.ObjectMeta.Labels[config.LABEL_PG_CLUSTER], cl.Spec.Port); err != nil {
235235
log.Error(err)
236236
resp.Status.Code = msgs.Error
237237
resp.Status.Msg = err.Error()

internal/util/policy.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ import (
4040
)
4141

4242
// ExecPolicy execute a sql policy against a cluster
43-
func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace, policyName, serviceName, port string) error {
44-
//fetch the policy sql
43+
func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace, policyName, clusterName, port string) error {
44+
// fetch the policy sql
4545
sql, err := GetPolicySQL(clientset, namespace, policyName)
4646

4747
if err != nil {
@@ -53,11 +53,10 @@ func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace,
5353
stdin := strings.NewReader(sql)
5454

5555
// now, we need to ensure we can get the Pod name of the primary PostgreSQL
56-
// instance. Thname being passed in is actually the "serviceName" of the Pod
57-
// We can isolate the exact Pod we want by using this (LABEL_SERVICE_NAME) and
58-
// the LABEL_PGHA_ROLE labels
56+
// instance. We can isolate the exact Pod we want by using the
57+
// LABEL_PG_CLUSTER and LABEL_PGHA_ROLE labels
5958
selector := fmt.Sprintf("%s=%s,%s=%s",
60-
config.LABEL_SERVICE_NAME, serviceName,
59+
config.LABEL_PG_CLUSTER, clusterName,
6160
config.LABEL_PGHA_ROLE, config.LABEL_PGHA_ROLE_PRIMARY)
6261

6362
podList, err := clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{LabelSelector: selector})

0 commit comments

Comments
 (0)