Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 5d32b23

Browse files
author
Maya Baya
committed
fix: Make sure the placement is set to default
1 parent fc16cee commit 5d32b23

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pkg/apis/riotkit.org/v1alpha1/podfilesystemsync.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,23 @@ type InitContainerPlacementSpec struct {
109109
Placement ContainerPlacement `json:"placement,omitempty"`
110110
}
111111

112+
func (ic *InitContainerPlacementSpec) GetPlacement() ContainerPlacement {
113+
if ic.Placement == "" {
114+
return "last"
115+
}
116+
return ic.Placement
117+
}
118+
112119
func (ic *InitContainerPlacementSpec) Validate() error {
113-
if (ic.Placement == "before" || ic.Placement == "after") && ic.ContainerReference == "" {
120+
p := ic.GetPlacement()
121+
122+
if (p == "before" || p == "after") && ic.ContainerReference == "" {
114123
return errors.Errorf("Cannot place container as '%s' to unknown container, when containerReference is not specified. Specify .spec.initContainerPlacement.containerReference", ic.Placement)
115124
}
116-
if (ic.Placement == "last" || ic.Placement == "first") && ic.ContainerReference != "" {
117-
return errors.Errorf("Cannot specify .spec.initContainerPlacement.containerReference together with '%v'", ic.Placement)
125+
if (p == "last" || p == "first") && ic.ContainerReference != "" {
126+
return errors.Errorf("Cannot specify .spec.initContainerPlacement.containerReference together with '%v'", ic.GetPlacement())
118127
}
119-
if ic.Placement != "last" && ic.Placement != "first" && ic.Placement != "before" && ic.Placement != "after" {
128+
if p != "last" && p != "first" && p != "before" && p != "after" {
120129
return errors.Errorf(".spec.initContainerPlacement.Placement is not one of: last, first, before, after")
121130
}
122131
return nil

pkg/server/mutation/containers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,21 @@ func reorderInitContainer(containers []corev1.Container, containerName string, p
178178
copied = append(copied, container)
179179
}
180180

181-
if placement.Placement == "first" && foundAtIndex != 0 {
181+
if placement.GetPlacement() == "first" && foundAtIndex != 0 {
182182
return append([]corev1.Container{ourContainer}, copied...), nil
183183

184-
} else if placement.Placement == "last" && foundAtIndex+1 != len(containers) {
184+
} else if placement.GetPlacement() == "last" && foundAtIndex+1 != len(containers) {
185185
return append(copied, ourContainer), nil
186186

187-
} else if placement.Placement == "before" || placement.Placement == "after" {
187+
} else if placement.GetPlacement() == "before" || placement.GetPlacement() == "after" {
188188
var final []corev1.Container
189189

190190
for _, container := range copied {
191-
if container.Name == placement.ContainerReference && placement.Placement == "before" {
191+
if container.Name == placement.ContainerReference && placement.GetPlacement() == "before" {
192192
final = append(final, ourContainer)
193193
}
194194
final = append(final, container)
195-
if container.Name == placement.ContainerReference && placement.Placement == "after" {
195+
if container.Name == placement.ContainerReference && placement.GetPlacement() == "after" {
196196
final = append(final, ourContainer)
197197
}
198198
}

0 commit comments

Comments
 (0)