Skip to content

Commit

Permalink
[release-1.13] Fix possible nil pointer dereferences on Consumer/Cons…
Browse files Browse the repository at this point in the history
…umerGroup (#3773)

* fix some possible nil pointer references

Signed-off-by: Calum Murray <[email protected]>

* default to 1 instead of 0

Signed-off-by: Calum Murray <[email protected]>

---------

Signed-off-by: Calum Murray <[email protected]>
Co-authored-by: Calum Murray <[email protected]>
  • Loading branch information
knative-prow-robot and Cali0707 authored Mar 20, 2024
1 parent 4291693 commit ead2a69
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (cg *ConsumerGroup) GetKey() types.NamespacedName {

// GetVReplicas implements scheduler.VPod interface.
func (cg *ConsumerGroup) GetVReplicas() int32 {
if cg.Spec.Replicas == nil {
return 1
}

return *cg.Spec.Replicas
}

Expand Down
12 changes: 11 additions & 1 deletion control-plane/pkg/reconciler/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ func (r *Reconciler) reconcileContractResource(ctx context.Context, c *kafkainte
}

egress.Reference = userFacingResourceRef
egress.VReplicas = *c.Spec.VReplicas
if c.Spec.VReplicas != nil {
egress.VReplicas = *c.Spec.VReplicas
} else {
egress.VReplicas = 1
}

resource := &contract.Resource{
Uid: string(c.UID),
Expand Down Expand Up @@ -332,6 +336,12 @@ func removeResource(_ *zap.Logger, ct *contract.Contract, c *kafkainternals.Cons
//
// The actual mutation is done by calling the provided contractMutatorFunc.
func (r *Reconciler) schedule(ctx context.Context, logger *zap.Logger, c *kafkainternals.Consumer, mutatorFunc contractMutatorFunc, shouldWait PodStatusWaitFunc) (bool, error) {
if c.Spec.PodBind == nil {
// No PodBind so Pod will not be found, return no error since the Consumer
// will get re-queued when the pod is added.
return false, nil
}

// Get the data plane pod when the Consumer should be scheduled.
p, err := r.PodLister.Pods(c.Spec.PodBind.PodNamespace).Get(c.Spec.PodBind.PodName)
if apierrors.IsNotFound(err) {
Expand Down

0 comments on commit ead2a69

Please sign in to comment.