apecloud / kubeblocks

KubeBlocks is an open-source control plane software that runs and manages databases, message queues and other stateful applications on K8s.
https://kubeblocks.io
GNU Affero General Public License v3.0
2.12k stars 175 forks source link

[BUG] create postgresql cluster ConditionsError #1782

Closed linghan-hub closed 1 year ago

linghan-hub commented 1 year ago

local k3d environment

kbcli version
Kubernetes: v1.24.4+k3s1
KubeBlocks: 0.4.0-beta.4
kbcli: 0.4.0-beta.4
/opt/homebrew/bin/helm template mycluster deploy/postgresqlcluster > test/e2e/testdata/smoketest/postgresql/00_postgresqlcluster.yaml

cat 00_postgresqlcluster.yaml

---
# Source: pgcluster/templates/cluster.yaml
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
  name: mycluster
  labels: 
    helm.sh/chart: pgcluster-0.1.1
    app.kubernetes.io/name: pgcluster
    app.kubernetes.io/instance: mycluster
    app.kubernetes.io/version: "14.6.0"
    app.kubernetes.io/managed-by: Helm
spec:
  clusterDefinitionRef: postgresql # ref clusterdefinition.name
  clusterVersionRef: postgresql-14.6.0 # ref clusterversion.name
  terminationPolicy: Delete
  affinity:
  componentSpecs:
    - name: postgresql # user-defined
      componentDefRef: postgresql # ref clusterdefinition components.name
      monitor: false
      replicas: 2
      primaryIndex: 0
      enabledLogs:     ["running"]
      volumeClaimTemplates:
        - name: data # ref clusterdefinition components.containers.volumeMounts.name
          spec:
            storageClassName: 
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 1Gi
k get cluster,pod
NAME                                   CLUSTER-DEFINITION   VERSION             TERMINATION-POLICY   STATUS            AGE
cluster.apps.kubeblocks.io/mycluster   postgresql           postgresql-14.6.0   Delete               ConditionsError   15m

NAME                                       READY   STATUS    RESTARTS   AGE
pod/kubeblocks-grafana-595b8c9-wtl7n       3/3     Running   0          16m
pod/kubeblocks-7657ff55d-m4tfc             1/1     Running   0          16m
pod/kubeblocks-prometheus-alertmanager-0   2/2     Running   0          16m
pod/kubeblocks-prometheus-server-0         2/2     Running   0          16m

see logs

k describe cluster mycluster
Name:         mycluster
Namespace:    default
Labels:       app.kubernetes.io/instance=mycluster
              app.kubernetes.io/managed-by=Helm
              app.kubernetes.io/name=pgcluster
              app.kubernetes.io/version=14.6.0
              clusterdefinition.kubeblocks.io/name=postgresql
              clusterversion.kubeblocks.io/name=postgresql-14.6.0
              helm.sh/chart=pgcluster-0.1.1
Annotations:  kubeblocks.io/storage-class: local-path
API Version:  apps.kubeblocks.io/v1alpha1
Kind:         Cluster
Metadata:
  Creation Timestamp:  2023-03-06T03:32:54Z
  Finalizers:
    cluster.kubeblocks.io/finalizer
  Generation:  2
  Managed Fields:
    API Version:  apps.kubeblocks.io/v1alpha1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
        f:labels:
          .:
          f:app.kubernetes.io/instance:
          f:app.kubernetes.io/managed-by:
          f:app.kubernetes.io/name:
          f:app.kubernetes.io/version:
          f:helm.sh/chart:
      f:spec:
        .:
        f:clusterDefinitionRef:
        f:clusterVersionRef:
        f:componentSpecs:
          .:
          k:{"name":"postgresql"}:
            .:
            f:componentDefRef:
            f:enabledLogs:
              .:
              v:"running":
            f:monitor:
            f:name:
            f:primaryIndex:
            f:replicas:
            f:serviceType:
            f:volumeClaimTemplates:
        f:terminationPolicy:
    Manager:      kubectl-client-side-apply
    Operation:    Update
    Time:         2023-03-06T03:32:54Z
    API Version:  apps.kubeblocks.io/v1alpha1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          f:kubeblocks.io/storage-class:
        f:finalizers:
          .:
          v:"cluster.kubeblocks.io/finalizer":
        f:labels:
          f:clusterdefinition.kubeblocks.io/name:
          f:clusterversion.kubeblocks.io/name:
      f:spec:
        f:componentSpecs:
          k:{"name":"postgresql"}:
            f:resources:
    Manager:      manager
    Operation:    Update
    Time:         2023-03-06T03:32:54Z
    API Version:  apps.kubeblocks.io/v1alpha1
    Fields Type:  FieldsV1
    fieldsV1:
      f:status:
        .:
        f:components:
          .:
          f:postgresql:
            .:
            f:phase:
        f:conditions:
        f:operations:
        f:phase:
    Manager:         manager
    Operation:       Update
    Subresource:     status
    Time:            2023-03-06T03:32:54Z
  Resource Version:  63304
  UID:               3d7b94fa-7f53-4819-a85f-6b7c621e05f1
