kubeblocks icon indicating copy to clipboard operation
kubeblocks copied to clipboard

[BUG] mysql orc switchover /bin/sh: syntax error: unexpected end of file (expecting ")")

Open JashBook opened this issue 8 months ago • 1 comments

Describe the bug A clear and concise description of what the bug is.

kbcli version
Kubernetes: v1.32.0
KubeBlocks: 1.0.0-beta.45
kbcli: 1.0.0-beta.20

kubectl logs a8a1bf31-mysql-apegqo-switc-mysql-switchover-0-4xg2p Defaulted container "switchover" out of: switchover, ops-utils (init) /bin/sh: syntax error: unexpected end of file (expecting ")")

To Reproduce Steps to reproduce the behavior:

  1. create orc cluster
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: orcm-apegqo
  namespace: default
spec:
  clusterDef: orchestrator
  topology: raft
  terminationPolicy: WipeOut
  services:
    - name: orchestrator
      componentSelector: orchestrator
      spec:
        ports:
          - name: orc-http
            port: 80
  componentSpecs:
    - name: orchestrator
      serviceVersion: 3.2.6
      replicas: 3
      resources:
        requests:
          cpu: 500m
          memory: 0.5Gi
        limits:
          cpu: 500m
          memory: 0.5Gi
      volumeClaimTemplates:
        - name: data
          spec:
            storageClassName: 
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 1Gi
  1. create mysql cluster
apiVersion: apps.kubeblocks.io/v1
kind: Cluster
metadata:
  name: mysql-apegqo
  namespace: default
spec:
  clusterDef: mysql
  topology: orc
  terminationPolicy: WipeOut
  componentSpecs:
    - name: mysql
      serviceVersion: 8.0.30
      
      disableExporter: true
      replicas: 2
      resources:
        limits:
          cpu: 500m
          memory: 0.5Gi
        requests:
          cpu: 500m
          memory: 0.5Gi
      volumeClaimTemplates:
        - name: data
          spec:
            storageClassName: 
            accessModes:
              - ReadWriteOnce
            resources:
              requests:
                storage: 10Gi
      serviceRefs:
      - name: orchestrator
        namespace: default
        clusterServiceSelector:
          cluster: orcm-apegqo
          service:
            component: orchestrator
            service: orchestrator
            port: orc-http
          credential:
            component: orchestrator
            name: orchestrator
kbcli cluster list-instances mysql-apegqo 
NAME                   NAMESPACE   CLUSTER        COMPONENT   STATUS    ROLE        ACCESSMODE   AZ       CPU(REQUEST/LIMIT)   MEMORY(REQUEST/LIMIT)   STORAGE     NODE                    CREATED-TIME                 
mysql-apegqo-mysql-0   default     mysql-apegqo   mysql       Running   secondary                <none>   500m / 500m          512Mi / 512Mi           data:10Gi   minikube/192.168.49.2   Apr 24,2025 15:03 UTC+0800   
mysql-apegqo-mysql-1   default     mysql-apegqo   mysql       Running   primary                  <none>   500m / 500m          512Mi / 512Mi           data:10Gi   minikube/192.168.49.2   Apr 24,2025 15:05 UTC+0800 
  1. switchover
kubectl create -f -<<EOF
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsRequest
metadata:
  generateName: mysql-apegqo-switchover-
spec:
  clusterName: mysql-apegqo
  type: Custom
  custom:
    components:
      - componentName: mysql
        parameters:
          - name: candidate
            value: mysql-apegqo-mysql-0
    opsDefinitionName: mysql-orc-switchover
EOF
  1. See error
➜  ~ kubectl get pod a8a1bf31-mysql-apegqo-switc-mysql-switchover-0-4xg2p 
NAME                                                   READY   STATUS   RESTARTS   AGE
a8a1bf31-mysql-apegqo-switc-mysql-switchover-0-4xg2p   0/1     Error    0          43s
➜  ~ 
➜  ~ kubectl get ops mysql-apegqo-switchover-hvzgq 
NAME                            TYPE     CLUSTER        STATUS   PROGRESS   AGE
mysql-apegqo-switchover-hvzgq   Custom   mysql-apegqo   Failed   1/1        50s
➜  ~ 
➜  ~ kubectl logs a8a1bf31-mysql-apegqo-switc-mysql-switchover-0-4xg2p
Defaulted container "switchover" out of: switchover, ops-utils (init)
/bin/sh: syntax error: unexpected end of file (expecting ")")
kubectl get opsdefinitions mysql-orc-switchover -oyaml
apiVersion: operations.kubeblocks.io/v1alpha1
kind: OpsDefinition
metadata:
  annotations:
    meta.helm.sh/release-name: kb-addon-mysql
    meta.helm.sh/release-namespace: kb-system
  creationTimestamp: "2025-04-24T06:40:08Z"
  finalizers:
  - opsdefinition.kubeblocks.io/finalizer
  generation: 2
  labels:
    app.kubernetes.io/managed-by: Helm
  name: mysql-orc-switchover
  resourceVersion: "1487"
  uid: 2ddfcd95-8a28-4ef1-a0ca-22906f8125ba
spec:
  actions:
  - failurePolicy: Fail
    name: switchover
    workload:
      backoffLimit: 0
      podInfoExtractorName: orcInfo
      podSpec:
        containers:
        - command:
          - /bin/sh
          - -c
          - |
            response=$(curl -s -o /dev/null -w "%{http_code}" http://${ORC_ENDPOINTS}/api/graceful-master-takeover-auto/${candidate}
            if [ ! $response -eq 200 ]; then
              echo "switchover failed, please check the candidate"
              exit 1
            fi
          image: docker.io/apecloud/orc-tools:1.0.3
          imagePullPolicy: IfNotPresent
          name: switchover
          resources: {}
      type: Job
  parametersSchema:
    openAPIV3Schema:
      properties:
        candidate:
          description: |
            candidate instance name(pod Name). if candidate is not empty, will promote it to primary.
            otherwise promote a randomly selected pod to primary.
          type: string
      type: object
  podInfoExtractors:
  - env:
    - name: ORC_ENDPOINTS
      valueFrom:
        envRef:
          envName: ORC_ENDPOINTS
    name: orcInfo
    podSelector:
      multiPodSelectionPolicy: Any
status:
  observedGeneration: 2
  phase: Available

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Additional context Add any other context about the problem here.

JashBook avatar Apr 24 '25 07:04 JashBook

@xuriwuyun pls help improve this addon, use lifecycleAction.swtichover actions instead of opsdef if possible.

shanshanying avatar Apr 24 '25 09:04 shanshanying

fixed at https://github.com/apecloud/kubeblocks-addons/pull/1678

wangyelei avatar May 19 '25 07:05 wangyelei