Skip to content

Commit

Permalink
Update configmap , key peer and service builders to use correct ordin…
Browse files Browse the repository at this point in the history
…als values
  • Loading branch information
vimystic committed Nov 20, 2024
1 parent 4a11667 commit 3c8739e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
7 changes: 4 additions & 3 deletions internal/fullnode/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions internal/fullnode/node_key_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion internal/fullnode/peer_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/fullnode/service_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 3c8739e

Please sign in to comment.