Skip to content

Commit 404f6b4

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 e180993 commit 404f6b4

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

internal/apiserver/policyservice/policyimpl.go

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

210210
if request.DryRun {
211211
for _, d := range allDeployments {
212-
log.Debugf("deployment : %s", d.ObjectMeta.Name)
212+
log.Debugf("deployment: %s", d.ObjectMeta.Name)
213213
resp.Name = append(resp.Name, d.ObjectMeta.Name)
214214
}
215215
return resp
@@ -236,15 +236,15 @@ func ApplyPolicy(request *msgs.ApplyPolicyRequest, ns, pgouser string) msgs.Appl
236236

237237
cl, err := apiserver.Clientset.
238238
CrunchydataV1().Pgclusters(ns).
239-
Get(ctx, d.ObjectMeta.Labels[config.LABEL_SERVICE_NAME], metav1.GetOptions{})
239+
Get(ctx, d.ObjectMeta.Labels[config.LABEL_PG_CLUSTER], metav1.GetOptions{})
240240
if err != nil {
241241
resp.Status.Code = msgs.Error
242242
resp.Status.Msg = err.Error()
243243
return resp
244244
}
245245

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

internal/util/policy.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
// ExecPolicy execute a sql policy against a cluster
35-
func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace, policyName, serviceName, port string) error {
35+
func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace, policyName, clusterName, port string) error {
3636
ctx := context.TODO()
3737

3838
// fetch the policy sql
@@ -46,11 +46,10 @@ func ExecPolicy(clientset kubeapi.Interface, restconfig *rest.Config, namespace,
4646
stdin := strings.NewReader(sql)
4747

4848
// now, we need to ensure we can get the Pod name of the primary PostgreSQL
49-
// instance. Thname being passed in is actually the "serviceName" of the Pod
50-
// We can isolate the exact Pod we want by using this (LABEL_SERVICE_NAME) and
51-
// the LABEL_PGHA_ROLE labels
49+
// instance. We can isolate the exact Pod we want by using the
50+
// LABEL_PG_CLUSTER and LABEL_PGHA_ROLE labels
5251
selector := fmt.Sprintf("%s=%s,%s=%s",
53-
config.LABEL_SERVICE_NAME, serviceName,
52+
config.LABEL_PG_CLUSTER, clusterName,
5453
config.LABEL_PGHA_ROLE, config.LABEL_PGHA_ROLE_PRIMARY)
5554

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

0 commit comments

Comments
 (0)