Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply strategic overrides after image is set #405

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading