Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck in setup #65

Open
mstingl opened this issue Nov 23, 2024 · 15 comments
Open

Stuck in setup #65

mstingl opened this issue Nov 23, 2024 · 15 comments
Assignees
Labels
bug Something isn't working

Comments

@mstingl
Copy link

mstingl commented Nov 23, 2024

Steps to reproduce

Deployment of a Shop through shopware helm chart

What should happened?

The setup job should pass

What actually happened?

The setup job is instantly deleted (and the pod killed) after creation, leaving the operator stuck in the setup stage. Repeating every 10 seconds

Relevant log output

(Namespace, deployment name and URLs are changed)

2024-11-27 18:41:05    [INFO]    setup    starting manager
2024-11-27 18:41:05    [INFO]    controller-runtime.metrics    Starting metrics server
2024-11-27 18:41:05    [INFO]    starting server    {"kind": "health probe", "addr": ":8081"}
2024-11-27 18:41:05    [INFO]    controller-runtime.metrics    Serving metrics server    {"bindAddress": ":8080", "secure": false}
I1127 18:41:05.986837       1 leaderelection.go:250] attempting to acquire leader lease my-shop/d79142e5.shopware.com...
I1127 18:41:21.032202       1 leaderelection.go:260] successfully acquired lease my-shop/d79142e5.shopware.com
2024-11-27 18:41:21    [DEBUG]    events    shopware-operator-5b8dfc5f8f-ctmz8_b033fa7b-3577-4bce-9362-4281a886aaaf became leader    {"type": "Normal", "object": {"kind":"Lease","namespace":"my-shop","name":"d79142e5.shopware.com","uid":"6c33bfe3-8dca-4893-897d-88b1e00ec547","apiVersion":"coordination.k8s.io/v1","resourceVersion":"513755298"}, "reason": "LeaderElection"}
2024-11-27 18:41:21    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Store"}
2024-11-27 18:41:21    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Secret"}
2024-11-27 18:41:21    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Deployment"}
2024-11-27 18:41:21    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Job"}
2024-11-27 18:41:21    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Secret"}
2024-11-27 18:41:21    [INFO]    Starting Controller    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store"}
2024-11-27 18:41:21    [INFO]    Starting workers    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "worker count": 1}
2024-11-27 18:41:21    [INFO]    Do reconcile on store because db secret has changed    {"Store": "my-shop"}
2024-11-27 18:41:21    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276", "state": "setup"}
2024-11-27 18:41:21    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276", "state": "setup"}
2024-11-27 18:41:21    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"513754547"}, "reason": "Diff setup job hash"}
2024-11-27 18:41:21    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276", "state": "setup"}
2024-11-27 18:41:21    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276"}
2024-11-27 18:41:21    [INFO]    Found container for job `shopware-setup`    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276"}
2024-11-27 18:41:21    [INFO]    Job not terminated still running    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276"}
2024-11-27 18:41:21    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "8f480550-5d3b-4023-b9e1-8a1570c38276", "status": {"state":"setup","conditions":[{"type":"setup","lastTransiti
onTime":null,"lastUpdatedTime":"2024-11-27T18:41:21Z","message":"Waiting for setup job to finish (Notice sidecars are counted). Active jobs: 0, Failed jobs: 0","status":"True"}]}}
2024-11-27 18:41:21    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5a9d1b84-b146-4eb1-9f1b-aa6568c7de81", "state": "setup"}
2024-11-27 18:41:21    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5a9d1b84-b146-4eb1-9f1b-aa6568c7de81", "state": "setup"}
2024-11-27 18:41:21    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"513754547"}, "reason": "Diff setup job hash"}
2024-11-27 18:41:31    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5a9d1b84-b146-4eb1-9f1b-aa6568c7de81", "state": "setup"}
2024-11-27 18:41:31    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5a9d1b84-b146-4eb1-9f1b-aa6568c7de81"}
2024-11-27 18:41:31    [ERROR]    job not found in container: shopware-setup    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5a9d1b84-b146-4eb1-9f1b-aa6568c7de81", "error": "job not found in container: shopware
-setup"}
github.com/shopware/shopware-operator/internal/job.IsJobContainerDone
    /home/runner/work/shopware-operator/shopware-operator/internal/job/util.go:89
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).stateSetup
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/status.go:232
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).reconcileCRStatus
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/status.go:63
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile.func1
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:107
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:132
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227
2024-11-27 18:41:31    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5a9d1b84-b146-4eb1-9f1b-aa6568c7de81", "status": {"state":"setup","conditions":[{"type":"setup","lastTransiti
onTime":null,"lastUpdatedTime":"2024-11-27T18:41:31Z","message":"Waiting for setup job to finish","reason":"job not found in container: shopware-setup","status":"Error"}]}}
2024-11-27 18:41:31    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "705040e8-3343-4517-a1d1-f55d68f24e7e", "state": "setup"}
2024-11-27 18:41:31    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "705040e8-3343-4517-a1d1-f55d68f24e7e", "state": "setup"}
2024-11-27 18:41:31    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"513755310"}, "reason": "Diff setup job hash"}
2024-11-27 18:41:41    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "705040e8-3343-4517-a1d1-f55d68f24e7e", "state": "setup"}
2024-11-27 18:41:41    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "705040e8-3343-4517-a1d1-f55d68f24e7e"}
2024-11-27 18:41:41    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "705040e8-3343-4517-a1d1-f55d68f24e7e", "status": {"state":"setup","conditions":[{"type":"setup","lastTransiti
onTime":null,"lastUpdatedTime":"2024-11-27T18:41:41Z","message":"Waiting for setup job to finish","status":"True"}]}}
2024-11-27 18:41:41    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "9eed825f-148b-448a-bffd-46027bb35b3b", "state": "setup"}
2024-11-27 18:41:41    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "9eed825f-148b-448a-bffd-46027bb35b3b", "state": "setup"}
2024-11-27 18:41:41    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"513755386"}, "reason": "Diff setup job hash"}