Spec:
  Cluster Definition Ref:  postgresql
  Cluster Version Ref:     postgresql-14.6.0
  Component Specs:
    Component Def Ref:  postgresql
    Enabled Logs:
      running
    Monitor:        false
    Name:           postgresql
    Primary Index:  0
    Replicas:       2
    Resources:
    Service Type:  ClusterIP
    Volume Claim Templates:
      Name:  data
      Spec:
        Access Modes:
          ReadWriteOnce
        Resources:
          Requests:
            Storage:   1Gi
  Termination Policy:  Delete
Status:
  Components:
    Postgresql:
      Phase:  Creating
  Conditions:
    Last Transition Time:  2023-03-06T03:32:54Z
    Message:               EnabledLogs: [running] are not defined in Component: postgresql of the clusterDefinition
    Reason:                PreCheckFailed
    Status:                False
    Type:                  ProvisioningStarted
  Operations:
  Phase:  ConditionsError
Events:
  Type     Reason          Age                  From                Message
  ----     ------          ----                 ----                -------
  Normal   Creating        16m                  cluster-controller  Start Creating in Cluster: mycluster
  Warning  PreCheckFailed  76s (x183 over 16m)  cluster-controller  EnabledLogs: [running] are not defined in Component: postgresql of the clusterDefinition
kubectl get cd
NAME             MAIN-COMPONENT-NAME   STATUS      AGE
postgresql       postgresql            Available   157m
apecloud-mysql   mysql                 Available   157m
➜  ~ git:(main) ✗ k get cd postgresql -o yaml
apiVersion: apps.kubeblocks.io/v1alpha1
kind: ClusterDefinition
metadata:
  annotations:
    meta.helm.sh/release-name: kubeblocks
    meta.helm.sh/release-namespace: default
  creationTimestamp: "2023-03-06T03:31:40Z"
  finalizers:
  - clusterdefinition.kubeblocks.io/finalizer
  generation: 2
  labels:
    app.kubernetes.io/instance: kubeblocks
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/version: 14.6.0
    configuration.kubeblocks.io/cfg-constraints-postgresql14-cc: postgresql14-cc
    configuration.kubeblocks.io/cfg-tpl-postgresql-configuration: postgresql-configuration
    configuration.kubeblocks.io/cfg-tpl-postgresql-custom-metrics: postgresql-custom-metrics
    configuration.kubeblocks.io/cfg-tpl-postgresql-scripts: postgresql-scripts
    helm.sh/chart: postgresql-0.1.1
  name: postgresql
  resourceVersion: "63250"
  uid: e6725da7-26a3-4f10-92df-fdfeac3d7332
