Skip to content

Commit

Permalink
operator: k8s: Move ordinal extraction to seperated function
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Korepta committed Jan 4, 2023
1 parent ff9da71 commit 836e938
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion controllers/redpanda/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ func (r *ClusterReconciler) fetchAdminNodeID(ctx context.Context, rp *redpandav1
return -1, fmt.Errorf("creating pki: %w", err)
}

ordinal, err := strconv.ParseInt(pod.Name[len(rp.Name)+1:], 10, 0)
ordinal, err := strconv.ParseInt(getPodOrdinal(pod.Name, rp.Name), 10, 0)
if err != nil {
return -1, fmt.Errorf("cluster %s: cannot convert pod name (%s) to ordinal: %w", rp.Name, pod.Name, err)
}
Expand All @@ -567,6 +567,16 @@ func (r *ClusterReconciler) fetchAdminNodeID(ctx context.Context, rp *redpandav1
return int32(cfg.NodeID), nil
}

func getPodOrdinal(podName string, clusterName string) string {
// Pod name needs to have at least 2 more characters
if len(podName) < len(clusterName)+2 {
return ""
}

// The +1 is for the separator between stateful set name and pod ordinal
return podName[len(clusterName)+1:]
}

func (r *ClusterReconciler) reportStatus(
ctx context.Context,
redpandaCluster *redpandav1alpha1.Cluster,
Expand Down

0 comments on commit 836e938

Please sign in to comment.