You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The EMQX CRD version v2beta1 can cause a nil pointer dereference in the operator controller when updating the Replicas status if spec.coreTemplate.spec.replicas is not defined in the CRD.
Observe that the operator crashes due to a nil pointer dereference.
Expected Behavior
An EMQX instace should be deployed successfully based on the CRD without causing a crash in the operator controller. The operator should handle the absence of replicas gracefully.
Additional Information
The issue is likely caused by the lack of a nil check on instance.Spec.CoreTemplate.Spec.Replicas in the controller code, specifically at [this line](
HI @Kallepan the default value of the replicas in .spec.coreTemplate.spce.replicas is 2, so it shouldn't be nil, I used the following file to deploy EMQX is work
my mistake, I forgot to add the key coreTemplate in the example. I have adjusted the example in the issue. Basically this error occurs when coreTemplate is defined in the manifest but replicas is omitted.
Yes, you are right, but I'm still find the reason, check the default value of CRD by kubectl get crd emqxes.apps.emqx.io -o yaml | yq '.spec.versions[1].schema.openAPIV3Schema.properties.spec.properties.coreTemplate.properties.spec.properties.replicas', can find I already have to set 2 for default, but it's not work in your case
Describe the bug
The EMQX CRD version
v2beta1
can cause a nil pointer dereference in the operator controller when updating theReplicas
status ifspec.coreTemplate.spec.replicas
is not defined in the CRD.Logs
To Reproduce
Deploy the EMQX Operator as described in the official docs
Create an EMQX CRD without defining
spec.coreTemplate.spec.replicas
:Observe that the operator crashes due to a nil pointer dereference.
Expected Behavior
An EMQX instace should be deployed successfully based on the CRD without causing a crash in the operator controller. The operator should handle the absence of
replicas
gracefully.The following manifest resolves the issue:
Additional Information
The issue is likely caused by the lack of a nil check on
instance.Spec.CoreTemplate.Spec.Replicas
in the controller code, specifically at [this line](emqx-operator/controllers/apps/v2beta1/update_emqx_status.go
Line 24 in 2f4089d
Replicas
field if it is not specified.To fix this:
instance.Spec.CoreTemplate.Spec.Replicas
is checked fornil
before dereferencing.replicas
is provided during CRD creation.Environment Details:
The text was updated successfully, but these errors were encountered: