PacktPublishing / The-Kubernetes-Operator-Framework-Book

The Kubernetes Operator Framework Book, published by Packt
MIT License
43 stars 19 forks source link

Reconciler error #3

Open ss025 opened 1 year ago

ss025 commented 1 year ago

I am facing error while deploying sample-cr.yaml


2023-10-13T14:56:53Z    INFO    setup   starting manager
2023-10-13T14:56:53Z    INFO    controller-runtime.metrics  Starting metrics server
2023-10-13T14:56:53Z    INFO    starting server {"kind": "health probe", "addr": "[::]:8081"}
2023-10-13T14:56:53Z    INFO    controller-runtime.metrics  Serving metrics server  {"bindAddress": "127.0.0.1:8080", "secure": false}
I1013 14:56:53.595292       1 leaderelection.go:250] attempting to acquire leader lease nginx-operator-system/a7e021da.example.com...
I1013 14:56:53.629060       1 leaderelection.go:260] successfully acquired lease nginx-operator-system/a7e021da.example.com
2023-10-13T14:56:53Z    DEBUG   events  nginx-operator-controller-manager-7dd7b9f8b4-j8ccj_95e9ff77-e889-4905-9c46-8b7668bc2efa became leader   {"type": "Normal", "object": {"kind":"Lease","namespace":"nginx-operator-system","name":"a7e021da.example.com","uid":"8e8e3396-e7a8-41ce-9d8d-b59e8f080f2d","apiVersion":"coordination.k8s.io/v1","resourceVersion":"58857"}, "reason": "LeaderElection"}
2023-10-13T14:56:53Z    INFO    Starting EventSource    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "source": "kind source: *v1alpha1.NginxOperator"}
2023-10-13T14:56:53Z    INFO    Starting EventSource    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "source": "kind source: *v1.Deployment"}
2023-10-13T14:56:53Z    INFO    Starting Controller {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator"}
2023-10-13T14:56:53Z    INFO    Starting workers    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "worker count": 1}
2023-10-13T14:58:08Z    ERROR   Reconciler error    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "NginxOperator": {"name":"cluster","namespace":"nginx-operator-system"}, "namespace": "nginx-operator-system", "name": "cluster", "reconcileID": "578044a5-ca09-499e-b425-bb5292d27814", "error": "get operator condition name: could not determine operator condition name: environment variable OPERATOR_CONDITION_NAME not set"}
Lucifergene commented 11 months ago

I am also facing a Reconciler error, but for me its related to array index out of bounds

2023-12-21T17:10:48Z    INFO    controller-runtime.metrics    Metrics server is starting to listen    {"addr": "127.0.0.1:8080"}                                                                                  │
│ 2023-12-21T17:10:48Z    INFO    setup    starting manager                                                                                                                                                         │
│ 2023-12-21T17:10:48Z    INFO    Starting server    {"kind": "health probe", "addr": ":8081"}                                                                                                                      │
│ 2023-12-21T17:10:48Z    INFO    starting server    {"path": "/metrics", "kind": "metrics", "addr": "127.0.0.1:8080"}                                                                                              │
│ I1221 17:10:48.008736       1 leaderelection.go:250] attempting to acquire leader lease nginx-operator-system/624297ef.example.com...                                                                             │
│ I1221 17:11:05.429593       1 leaderelection.go:260] successfully acquired lease nginx-operator-system/624297ef.example.com                                                                                       │
│ 2023-12-21T17:11:05Z    INFO    Starting EventSource    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "source": "kind source: *v1alpha1.NginxOper │
│ 2023-12-21T17:11:05Z    INFO    Starting EventSource    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "source": "kind source: *v1.Deployment"}    │
│ 2023-12-21T17:11:05Z    INFO    Starting Controller    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator"}                                              │
│ 2023-12-21T17:11:05Z    DEBUG    events    nginx-operator-controller-manager-66bcbcfd98-jcxqv_be110471-8a47-4879-b828-c6e1e9014569 became leader    {"type": "Normal", "object": {"kind":"Lease","namespace":"ngi │
│ 2023-12-21T17:11:05Z    INFO    Starting workers    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind": "NginxOperator", "worker count": 1}                              │
│ 2023-12-21T17:11:05Z    INFO    Observed a panic in reconciler: runtime error: index out of range [0] with length 0    {"controller": "nginxoperator", "controllerGroup": "operator.example.com", "controllerKind │
│ panic: runtime error: index out of range [0] with length 0 [recovered]                                                                                                                                            │
│     panic: runtime error: index out of range [0] with length 0                                                                                                                                                    │
│                                                                                                                                                                                                                   │
│ goroutine 178 [running]:                                                                                                                                                                                          │
│ sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile.func1()                                                                                                                            │
│     /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:115 +0x1fa                                                                                                           │
│ panic({0x1715b20, 0xc00004bc20})                                                                                                                                                                                  │
│     /usr/local/go/src/runtime/panic.go:884 +0x212                                                                                                                                                                 │
│ github.com/Lucifergene/nginx-operator/controllers.(*NginxOperatorReconciler).Reconcile(0xc000010e58, {0x1a826f8, 0xc00028cab0}, {{{0xc00004a8d0?, 0x10?}, {0xc00004fb70?, 0x40dc07?}}})                           │
│     /workspace/controllers/nginxoperator_controller.go:107 +0xebd                                                                                                                                                 │
│ sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Reconcile(0x1a826f8?, {0x1a826f8?, 0xc00028cab0?}, {{{0xc00004a8d0?, 0x15af940?}, {0xc00004fb70?, 0x10?}}})                                  │
│     /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:118 +0xc8                                                                                                            │
│ sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler(0xc000120460, {0x1a82650, 0xc0006aa500}, {0x16a04c0?, 0xc00050c280?})                                                       │
│     /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:314 +0x3a5                                                                                                           │
│ sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem(0xc000120460, {0x1a82650, 0xc0006aa500})                                                                                 │
│     /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:265 +0x1d9                                                                                                           │
│ sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2()                                                                                                                              │
│     /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:226 +0x85                                                                                                            │
│ created by sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2                                                                                                                       │
│     /go/pkg/mod/sigs.k8s.io/controller-runtime@v0.15.3/pkg/internal/controller/controller.go:222 +0x333                                                                                                           │
│ Stream closed EOF for nginx-operator-system/nginx-operator-controller-manager-66bcbcfd98-jcxqv (manager)                                                                                                          │
│

Sent a mail to the author requesting him to look into the Reconciler logic once.

damemi commented 11 months ago

Hi, thanks for reporting these. I have been out of the office for a few months and am catching back up. Will take a look and update here once I have it figured out. It's possible that more recent updates to the operator framework and sdk after the book was published (along with this code) have broken some things.

damemi commented 11 months ago

@ss025 @Lucifergene if you could, in the meantime, please try running the code from this repo exactly as cloned (without running any go mod tidy or go get, etc commands). From the stack trace you provided @Lucifergene I see you are running v0.15.3 of the controller-runtime dependency while the code in this repo was written with v0.11.0. This may or may not help, but it can at least rule out dependency skew. Thanks!

Lucifergene commented 11 months ago

Thanks @damemi

I ran the code from the repo without any package update, and the issue I pointed out -"Array index out of bounds" was not visible anymore. Thanks for your advice!

But now, I can see the error @ss025 had pointed out initially, i.e. "environment variable OPERATOR_CONDITION_NAME not set".

I think I need to install the OLM to get this env. Will verify it once and reply. Although, make deploy helps to install the operator on the cluster, this error prevents the deployments from persisting in the cluster.