spec:
  componentDefs:
  - characterType: postgresql
    configSpec:
      configTemplateRefs:
      - configConstraintRef: postgresql14-cc
        configTplRef: postgresql-configuration
        defaultMode: 511
        keys:
        - postgresql.conf
        name: postgresql-configuration
        namespace: default
        volumeName: postgresql-config
      - configTplRef: postgresql-scripts
        defaultMode: 511
        name: postgresql-scripts
        namespace: default
        volumeName: scripts
      - configTplRef: postgresql-custom-metrics
        defaultMode: 511
        name: postgresql-custom-metrics
        namespace: default
        volumeName: postgresql-custom-metrics
    logConfigs:
    - filePathPattern: /postgresql/data/log/postgresql-*
      name: run
    monitor:
      builtIn: false
      exporterConfig:
        scrapePath: /metrics
        scrapePort: 9187
    name: postgresql
    podSpec:
      containers:
      - env:
        - name: BITNAMI_DEBUG
          value: "false"
        - name: POSTGRESQL_PORT_NUMBER
          value: "5432"
        - name: POSTGRESQL_VOLUME_DIR
          value: /postgresql
        - name: PGDATA
          value: /postgresql/data
        - name: PGUSER
          valueFrom:
            secretKeyRef:
              key: username
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: PGPASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres-password
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: POSTGRES_USER
          valueFrom:
            secretKeyRef:
              key: username
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: POSTGRES_POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres-password
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres-password
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: POSTGRES_DB
          value: custom_db
        - name: POSTGRESQL_LOG_HOSTNAME
          value: "false"
        - name: POSTGRESQL_LOG_CONNECTIONS
          value: "false"
        - name: POSTGRESQL_LOG_DISCONNECTIONS
          value: "false"
        - name: POSTGRESQL_PGAUDIT_LOG_CATALOG
          value: "off"
        - name: POSTGRESQL_CLIENT_MIN_MESSAGES
          value: error
        - name: POSTGRESQL_SHARED_PRELOAD_LIBRARIES
          value: pg_stat_statements, auto_explain
        imagePullPolicy: IfNotPresent
        lifecycle:
          postStart:
            exec:
              command:
              - /scripts/post_start.sh
        livenessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - exec pg_isready -U "postgres" -h 127.0.0.1 -p 5432
          failureThreshold: 6
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        name: postgresql
        ports:
        - containerPort: 5432
          name: tcp-postgresql
          protocol: TCP
        readinessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - -ee
            - |
              exec pg_isready -U "postgres" -h 127.0.0.1 -p 5432
              [ -f /postgresql/tmp/.initialized ] || [ -f /postgresql/.initialized ]
          failureThreshold: 6
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        resources: {}
        securityContext:
          runAsUser: 0
        volumeMounts:
        - mountPath: /dev/shm
          name: dshm
        - mountPath: /postgresql
          name: data
        - mountPath: /postgresql/conf
          name: postgresql-config
        - mountPath: /scripts
          name: scripts
      - command:
        - /opt/bitnami/postgres-exporter/bin/postgres_exporter
        - --auto-discover-databases
        - --extend.query-path=/opt/conf/custom-metrics.yaml
        - --exclude-databases=template0,template1
        - --log.level=info
        env:
        - name: DATA_SOURCE_URI
          value: 127.0.0.1:5432/postgres?sslmode=disable
        - name: DATA_SOURCE_PASS
          valueFrom:
            secretKeyRef:
              key: postgres-password
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: DATA_SOURCE_USER
          valueFrom:
            secretKeyRef:
              key: username
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        image: registry.cn-hangzhou.aliyuncs.com/apecloud/postgres-exporter:0.11.1-debian-11-r49
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 6
          httpGet:
            path: /
            port: http-metrics
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        name: metrics
        ports:
        - containerPort: 9187
          name: http-metrics
          protocol: TCP
        readinessProbe:
          failureThreshold: 6
          httpGet:
            path: /
            port: http-metrics
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        resources: {}
        securityContext:
          runAsUser: 0
        volumeMounts:
        - mountPath: /opt/conf
          name: postgresql-custom-metrics
      securityContext:
        fsGroup: 1001
      volumes:
      - emptyDir:
          medium: Memory
        name: dshm
    service:
      ports:
      - name: tcp-postgresql
        port: 5432
        protocol: TCP
        targetPort: tcp-postgresql
      - name: http-metrics-postgresql
        port: 9187
        protocol: TCP
        targetPort: http-metrics
    systemAccounts:
      accounts:
      - name: kbadmin
        provisionPolicy:
          scope: AnyPods
          statements:
            creation: CREATE USER $(USERNAME) SUPERUSER PASSWORD '$(PASSWD)';
            deletion: DROP USER IF EXISTS $(USERNAME);
          type: CreateByStmt
      - name: kbdataprotection
        provisionPolicy:
          scope: AnyPods
          statements:
            creation: CREATE USER $(USERNAME) SUPERUSER PASSWORD '$(PASSWD)';
            deletion: DROP USER IF EXISTS $(USERNAME);
          type: CreateByStmt
      - name: kbprobe
        provisionPolicy:
          scope: AnyPods
          statements:
            creation: CREATE USER $(USERNAME) WITH PASSWORD '$(PASSWD)';  GRANT pg_monitor
              TO $(USERNAME);
            deletion: DROP USER IF EXISTS $(USERNAME);
          type: CreateByStmt
      - name: kbmonitoring
        provisionPolicy:
          scope: AnyPods
          statements:
            creation: CREATE USER $(USERNAME) WITH PASSWORD '$(PASSWD)';  GRANT pg_monitor
              TO $(USERNAME);
            deletion: DROP USER IF EXISTS $(USERNAME);
          type: CreateByStmt
      - name: kbreplicator
        provisionPolicy:
          scope: AnyPods
          statements:
            creation: CREATE USER $(USERNAME) WITH REPLICATION PASSWORD '$(PASSWD)';
            deletion: DROP USER IF EXISTS $(USERNAME);
          type: CreateByStmt
      cmdExecutorConfig:
        args:
        - -h$(KB_ACCOUNT_ENDPOINT)
        - -c $(KB_ACCOUNT_STATEMENT)
        command:
        - psql
        env:
        - name: PGUSER
          valueFrom:
            secretKeyRef:
              key: username
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        - name: PGPASSWORD
          valueFrom:
            secretKeyRef:
              key: postgres-password
              name: $(CONN_CREDENTIAL_SECRET_NAME)
        image: registry.cn-hangzhou.aliyuncs.com/apecloud/postgresql:14.6.0
      passwordConfig:
        length: 10
        letterCase: MixedCases
        numDigits: 5
        numSymbols: 0
    workloadType: Stateful
  connectionCredential:
    endpoint: $(SVC_FQDN):$(SVC_PORT_tcp-postgresql)
    host: $(SVC_FQDN)
    port: $(SVC_PORT_tcp-postgresql)
    postgres-password: $(RANDOM_PASSWD)
    username: postgres
status:
  observedGeneration: 2
  phase: Available
yangmeilly commented 1 year ago

log of pg has renamed to running, and isn't merged to release-0.4.

this case results from this scenario: 1: use origin helm chart of release-0.4 , and install cluster-definition.yaml which doesn't contain the running-log changes 2: local test uses the new code of main, and generate the resource of cluster.yaml

brief recap, the origin helm chart doesn't keep inconsistent with branch main result in the failure of this installation

linghan-hub commented 1 year ago

The name in the cd should be synchronized to running

lynnleelhl commented 1 year ago

code not synced between cluster and clusterdefinition.