Skip to content

Commit 0d77108

Browse files
author
Jeff McCormick
committed
minor tweaks
1 parent b5c1e1f commit 0d77108

File tree

9 files changed

+82
-49
lines changed

9 files changed

+82
-49
lines changed

centos7/Dockerfile.postgres-operator.centos7

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM centos:7
22

3-
LABEL Release="1.3.2" Vendor="Crunchy Data Solutions"
3+
LABEL Release="1.4" Vendor="Crunchy Data Solutions"
44

55
ENV PGVERSION="9.6" PGDG_REPO="pgdg-centos96-9.6-3.noarch.rpm"
66

client/cmd/apply.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
)
2222

2323
var Selector string
24+
var DryRun bool
2425

2526
var applyCmd = &cobra.Command{
2627
Use: "apply",
@@ -30,6 +31,7 @@ For example:
3031
3132
pgo apply mypolicy1 --selector=name=mycluster
3233
pgo apply mypolicy1 --selector=someotherpolicy
34+
pgo apply mypolicy1 --selector=someotherpolicy --dry-run
3335
.`,
3436
Run: func(cmd *cobra.Command, args []string) {
3537
log.Debug("apply called")
@@ -49,5 +51,6 @@ func init() {
4951
RootCmd.AddCommand(applyCmd)
5052

5153
applyCmd.Flags().StringVarP(&Selector, "selector", "s", "", "The selector to use for cluster filtering ")
54+
applyCmd.Flags().BoolVarP(&DryRun, "dry-run", "d", false, "--dry-run shows clusters that policy would be applied to but does not actually apply them")
5255

5356
}

client/cmd/clone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func createClone(clusterName string) {
107107
log.Error(err.Error())
108108
return
109109
}
110-
fmt.Println("created PgClone " + clusterName)
110+
fmt.Println("cloned " + clusterName + " as " + CloneName)
111111

112112
}
113113

client/cmd/policy.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ func applyPolicy(policies []string) {
254254
return
255255
}
256256

257+
if DryRun {
258+
fmt.Println("policy would be applied to the following clusters:")
259+
for _, d := range deployments.Items {
260+
fmt.Println("deployment : " + d.ObjectMeta.Name)
261+
}
262+
return
263+
}
264+
257265
var newInstance *tpr.PgPolicylog
258266
for _, d := range deployments.Items {
259267
fmt.Println("deployment : " + d.ObjectMeta.Name)
@@ -263,6 +271,23 @@ func applyPolicy(policies []string) {
263271
newInstance, err = getPolicylog(p, d.ObjectMeta.Name)
264272

265273
result := tpr.PgPolicylog{}
274+
err = Tprclient.Get().
275+
Resource(tpr.POLICY_LOG_RESOURCE).
276+
Namespace(Namespace).
277+
Name(newInstance.Metadata.Name).
278+
Do().Into(&result)
279+
if err == nil {
280+
fmt.Println(p + " already applied to " + d.ObjectMeta.Name)
281+
break
282+
} else {
283+
if kerrors.IsNotFound(err) {
284+
} else {
285+
log.Error(err)
286+
break
287+
}
288+
}
289+
290+
result = tpr.PgPolicylog{}
266291
err = Tprclient.Post().
267292
Resource(tpr.POLICY_LOG_RESOURCE).
268293
Namespace(Namespace).

docs/build.asciidoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ A simple *smoke test* of the postgres operator includes testing
287287
the following:
288288

289289
* create a cluster (*pgo create cluster testcluster*)
290+
* scale a cluster (*pgo scale testcluster --replica-count=1*)
290291
* show a cluster (*pgo show cluster testcluster*)
291292
* show all clusters (*pgo show cluster all*)
292293
* backup a cluster (*pgo backup testcluster*)
@@ -299,6 +300,9 @@ the following:
299300
* clone a cluster (*pgo clone testcluster --name=cloneexample*)
300301
* delete a cluster (*pgo delete cluster testcluster*)
301302
* create a policy from local file (*pgo create policy policy1 --in-file=./examples/policy/policy1.sql*)
302-
* create a policy from git repo (*pgo create policy gitpolicy --repo=https://github.com/CrunchyData/postgres-operator/blob/master/examples/policy/gitpolicy.sql*)
303+
* create a policy from git repo (*pgo create policy gitpolicy --url=https://github.com/CrunchyData/postgres-operator/blob/master/examples/policy/gitpolicy.sql*)
304+
* repeat testing using emptydir storage type
305+
* repeat testing using create storage type
306+
* repeat testing using existing storage type
303307

304308
More detailed explanations of the commands can be found in the link:user-guide.asciidoc[User Guide].

examples/.pgo.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ REPLICA_STORAGE:
2525
STORAGE_TYPE: emptydir
2626
PGO:
2727
LSPVC_TEMPLATE: /home/jeffmc/.pgo.lspvc-template.json
28-
CO_IMAGE_TAG: centos7-1.3.2
28+
CO_IMAGE_TAG: centos7-1.4
2929
DEBUG: false

operator/cluster/clone.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ func addClone(clientset *kubernetes.Clientset, tprclient *rest.RESTClient, clone
128128

129129
func CompleteClone(config *rest.Config, clientset *kubernetes.Clientset, client *rest.RESTClient, stopchan chan struct{}, namespace string) {
130130

131+
log.Debug("setting up clone Deployment watch")
132+
131133
lo := v1.ListOptions{LabelSelector: "clone"}
132134
fw, err := clientset.Extensions().Deployments(namespace).Watch(lo)
133135
if err != nil {

operator/cluster/cluster.go

Lines changed: 30 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -137,34 +137,6 @@ func addCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl *tp
137137
return
138138
}
139139

140-
//create the PVC for the master if required
141-
//var pvcName string
142-
/**
143-
144-
switch cl.Spec.MasterStorage.StorageType {
145-
case "":
146-
log.Debug("MasterStorage.StorageType is empty")
147-
case "emptydir":
148-
log.Debug("MasterStorage.StorageType is emptydir")
149-
case "existing":
150-
log.Debug("MasterStorage.StorageType is existing")
151-
pvcName = cl.Spec.MasterStorage.PvcName
152-
case "create":
153-
log.Debug("MasterStorage.StorageType is create")
154-
pvcName = cl.Spec.Name + "-pvc"
155-
log.Debug("PVC_NAME=%s PVC_SIZE=%s PVC_ACCESS_MODE=%s\n",
156-
pvcName, cl.Spec.MasterStorage.PvcAccessMode, cl.Spec.MasterStorage.PvcSize)
157-
err = pvc.Create(clientset, pvcName, cl.Spec.MasterStorage.PvcAccessMode, cl.Spec.MasterStorage.PvcSize, cl.Spec.MasterStorage.StorageType, cl.Spec.MasterStorage.StorageClass, namespace)
158-
if err != nil {
159-
log.Error("error in pvc create " + err.Error())
160-
return
161-
}
162-
log.Info("created PVC =" + pvcName + " in namespace " + namespace)
163-
case "dynamic":
164-
log.Debug("MasterStorage.StorageType is dynamic, not supported yet")
165-
}
166-
*/
167-
168140
pvcName, err := createPVC(clientset, cl.Spec.Name, &cl.Spec.MasterStorage, namespace)
169141
log.Debug("created master pvc [" + pvcName + "]")
170142

@@ -300,7 +272,7 @@ func AddUpgrade(clientset *kubernetes.Clientset, client *rest.RESTClient, upgrad
300272

301273
func updateCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl *tpr.PgCluster, oldcluster *tpr.PgCluster, namespace string) {
302274

303-
log.Debug("updateCluster on pgcluster called..something changed")
275+
//log.Debug("updateCluster on pgcluster called..something changed")
304276

305277
if oldcluster.Spec.REPLICAS != cl.Spec.REPLICAS {
306278
log.Debug("detected change to REPLICAS for " + cl.Spec.Name + " from " + oldcluster.Spec.REPLICAS + " to " + cl.Spec.REPLICAS)
@@ -320,15 +292,29 @@ func updateCluster(clientset *kubernetes.Clientset, client *rest.RESTClient, cl
320292
}
321293
newReps := newCount - oldCount
322294
if newReps > 0 {
323-
ScaleReplicas(clientset, cl, newReps, namespace)
295+
serviceName := cl.Spec.Name + "-replica"
296+
ScaleReplicas(serviceName, clientset, cl, newReps, namespace)
324297
} else {
325298
log.Error("scale to the same number does nothing")
326299
}
327300
}
328301

329302
}
330303

331-
func ScaleReplicas(clientset *kubernetes.Clientset, cl *tpr.PgCluster, newReplicas int, namespace string) {
304+
func ScaleReplicas(serviceName string, clientset *kubernetes.Clientset, cl *tpr.PgCluster, newReplicas int, namespace string) {
305+
306+
//create the service if it doesn't exist
307+
serviceFields := ServiceTemplateFields{
308+
Name: serviceName,
309+
ClusterName: cl.Spec.Name,
310+
Port: cl.Spec.Port,
311+
}
312+
313+
err := CreateService(clientset, &serviceFields, namespace)
314+
if err != nil {
315+
log.Error(err)
316+
return
317+
}
332318

333319
//get the strategy to use
334320
if cl.Spec.STRATEGY == "" {
@@ -357,19 +343,19 @@ func ScaleReplicas(clientset *kubernetes.Clientset, cl *tpr.PgCluster, newReplic
357343
log.Error(err)
358344
return
359345
}
360-
//create a Deployment and its service
361-
serviceName := depName + "-replica"
362-
replicaServiceFields := ServiceTemplateFields{
363-
Name: serviceName,
364-
ClusterName: cl.Spec.Name,
365-
Port: cl.Spec.Port,
366-
}
367-
368-
err = CreateService(clientset, &replicaServiceFields, namespace)
369-
if err != nil {
370-
log.Error(err)
371-
return
372-
}
346+
//create a Deployment
347+
//serviceName := depName + "-replica"
348+
//replicaServiceFields := ServiceTemplateFields{
349+
//Name: serviceName,
350+
//ClusterName: cl.Spec.Name,
351+
//Port: cl.Spec.Port,
352+
//}
353+
354+
//err = CreateService(clientset, &replicaServiceFields, namespace)
355+
//if err != nil {
356+
//log.Error(err)
357+
//return
358+
//}
373359
strategy.CreateReplica(serviceName, clientset, cl, depName, pvcName, namespace, false)
374360
}
375361
}

operator/cluster/cluster_strategy_1.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,20 @@ func (r ClusterStrategy1) AddCluster(clientset *kubernetes.Clientset, client *re
123123
if err != nil {
124124
log.Error("could not convert REPLICAS config setting")
125125
} else {
126-
ScaleReplicas(clientset, cl, newReplicas, namespace)
126+
//create the replica service
127+
serviceName := cl.Spec.Name + "-replica"
128+
repserviceFields := ServiceTemplateFields{
129+
Name: serviceName,
130+
ClusterName: cl.Spec.Name,
131+
Port: cl.Spec.Port,
132+
}
133+
134+
err = CreateService(clientset, &repserviceFields, namespace)
135+
if err != nil {
136+
log.Error("error in creating replica service " + err.Error())
137+
return err
138+
}
139+
ScaleReplicas(serviceName, clientset, cl, newReplicas, namespace)
127140
}
128141

129142
return err

0 commit comments

Comments
 (0)