Skip to content

Commit

Permalink
Apply strategic overrides last (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
agouin committed Jan 29, 2024
1 parent b6c4970 commit d0ee04b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 27 deletions.
35 changes: 8 additions & 27 deletions internal/fullnode/build_pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,24 @@ const (
// BuildPods creates the final state of pods given the crd.
func BuildPods(crd *cosmosv1.CosmosFullNode, cksums ConfigChecksums) ([]diff.Resource[*corev1.Pod], error) {
var (
builder = NewPodBuilder(crd)
overrides = crd.Spec.InstanceOverrides
pods []diff.Resource[*corev1.Pod]
builder = NewPodBuilder(crd)
pods []diff.Resource[*corev1.Pod]
)
candidates := podCandidates(crd)
for i := int32(0); i < crd.Spec.Replicas; i++ {
pod, err := builder.WithOrdinal(i).Build()
if err != nil {
return nil, err
}
if _, shouldSnapshot := candidates[pod.Name]; shouldSnapshot {

if pod == nil {
continue
}
if len(crd.Spec.ChainSpec.Versions) > 0 {
instanceHeight := uint64(0)
if height, ok := crd.Status.Height[pod.Name]; ok {
instanceHeight = height
}
var image string
for _, version := range crd.Spec.ChainSpec.Versions {
if instanceHeight < version.UpgradeHeight {
break
}
image = version.Image
}
if image != "" {
setChainContainerImage(pod, image)
}
}
if o, ok := overrides[pod.Name]; ok {
if o.DisableStrategy != nil {
continue
}
if o.Image != "" {
setChainContainerImage(pod, o.Image)
}

if _, shouldSnapshot := candidates[pod.Name]; shouldSnapshot {
continue
}

pod.Annotations[configChecksumAnnotation] = cksums[client.ObjectKeyFromObject(pod)]
pods = append(pods, diff.Adapt(pod, i))
}
Expand Down
27 changes: 27 additions & 0 deletions internal/fullnode/pod_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,36 @@ func podReadinessProbes(crd *cosmosv1.CosmosFullNode) []*corev1.Probe {
// Build assigns the CosmosFullNode crd as the owner and returns a fully constructed pod.
func (b PodBuilder) Build() (*corev1.Pod, error) {
pod := b.pod.DeepCopy()

if len(b.crd.Spec.ChainSpec.Versions) > 0 {
instanceHeight := uint64(0)
if height, ok := b.crd.Status.Height[pod.Name]; ok {
instanceHeight = height
}
var image string
for _, version := range b.crd.Spec.ChainSpec.Versions {
if instanceHeight < version.UpgradeHeight {
break
}
image = version.Image
}
if image != "" {
setChainContainerImage(pod, image)
}
}
if o, ok := b.crd.Spec.InstanceOverrides[pod.Name]; ok {
if o.DisableStrategy != nil {
return nil, nil
}
if o.Image != "" {
setChainContainerImage(pod, o.Image)
}
}

if err := kube.ApplyStrategicMergePatch(pod, podPatch(b.crd)); err != nil {
return nil, err
}

kube.NormalizeMetadata(&pod.ObjectMeta)
return pod, nil
}
Expand Down

0 comments on commit d0ee04b

Please sign in to comment.