Your custom resource

# configured through helm chart shopware
# values:
percona:
  enabled: false

minio:
  enabled: false

store:
  host: shop...
  serviceAccountName: null

  disableJobDeletion: true

  network:
    enabled: false

  database:
    user: 'root'
    host: 'my-shop-mariadb'
    passwordSecretRef:
      name: 'my-shop-mariadb'
      key: 'mariadb-root-password'

  s3Storage:
    endpointURL: https://s3...
    accessKeyRef:
      name: s3-credentials
      key: AWS_ACCESS_KEY
    secretAccessKeyRef:
      name: s3-credentials
      key: AWS_SECRET_KEY
@mstingl mstingl added the bug Something isn't working label Nov 23, 2024
@TrayserCassa TrayserCassa self-assigned this Nov 25, 2024
@TrayserCassa
Copy link
Contributor

Hi thank you for the issue 👍

This happens when the job resource is modified from other operators or in some way. That's mostly true if you see the diff hash log/event.

Update Store my-shop setup job in namespace my-shop-namespace. Diff hash

If the job resource is not the same as it was before, we delete the job and recreate it. Because jobs can't be patched and so we delete and recreate it.

The first issue

job not found in container: shopware-setup

happens when the setup job is found but the name of the setup container inside the job is not shopware-setup. You can't modify the name, because it's hard coded in the code so I guess the issue is a timing issue with the api and the operator.

We can fix this in the operator by ignoring fields for the hash generation. So if you can tell me what get's attached after the job is created, I can fix it. Annotations should be fine, but labels for example would trigger a recreate of the job.

@mstingl
Copy link
Author

mstingl commented Nov 27, 2024

Thanks for your reply.

I got the definitions of the resources. I cannot see that any other operator would modify the job. It is deleted almost instantly after creation (aprox. 4-5 sec).

The created Pod is also being terminated almost instantly as the Job is deleted.

apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    batch.kubernetes.io/job-tracking: ""
    shopware.com/last-config-hash: 24b308ee1d48a04d07293a69ed85e4f4
  creationTimestamp: "2024-11-27T18:29:00Z"
  deletionGracePeriodSeconds: 0
  deletionTimestamp: "2024-11-27T18:29:00Z"
  finalizers:
  - foregroundDeletion
  generation: 2
  labels:
    store: my-shop
    type: setup
  name: my-shop-setup
  namespace: my-shop
  ownerReferences:
  - apiVersion: shop.shopware.com/v1
    blockOwnerDeletion: true
    controller: true
    kind: Store
    name: my-shop
    uid: 0cd29409-5b25-4e5e-ac71-89e86a48dc7b
  resourceVersion: "513749357"
  uid: 87de84cf-7c20-42d9-b5b1-c20202fb4cf4
spec:
  backoffLimit: 6
  completionMode: NonIndexed
  completions: 1
  parallelism: 1
  selector:
    matchLabels:
      controller-uid: 87de84cf-7c20-42d9-b5b1-c20202fb4cf4
  suspend: false
  template:
    metadata:
      creationTimestamp: null
      labels:
        controller-uid: 87de84cf-7c20-42d9-b5b1-c20202fb4cf4
        job-name: my-shop-setup
        store: my-shop
        type: setup
    spec:
      containers:
        ...
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: "2024-11-27T18:33:51Z"
  deletionGracePeriodSeconds: 30
  deletionTimestamp: "2024-11-27T18:34:21Z"
  generateName: my-shop-setup-
  labels:
    controller-uid: 2c455c57-04c6-4657-8d3a-ef259f660179
    job-name: my-shop-setup
    store: my-shop
    type: setup
  name: my-shop-setup-hd8rl
  namespace: my-shop
  ownerReferences:
  - apiVersion: batch/v1
    blockOwnerDeletion: true
    controller: true
    kind: Job
    name: my-shop-setup
    uid: 2c455c57-04c6-4657-8d3a-ef259f660179
  resourceVersion: "513751839"
  uid: 22f56eb5-a237-4119-8f3a-094767a66f45
spec:
  containers:
  - args:
    - /setup
    command:
    - sh
    - -c
    env:
      ...
    image: ghcr.io/shopware/shopware-kubernetes:latest
    imagePullPolicy: IfNotPresent
    name: shopware-setup
    resources: {}
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /etc/caddy
      name: my-shop-caddy-config
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-nd4gj
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  nodeName: ...
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Never
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  shareProcessNamespace: true
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - configMap:
      defaultMode: 420
      name: my-shop-caddy-config
    name: my-shop-caddy-config
  - name: kube-api-access-nd4gj
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2024-11-27T18:33:51Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2024-11-27T18:33:51Z"
    message: 'containers with unready status: [shopware-setup]'
    reason: ContainersNotReady
    status: "False"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2024-11-27T18:33:51Z"
    message: 'containers with unready status: [shopware-setup]'
    reason: ContainersNotReady
    status: "False"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2024-11-27T18:33:51Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - image: ghcr.io/shopware/shopware-kubernetes:latest
    imageID: ""
    lastState: {}
    name: shopware-setup
    ready: false
    restartCount: 0
    started: false
    state:
      waiting:
        reason: ContainerCreating
  hostIP: ...
  phase: Pending
  qosClass: BestEffort
  startTime: "2024-11-27T18:33:51Z"

@mstingl
Copy link
Author

mstingl commented Nov 27, 2024

Updated shopware operator logs in the issue description

@TrayserCassa
Copy link
Contributor

The operator is changing the setup job because the resource is modified in some way. I can't see anything directly what cause this problem, but I will focus on the sub issue to make it visible. Sorry for that.
If you want to test it out, you can use the helm chart to create a local cluster. This works as expected currently and I will make the cause more visible with the next patch.

@mstingl
Copy link
Author

mstingl commented Nov 28, 2024

Just for clearification, a local cluster without the operator? Which chart are you referring to? I'm not able to find one where the operator isn't used. Thanks for your help in advance :)

@tombojer
Copy link
Contributor

Hi,

we provider a helm-chart which you can use for testing.
The docs also include the steps for setting it up in a kind cluster.

Can you maybe give us some more information about the current environment you are running the workload in?
This would help us for recreating the error for further debugging.

@mstingl
Copy link
Author

mstingl commented Nov 30, 2024

Exactly this helm chart is used to deploy the shop (incl. operator) and it was setup according to docs (see values in issue description).

Environment is a k3s, self hosted. Furthermore I want to use the s3 backend provided by rook-ceph, which is used as storage backend, as I don't want to deploy multiple services providing a s3 (e. g. minio)

@tombojer
Copy link
Contributor

tombojer commented Dec 2, 2024

Thank you, I will try to recreate the issue in k3s.
I will keep you updated when I found a solution.

@tombojer
Copy link
Contributor

tombojer commented Dec 6, 2024

Hi

I am still on trying to recreate the issue.

Are the secrets that are used for the store generated by other operators or did you create them manually?

@TrayserCassa
Copy link
Contributor

So I did manage to let the k3s setup run on my local machine and unfortunately it worked like expected. I used minio in this example but set the credentials by a test values yaml file:

percona:
  enabled: true

# minio:
#   enabled: true

store:
  host: shop.localhost.traefik.me
  serviceAccountName: null

  disableJobDeletion: true

  network:
    enabled: false

  s3Storage:
    endpointURL: http://minio.issue.svc.cluster.local
    accessKeyRef:
      key: CONSOLE_ACCESS_KEY
      name: store-s3-shopware
    secretAccessKeyRef:
      key: CONSOLE_SECRET_KEY
      name: store-s3-shopware

After some debugging and testing my first assumption was wrong, the job resource doesn't get changed because that is also not possible for most of the values.
The job resource is generated inside the operator and gets hashed. The hash is then applied as a annotation like this:

apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    shopware.com/last-config-hash: 1f0ebac42cce5d8f7a2bd1cbf0381fd1

If you change for example some env variables for the store resource, the hash is different and that's when the job gets deleted and then created. Why this is happening I can only guess. Important would be that we are talking of the same helm-chart and the same operator.

Operator image of the pod kubectl get deployment/shopware-operator -n <your-namespace> -o wide
Image: ghcr.io/shopware/shopware-operator:0.0.26

One Idea to see if something is changing the resource you can watch the resources like this:

kubectl get stores -n <namespace> --watch 

Make sure to scale the shopware operator deployment down to 0, because the operator is changing the status of the resource from time to time.

And if you run this command:

kubectl get jobs/<helm installation name>-setup -n <namespace> -o=jsonpath='{$.metadata.annotations}' --watch

you should see different hashes each time the job get's created. This is not tested because it's working locally for me but should confirm my suspicions.

@mstingl
Copy link
Author

mstingl commented Dec 13, 2024

Thanks for your support. I can provide the following answers:

@tombojer

Hi

I am still on trying to recreate the issue.

Are the secrets that are used for the store generated by other operators or did you create them manually?

The secret for the store is created manually.


@TrayserCassa

Operator image of the pod kubectl get deployment/shopware-operator -n -o wide
Image: ghcr.io/shopware/shopware-operator:0.0.26

I can confirm that the same image is being used.

One Idea to see if something is changing the resource you can watch the resources like this:

kubectl get stores -n <namespace> --watch

Make sure to scale the shopware operator deployment down to 0, because the operator is changing the status of the resource from time to time.

When the operator is not running, there are no changes to the store resource.

And if you run this command:

kubectl get jobs/<helm installation name>-setup -n <namespace> -o=jsonpath='{$.metadata.annotations}' --watch

you should see different hashes each time the job get's created. This is not tested because it's working locally for me but should confirm my suspicions.

The hash of the job is the same while it's being recreated multiple times:

