Skip to content

Commit

Permalink
make for loops consistent across all builders
Browse files Browse the repository at this point in the history
  • Loading branch information
vimystic committed Dec 4, 2024
1 parent e0afa9b commit 4595139
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
10 changes: 5 additions & 5 deletions internal/fullnode/pvc_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ func BuildPVCs(
}

var pvcs []diff.Resource[*corev1.PersistentVolumeClaim]
for i := int32(0); i < crd.Spec.Replicas; i++ {
ordinal := i + crd.Spec.Ordinals.Start
if pvcDisabled(crd, ordinal) {
for i := crd.Spec.Ordinals.Start; i < crd.Spec.Ordinals.Start+crd.Spec.Replicas; i++ {

if pvcDisabled(crd, i) {
continue
}

pvc := base.DeepCopy()
name := pvcName(crd, ordinal)
name := pvcName(crd, i)
pvc.Name = name
podName := instanceName(crd, ordinal)
podName := instanceName(crd, i)
pvc.Labels[kube.InstanceLabel] = podName

var dataSource *corev1.TypedLocalObjectReference
Expand Down
7 changes: 3 additions & 4 deletions internal/fullnode/pvc_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ func (control PVCControl) Reconcile(ctx context.Context, reporter kube.Reporter,

dataSources := make(map[int32]*dataSource)
if len(currentPVCs) < int(crd.Spec.Replicas) {
for i := int32(0); i < crd.Spec.Replicas; i++ {
ordinal := i + crd.Spec.Ordinals.Start
name := pvcName(crd, ordinal)
for i := crd.Spec.Ordinals.Start; i < crd.Spec.Ordinals.Start+crd.Spec.Replicas; i++ {
name := pvcName(crd, i)
found := false
for _, pvc := range currentPVCs {
if pvc.Name == name {
Expand All @@ -62,7 +61,7 @@ func (control PVCControl) Reconcile(ctx context.Context, reporter kube.Reporter,
}
}
if !found {
ds := control.findDataSource(ctx, reporter, crd, ordinal)
ds := control.findDataSource(ctx, reporter, crd, i)
if ds == nil {
ds = &dataSource{
size: crd.Spec.VolumeClaimTemplate.Resources.Requests[corev1.ResourceStorage],
Expand Down
11 changes: 4 additions & 7 deletions internal/fullnode/service_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@ 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.Ordinals.Start

for i := int32(0); i < crd.Spec.Replicas; i++ {
ordinal := startOrdinal + i
for i := crd.Spec.Ordinals.Start; i < crd.Spec.Ordinals.Start+crd.Spec.Replicas; i++ {
var svc corev1.Service
svc.Name = p2pServiceName(crd, ordinal)
svc.Name = p2pServiceName(crd, i)
svc.Namespace = crd.Namespace
svc.Kind = "Service"
svc.APIVersion = "v1"

svc.Labels = defaultLabels(crd,
kube.InstanceLabel, instanceName(crd, ordinal),
kube.InstanceLabel, instanceName(crd, i),
kube.ComponentLabel, "p2p",
)
svc.Annotations = map[string]string{}
Expand All @@ -55,7 +52,7 @@ func BuildServices(crd *cosmosv1.CosmosFullNode) []diff.Resource[*corev1.Service
TargetPort: intstr.FromString("p2p"),
},
}
svc.Spec.Selector = map[string]string{kube.InstanceLabel: instanceName(crd, ordinal)}
svc.Spec.Selector = map[string]string{kube.InstanceLabel: instanceName(crd, i)}

if i < maxExternal {
preserveMergeInto(svc.Labels, crd.Spec.Service.P2PTemplate.Metadata.Labels)
Expand Down

0 comments on commit 4595139

Please sign in to comment.