Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions docs/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,32 @@ make docker

# kind
make docker
kind load docker-image <image> --name <kind-cluster-name>
kind load docker-image registry.opensource.zalan.do/acid/postgres-operator:${TAG} --name <kind-cluster-name>
```

Then create a new Postgres Operator deployment. You can reuse the provided
manifest but replace the version and tag. Don't forget to also apply
Then create a new Postgres Operator deployment.

### Deploying manually with manifests and kubectl

You can reuse the provided manifest but replace the version and tag. Don't forget to also apply
configuration and RBAC manifests first, e.g.:

```bash
kubectl create -f manifests/configmap.yaml
kubectl create -f manifests/operator-service-account-rbac.yaml
sed -e "s/\(image\:.*\:\).*$/\1$TAG/" manifests/postgres-operator.yaml | kubectl create -f -
sed -e "s/\(image\:.*\:\).*$/\1$TAG/" -e "s/\(imagePullPolicy\:\).*$/\1 Never/" manifests/postgres-operator.yaml | kubectl create -f -

# check if the operator is coming up
kubectl get pod -l name=postgres-operator
```

### Deploying with Helm chart

Yoy can reuse the provided Helm chart to deploy local operator build with the following command:
```bash
helm install postgres-operator ./charts/postgres-operator --namespace zalando-operator --set image.tag=${TAG} --set image.pullPolicy=Never
```

## Code generation

The operator employs K8s-provided code generation to obtain deep copy methods
Expand Down
19 changes: 7 additions & 12 deletions pkg/cluster/k8sres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
return nil, fmt.Errorf("could not generate pod template: %v", err)
}

if volumeClaimTemplate, err = generatePersistentVolumeClaimTemplate(spec.Volume.Size,
if volumeClaimTemplate, err = c.generatePersistentVolumeClaimTemplate(spec.Volume.Size,
spec.Volume.StorageClass, spec.Volume.Selector); err != nil {
return nil, fmt.Errorf("could not generate volume claim template: %v", err)
}
Expand Down Expand Up @@ -1540,21 +1540,12 @@ func (c *Cluster) addAdditionalVolumes(podSpec *v1.PodSpec,
podSpec.Volumes = volumes
}

func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string,
func (c *Cluster) generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string,
volumeSelector *metav1.LabelSelector) (*v1.PersistentVolumeClaim, error) {

var storageClassName *string

metadata := metav1.ObjectMeta{
Name: constants.DataVolumeName,
}
if volumeStorageClass != "" {
// TODO: remove the old annotation, switching completely to the StorageClassName field.
metadata.Annotations = map[string]string{"volume.beta.kubernetes.io/storage-class": volumeStorageClass}
storageClassName = &volumeStorageClass
} else {
metadata.Annotations = map[string]string{"volume.alpha.kubernetes.io/storage-class": "default"}
storageClassName = nil
}

quantity, err := resource.ParseQuantity(volumeSize)
Expand All @@ -1564,7 +1555,11 @@ func generatePersistentVolumeClaimTemplate(volumeSize, volumeStorageClass string

volumeMode := v1.PersistentVolumeFilesystem
volumeClaim := &v1.PersistentVolumeClaim{
ObjectMeta: metadata,
ObjectMeta: metav1.ObjectMeta{
Name: constants.DataVolumeName,
Annotations: c.annotationsSet(nil),
Labels: c.labelsSet(true),
},
Spec: v1.PersistentVolumeClaimSpec{
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Resources: v1.ResourceRequirements{
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func TestInheritedAnnotations(t *testing.T) {
t.Errorf("%s: pod template %v not inherited annotations %#v, got %#v", testName, sts.ObjectMeta.Name, inheritedAnnotations, sts.ObjectMeta.Annotations)
}
// pvc template
if util.MapContains(sts.Spec.VolumeClaimTemplates[0].Annotations, inheritedAnnotations) {
t.Errorf("%s: PVC template %v not expected to have inherited annotations %#v, got %#v", testName, sts.ObjectMeta.Name, inheritedAnnotations, sts.ObjectMeta.Annotations)
if !(util.MapContains(sts.Spec.VolumeClaimTemplates[0].Annotations, inheritedAnnotations)) {
t.Errorf("%s: PVC template %v not inherited annotations %#v, got %#v", testName, sts.ObjectMeta.Name, inheritedAnnotations, sts.ObjectMeta.Annotations)
}
}

Expand Down
6 changes: 0 additions & 6 deletions pkg/controller/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,6 @@ func (c *Controller) postgresqlAdd(obj interface{}) {
// We will not get multiple Add events for the same cluster
c.queueClusterEvent(nil, pg, EventAdd)
}

return
}

func (c *Controller) postgresqlUpdate(prev, cur interface{}) {
Expand All @@ -521,17 +519,13 @@ func (c *Controller) postgresqlUpdate(prev, cur interface{}) {
}
c.queueClusterEvent(pgOld, pgNew, EventUpdate)
}

return
}

func (c *Controller) postgresqlDelete(obj interface{}) {
pg := c.postgresqlCheck(obj)
if pg != nil {
c.queueClusterEvent(pg, nil, EventDelete)
}

return
}

func (c *Controller) postgresqlCheck(obj interface{}) *acidv1.Postgresql {
Expand Down