{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}
{"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}

@TrayserCassa
Copy link
Contributor

Ok for me it's a bit strange, because the calculation of the hash looks good. So the crd is not getting changed at all, which is good. We pushed a new image which logs the reason why the object will be patched by the operator:

ghcr.io/shopware/shopware-operator:0.0.27

If you change the deployment of the operator to this image you should get more logs like this one:
Object last-config-hash has changed or Object meta has changed
This happens only if the annotation or label is not equal and print it out or the hash is not the same. So we can maybe see why this is happening. And if the message doesn't show up at all, the job is not modified by the operator.

On thing to make sure that the operator is deleting the job would be, that you remove the permission for the deletion of the operator. Then we should also see an error if the operator is trying to delete it. The object manager-role in the resource pool of roles should be edited for that.

@mstingl
Copy link
Author

mstingl commented Dec 16, 2024

I collected the following logs with the new image.

2024-12-16 21:04:14    [INFO]    setup    starting manager
2024-12-16 21:04:14    [INFO]    controller-runtime.metrics    Starting metrics server
2024-12-16 21:04:14    [INFO]    starting server    {"kind": "health probe", "addr": ":8081"}
2024-12-16 21:04:14    [INFO]    controller-runtime.metrics    Serving metrics server    {"bindAddress": ":8080", "secure": false}
I1216 21:04:14.982176       1 leaderelection.go:250] attempting to acquire leader lease my-shop/d79142e5.shopware.com...
I1216 21:04:31.506923       1 leaderelection.go:260] successfully acquired lease my-shop/d79142e5.shopware.com
2024-12-16 21:04:31    [DEBUG]    events    shopware-operator-667d87d5b8-2gt9s_2be48b6f-64e8-4dca-8160-435b7ec0c3ad became leader    {"type": "Normal", "object": {"kind":"Lease","namespace":"my-shop","name":"d79142e5.shopware.com","uid":"6c33bfe3-8dca-4893-897d-88b1e00ec547","apiVersion":"coordination.k8s.io/v1","resourceVersion":"523980636"}, "reason": "LeaderElection"}
2024-12-16 21:04:31    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Store"}
2024-12-16 21:04:31    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Secret"}
2024-12-16 21:04:31    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Deployment"}
2024-12-16 21:04:31    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Job"}
2024-12-16 21:04:31    [INFO]    Starting EventSource    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "source": "kind source: *v1.Secret"}
2024-12-16 21:04:31    [INFO]    Starting Controller    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store"}
2024-12-16 21:04:31    [INFO]    Do reconcile on store because db secret has changed    {"Store": "my-shop"}
2024-12-16 21:04:31    [INFO]    Starting workers    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "worker count": 1}
2024-12-16 21:04:31    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "026b21af-f329-41e2-b7dd-3a6f1a0c0645", "state": "setup"}
2024-12-16 21:04:31    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "026b21af-f329-41e2-b7dd-3a6f1a0c0645", "state": "setup"}
2024-12-16 21:04:31    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"522362914"}, "reason": "Diff setup job hash"}
2024-12-16 21:04:31    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "026b21af-f329-41e2-b7dd-3a6f1a0c0645", "state": "setup"}
2024-12-16 21:04:31    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "026b21af-f329-41e2-b7dd-3a6f1a0c0645"}
2024-12-16 21:04:31    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "026b21af-f329-41e2-b7dd-3a6f1a0c0645", "status": {"state":"setup","conditions":[{"type":"setup","lastTransitionTime":null,"lastUpdatedTime":"2024-12-16T21:04:31Z","message":"Waiting for setup job to finish","status":"True"}]}}
2024-12-16 21:04:31    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076", "state": "setup"}
2024-12-16 21:04:31    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076", "state": "setup"}
2024-12-16 21:04:31    [INFO]    Object meta has changed    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076", "oldAnnotations": {"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "newAnnotations": {"shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "oldLabels": {"store":"my-shop","type":"setup"}, "newLabels": {"store":"my-shop","type":"setup"}}
2024-12-16 21:04:31    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"523980645"}, "reason": "Diff setup job hash"}
2024-12-16 21:04:41    [ERROR]    reconcile    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076", "error": "setup: reconcile unready setup job: create job my-shop/my-shop-setup: object is being deleted: jobs.batch \"my-shop-setup\" already exists"}
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:127
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227
2024-12-16 21:04:41    [INFO]    Found container for job `shopware-setup`    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076"}
2024-12-16 21:04:41    [INFO]    Job not terminated still running    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076"}
2024-12-16 21:04:41    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "f3393b18-4c58-4f03-aa5d-35acd404a076", "status": {"state":"setup","conditions":[{"type":"setup","lastTransitionTime":null,"lastUpdatedTime":"2024-12-16T21:04:41Z","message":"Waiting for setup job to finish (Notice sidecars are counted). Active jobs: 0, Failed jobs: 0","status":"True"}]}}
2024-12-16 21:04:41    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "92065c9f-7585-49be-91d2-b67bd73817c2", "state": "setup"}
2024-12-16 21:04:41    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "92065c9f-7585-49be-91d2-b67bd73817c2", "state": "setup"}
2024-12-16 21:04:41    [INFO]    Object meta has changed    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "92065c9f-7585-49be-91d2-b67bd73817c2", "oldAnnotations": {"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "newAnnotations": {"shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "oldLabels": {"store":"my-shop","type":"setup"}, "newLabels": {"store":"my-shop","type":"setup"}}
2024-12-16 21:04:41    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"523980645"}, "reason": "Diff setup job hash"}
2024-12-16 21:04:51    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "92065c9f-7585-49be-91d2-b67bd73817c2", "state": "setup"}
2024-12-16 21:04:51    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "92065c9f-7585-49be-91d2-b67bd73817c2"}
2024-12-16 21:04:51    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "92065c9f-7585-49be-91d2-b67bd73817c2", "status": {"state":"setup","conditions":[{"type":"setup","lastTransitionTime":null,"lastUpdatedTime":"2024-12-16T21:04:51Z","message":"Waiting for setup job to finish","status":"True"}]}}
2024-12-16 21:04:51    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754", "state": "setup"}
2024-12-16 21:04:51    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754", "state": "setup"}
2024-12-16 21:04:51    [INFO]    Object meta has changed    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754", "oldAnnotations": {"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "newAnnotations": {"shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "oldLabels": {"store":"my-shop","type":"setup"}, "newLabels": {"store":"my-shop","type":"setup"}}
2024-12-16 21:04:51    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"523980722"}, "reason": "Diff setup job hash"}
2024-12-16 21:05:01    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754", "state": "setup"}
2024-12-16 21:05:01    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754"}
2024-12-16 21:05:01    [ERROR]    job not found in container: shopware-setup    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754", "error": "job not found in container: shopware-setup"}
github.com/shopware/shopware-operator/internal/job.IsJobContainerDone
    /home/runner/work/shopware-operator/shopware-operator/internal/job/util.go:89
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).stateSetup
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/status.go:232
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).reconcileCRStatus
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/status.go:63
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile.func1
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:107
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:132
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227
2024-12-16 21:05:01    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "71cef471-9e4c-424d-b601-b2b1423e4754", "status": {"state":"setup","conditions":[{"type":"setup","lastTransitionTime":null,"lastUpdatedTime":"2024-12-16T21:05:01Z","message":"Waiting for setup job to finish","reason":"job not found in container: shopware-setup","status":"Error"}]}}
2024-12-16 21:05:01    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "7e754a95-22a8-4be3-bde3-7e0b0b82c9fe", "state": "setup"}
2024-12-16 21:05:01    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "7e754a95-22a8-4be3-bde3-7e0b0b82c9fe", "state": "setup"}
2024-12-16 21:05:01    [INFO]    Object meta has changed    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "7e754a95-22a8-4be3-bde3-7e0b0b82c9fe", "oldAnnotations": {"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "newAnnotations": {"shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "oldLabels": {"store":"my-shop","type":"setup"}, "newLabels": {"store":"my-shop","type":"setup"}}
2024-12-16 21:05:01    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"523980892"}, "reason": "Diff setup job hash"}
2024-12-16 21:05:11    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "7e754a95-22a8-4be3-bde3-7e0b0b82c9fe", "state": "setup"}
2024-12-16 21:05:11    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "7e754a95-22a8-4be3-bde3-7e0b0b82c9fe"}
2024-12-16 21:05:11    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "7e754a95-22a8-4be3-bde3-7e0b0b82c9fe", "status": {"state":"setup","conditions":[{"type":"setup","lastTransitionTime":null,"lastUpdatedTime":"2024-12-16T21:05:11Z","message":"Waiting for setup job to finish","status":"True"}]}}
2024-12-16 21:05:11    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6", "state": "setup"}
2024-12-16 21:05:11    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6", "state": "setup"}
2024-12-16 21:05:11    [INFO]    Object meta has changed    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6", "oldAnnotations": {"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "newAnnotations": {"shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "oldLabels": {"store":"my-shop","type":"setup"}, "newLabels": {"store":"my-shop","type":"setup"}}
2024-12-16 21:05:11    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"523980892"}, "reason": "Diff setup job hash"}
2024-12-16 21:05:21    [INFO]    my-shop    Wait for setup to finish    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6", "state": "setup"}
2024-12-16 21:05:21    [INFO]    Reconcile finished    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6"}
2024-12-16 21:05:21    [ERROR]    job not found in container: shopware-setup    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6", "error": "job not found in container: shopware-setup"}
github.com/shopware/shopware-operator/internal/job.IsJobContainerDone
    /home/runner/work/shopware-operator/shopware-operator/internal/job/util.go:89
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).stateSetup
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/status.go:232
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).reconcileCRStatus
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/status.go:63
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile.func1
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:107
github.com/shopware/shopware-operator/internal/controller.(*StoreReconciler).Reconcile
    /home/runner/work/shopware-operator/shopware-operator/internal/controller/store_controller.go:132
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:119
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:316
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:266
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:227
2024-12-16 21:05:21    [INFO]    Update store status    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "3189b2b1-3f83-4333-b443-b856a9bf68f6", "status": {"state":"setup","conditions":[{"type":"setup","lastTransitionTime":null,"lastUpdatedTime":"2024-12-16T21:05:21Z","message":"Waiting for setup job to finish","reason":"job not found in container: shopware-setup","status":"Error"}]}}
2024-12-16 21:05:21    [INFO]    my-shop    Do reconcile on store    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5f3cb242-4af1-4fba-960c-6dbc0896f631", "state": "setup"}
2024-12-16 21:05:21    [INFO]    my-shop    reconcile app secrets    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5f3cb242-4af1-4fba-960c-6dbc0896f631", "state": "setup"}
2024-12-16 21:05:21    [INFO]    Object meta has changed    {"controller": "store", "controllerGroup": "shop.shopware.com", "controllerKind": "Store", "Store": {"name":"my-shop","namespace":"my-shop"}, "namespace": "my-shop", "name": "my-shop", "reconcileID": "5f3cb242-4af1-4fba-960c-6dbc0896f631", "oldAnnotations": {"batch.kubernetes.io/job-tracking":"","shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "newAnnotations": {"shopware.com/last-config-hash":"24b308ee1d48a04d07293a69ed85e4f4"}, "oldLabels": {"store":"my-shop","type":"setup"}, "newLabels": {"store":"my-shop","type":"setup"}}
2024-12-16 21:05:21    [DEBUG]    events    Update Store my-shop setup job in namespace my-shop. Diff hash    {"type": "Normal", "object": {"kind":"Store","namespace":"my-shop","name":"my-shop","uid":"0cd29409-5b25-4e5e-ac71-89e86a48dc7b","apiVersion":"shop.shopware.com/v1","resourceVersion":"523981064"}, "reason": "Diff setup job hash"}

@TrayserCassa
Copy link
Contributor

Ok found it, the Object meta has changed is the indicator that the metadata of an resource is not the same after the operator created the resource.

  "oldAnnotations": {
    "batch.kubernetes.io/job-tracking": "",
    "shopware.com/last-config-hash": "24b308ee1d48a04d07293a69ed85e4f4"
  },
  "newAnnotations": {
    "shopware.com/last-config-hash": "24b308ee1d48a04d07293a69ed85e4f4"
  },

This is why it gets deleted and recreated. The Annotation batch.kubernetes.io/job-tracking is attached to the job after it's created. So for a hot fix you could attach it to the annotations in the store crd, just to make sure that my assumption is correct.
Since annotations are currently attached to any resource we need a way to support this. I will talk to my colleagues and fix this asap.

@mstingl
Copy link
Author

mstingl commented Dec 17, 2024

Can confirm that it works with the added annotation. (The annotation has to be added to the store crd directly, its currently missing in the helm chart template.)
The setup is started and after that all additional deployments are created correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants