diff --git a/docs/developer.md b/docs/developer.md index bc80d5380..40636d47a 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -72,22 +72,32 @@ make docker # kind make docker -kind load docker-image --name +kind load docker-image registry.opensource.zalan.do/acid/postgres-operator:${TAG} --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 diff --git a/pkg/cluster/k8sres.go b/pkg/cluster/k8sres.go index a42aa2d06..751606d93 100644 --- a/pkg/cluster/k8sres.go +++ b/pkg/cluster/k8sres.go @@ -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) } @@ -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) @@ -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{ diff --git a/pkg/cluster/util_test.go b/pkg/cluster/util_test.go index 20214a085..1463a5609 100644 --- a/pkg/cluster/util_test.go +++ b/pkg/cluster/util_test.go @@ -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) } } diff --git a/pkg/controller/postgresql.go b/pkg/controller/postgresql.go index b3c4d8414..590494412 100644 --- a/pkg/controller/postgresql.go +++ b/pkg/controller/postgresql.go @@ -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{}) { @@ -521,8 +519,6 @@ func (c *Controller) postgresqlUpdate(prev, cur interface{}) { } c.queueClusterEvent(pgOld, pgNew, EventUpdate) } - - return } func (c *Controller) postgresqlDelete(obj interface{}) { @@ -530,8 +526,6 @@ func (c *Controller) postgresqlDelete(obj interface{}) { if pg != nil { c.queueClusterEvent(pg, nil, EventDelete) } - - return } func (c *Controller) postgresqlCheck(obj interface{}) *acidv1.Postgresql {