Hi, I'm trying to use postgres-operator inside my own. Simple configuration with minimal cluster spec looks like:
apiVersion: project.project.com/v1
kind: CustomCRD
metadata:
name: project-sample
spec:
postgres:
teamId: "acid"
volume:
size: 1Gi
numberOfInstances: 2
users:
zalando: # database owner
- superuser
- createdb
foo_user: [] # role for application foo
databases:
foo: zalando # dbname: owner
preparedDatabases:
bar: {}
postgresql:
version: "12"
How cluster is created:
import (
v1 "github.com/zalando/postgres-operator/pkg/apis/acid.zalan.do/v1"
...
)
// Reconcilation func:
...
// Define a new pg cluster
dep, err := r.createCluster(name, project)
if err != nil {
log.Error(err, "Could not generate pg struct")
return ctrl.Result{}, err
}
log.Info("Creating a new PG Cluster")
err = r.Create(ctx, dep)
if err != nil {
log.Error(err, "Failed to create new PG Cluster")
return ctrl.Result{}, err
}
...
// createCluster returns a Postgresql object
func (r *CustomCRDReconciler) createCluster(name string, m *projectv1.CustomCRD) (*v1.Postgresql, error) {
postgresql := &v1.Postgresql{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: m.Namespace,
},
Spec: m.Spec.Postgres,
}
err := ctrl.SetControllerReference(m, postgresql, r.Scheme)
if err != nil {
return nil, err
}
return postgresql, nil
}
What I see in logs:
2020-08-28T10:19:10.487Z ERROR controller Reconciler error {"reconcilerGroup": "project.project.com", "reconcilerKind": "CustomCRD", "controller": "CustomCRD", "name": "CustomCRD-sample", "namespace": "default", "error": "postgresql.acid.zalan.do \"acid-CustomCRD-sample\" is invalid: [spec.postgresql.parameters: Invalid value: \"null\": spec.postgresql.parameters in body must be of type object: \"null\", spec.resources.limits.memory: Invalid value: \"\": spec.resources.limits.memory in body should match '^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$', spec.resources.limits.cpu: Invalid value: \"\": spec.resources.limits.cpu in body should match '^(\\d+m|\\d+(\\.\\d{1,3})?)$', spec.resources.requests.cpu: Invalid value: \"\": spec.resources.requests.cpu in body should match '^(\\d+m|\\d+(\\.\\d{1,3})?)$', spec.resources.requests.memory: Invalid value: \"\": spec.resources.requests.memory in body should match '^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$', spec.clone.cluster: Required value, spec.serviceAnnotations: Invalid value: \"null\": spec.serviceAnnotations in body must be of type object: \"null\", spec.patroni.slots: Invalid value: \"null\": spec.patroni.slots in body must be of type object: \"null\", spec.patroni.pg_hba: Invalid value: \"null\": spec.patroni.pg_hba in body must be of type array: \"null\", spec.patroni.initdb: Invalid value: \"null\": spec.patroni.initdb in body must be of type object: \"null\", spec.podAnnotations: Invalid value: \"null\": spec.podAnnotations in body must be of type object: \"null\", spec.tls: Invalid value: \"null\": spec.tls in body must be of type object: \"null\", spec.standby: Invalid value: \"null\": spec.standby in body must be of type object: \"null\"]"}
@telepenin did you apply the crds as part of the install?
So if using Helm you also need to apply these.
https://github.com/zalando/postgres-operator/tree/master/charts/postgres-operator/crds
Also what do the logs say when the operator starts?
@redscaresu I've applied -- https://github.com/zalando/postgres-operator/blob/master/manifests/postgresql.crd.yaml, but recreated with your way. The same issue:
2020-08-28T11:23:01.192Z ERROR controller Reconciler error {"reconcilerGroup": "project.project.com", "reconcilerKind": "CustomCRD", "controller": "CustomCRD", "name": "CustomCRD-sample", "namespace": "default", "error": "postgresql.acid.zalan.do \"acid-CustomCRD-sample\" is invalid: [spec.standby: Invalid value: \"null\": spec.standby in body must be of type object: \"null\", spec.postgresql.parameters: Invalid value: \"null\": spec.postgresql.parameters in body must be of type object: \"null\", spec.clone.cluster: Required value, spec.podAnnotations: Invalid value: \"null\": spec.podAnnotations in body must be of type object: \"null\", spec.serviceAnnotations: Invalid value: \"null\": spec.serviceAnnotations in body must be of type object: \"null\", spec.resources.limits.cpu: Invalid value: \"\": spec.resources.limits.cpu in body should match '^(\\d+m|\\d+(\\.\\d{1,3})?)$', spec.resources.limits.memory: Invalid value: \"\": spec.resources.limits.memory in body should match '^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$', spec.resources.requests.cpu: Invalid value: \"\": spec.resources.requests.cpu in body should match '^(\\d+m|\\d+(\\.\\d{1,3})?)$', spec.resources.requests.memory: Invalid value: \"\": spec.resources.requests.memory in body should match '^(\\d+(e\\d+)?|\\d+(\\.\\d+)?(e\\d+)?[EPTGMK]i?)$', spec.tls: Invalid value: \"null\": spec.tls in body must be of type object: \"null\", spec.patroni.pg_hba: Invalid value: \"null\": spec.patroni.pg_hba in body must be of type array: \"null\", spec.patroni.initdb: Invalid value: \"null\": spec.patroni.initdb in body must be of type object: \"null\", spec.patroni.slots: Invalid value: \"null\": spec.patroni.slots in body must be of type object: \"null\"]"}
Postgres operators's logs - https://bpa.st/UE6Q
You have nested it all within postgres: key that is not what the manifest shows you.
You have nested it all within postgres: key that is not what the manifest shows you.
Could you please provide a bit more information how to use nested zalando/postgres-operator in right way. Need I filling to default values of v1.Postgresql or/and using custom unmarshalling, or something else?
Sorry, I missed that that manifest is your custom manifest with postgres inside postgres. So that looks indeed fine.
On the other hand the error message is quite clear, indicating you are essentially trying to apply an invalid manifest from your operator. So that's what you need to look into.
https://github.com/zalando/postgres-operator/pull/1128 I guess this will help you
Btw, we talked about this internally. Without knowing what you want to achieve, one lesson that we learned so far is, exposing too many config options and e.g. resource configuration is not a good idea.
E.g. look into just providing
postgres:
size: xl
And have different size e.g configure resources.
Closing this, you can reopen if there is more issues around the client.
exposing too many config options and e.g. resource configuration is not a good idea.
Make sense, thank you!
Most helpful comment
https://github.com/zalando/postgres-operator/pull/1128 I guess this will help you