Skip to content

Commit 83df763

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 9c2e4c8 commit 83df763

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
@@ -208,7 +208,7 @@ func ApplyPolicy(request *msgs.ApplyPolicyRequest, ns, pgouser string) msgs.Appl
208208

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

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

245245
if err := util.ExecPolicy(apiserver.Clientset, apiserver.RESTConfig,
246-
ns, request.Name, d.ObjectMeta.Labels[config.LABEL_SERVICE_NAME], cl.Spec.Port); err != nil {
246+
ns, request.Name, d.ObjectMeta.Labels[config.LABEL_PG_CLUSTER], cl.Spec.Port); err != nil {
247247
log.Error(err)
248248
resp.Status.Code = msgs.Error
249249
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)