diff --git a/internal/fullnode/configmap_builder.go b/internal/fullnode/configmap_builder.go index af9bbb51..45aa0f0e 100644 --- a/internal/fullnode/configmap_builder.go +++ b/internal/fullnode/configmap_builder.go @@ -26,12 +26,13 @@ const ( func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource[*corev1.ConfigMap], error) { var ( buf = bufPool.Get().(*bytes.Buffer) - cms = make([]diff.Resource[*corev1.ConfigMap], crd.Spec.Replicas) + cms = make([]diff.Resource[*corev1.ConfigMap], 0, crd.Spec.Replicas) ) defer bufPool.Put(buf) defer buf.Reset() + startOrdinal := crd.Spec.Ordinal.Start - for i := int32(0); i < crd.Spec.Replicas; i++ { + for i := startOrdinal; i < startOrdinal+crd.Spec.Replicas; i++ { data := make(map[string]string) instance := instanceName(crd, i) if err := addConfigToml(buf, data, crd, instance, peers); err != nil { @@ -75,7 +76,7 @@ func BuildConfigMaps(crd *cosmosv1.CosmosFullNode, peers Peers) ([]diff.Resource ) cm.Data = data kube.NormalizeMetadata(&cm.ObjectMeta) - cms[i] = diff.Adapt(&cm, i) + cms = append(cms, diff.Adapt(&cm, int(i-startOrdinal))) } return cms, nil diff --git a/internal/fullnode/node_key_builder.go b/internal/fullnode/node_key_builder.go index 3ed330b8..bc2a8caf 100644 --- a/internal/fullnode/node_key_builder.go +++ b/internal/fullnode/node_key_builder.go @@ -20,8 +20,10 @@ const nodeKeyFile = "node_key.json" // If the secret already has a node key, it is reused. // Returns an error if a new node key cannot be serialized. (Should never happen.) func BuildNodeKeySecrets(existing []*corev1.Secret, crd *cosmosv1.CosmosFullNode) ([]diff.Resource[*corev1.Secret], error) { - secrets := make([]diff.Resource[*corev1.Secret], crd.Spec.Replicas) - for i := int32(0); i < crd.Spec.Replicas; i++ { + secrets := make([]diff.Resource[*corev1.Secret], 0, crd.Spec.Replicas) + startOrdinal := crd.Spec.Ordinal.Start + + for i := startOrdinal; i < startOrdinal+crd.Spec.Replicas; i++ { var s corev1.Secret s.Name = nodeKeySecretName(crd, i) s.Namespace = crd.Namespace @@ -52,7 +54,7 @@ func BuildNodeKeySecrets(existing []*corev1.Secret, crd *cosmosv1.CosmosFullNode } } - secrets[i] = diff.Adapt(&secret, i) + secrets = append(secrets, diff.Adapt(&secret, int(i-startOrdinal))) } return secrets, nil } diff --git a/internal/fullnode/peer_collector.go b/internal/fullnode/peer_collector.go index 37c27c3a..4247dba2 100644 --- a/internal/fullnode/peer_collector.go +++ b/internal/fullnode/peer_collector.go @@ -105,12 +105,14 @@ func NewPeerCollector(client Getter) *PeerCollector { // Collect peer information given the crd. func (c PeerCollector) Collect(ctx context.Context, crd *cosmosv1.CosmosFullNode) (Peers, kube.ReconcileError) { peers := make(Peers) + startOrdinal := crd.Spec.Ordinal.Start clusterDomain := "cluster.local" if crd.Spec.Service.ClusterDomain != nil { clusterDomain = *crd.Spec.Service.ClusterDomain } - for i := int32(0); i < crd.Spec.Replicas; i++ { + + for i := startOrdinal; i < startOrdinal+crd.Spec.Replicas; i++ { secretName := nodeKeySecretName(crd, i) var secret corev1.Secret // Hoping the caching layer kubebuilder prevents API errors or rate limits. Simplifies logic to use a Get here diff --git a/internal/fullnode/service_builder.go b/internal/fullnode/service_builder.go index 2831a12a..0c9aad32 100644 --- a/internal/fullnode/service_builder.go +++ b/internal/fullnode/service_builder.go @@ -31,9 +31,10 @@ func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service } maxExternal := lo.Clamp(max, 0, crd.Spec.Replicas) p2ps := make([]diff.Resource[*corev1.Service], crd.Spec.Replicas) + startOrdinal := crd.Spec.Ordinal.Start for i := int32(0); i < crd.Spec.Replicas; i++ { - ordinal := i + ordinal := startOrdinal + i var svc corev1.Service svc.Name = p2pServiceName(crd, ordinal) svc.Namespace = crd.Namespace @@ -66,7 +67,7 @@ func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service svc.Spec.ClusterIP = *valOrDefault(crd.Spec.Service.P2PTemplate.ClusterIP, ptr("")) } - p2ps[i] = diff.Adapt(&svc, i) + p2ps[i] = diff.Adapt(&svc, int(i)) } rpc := rpcService(crd)