-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inject volumes into init-containers too
- Loading branch information
1 parent
9544552
commit a0e0ef3
Showing
2 changed files
with
79 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package patch | ||
|
||
import ( | ||
"strconv" | ||
|
||
json_patch "github.com/evanphx/json-patch" | ||
"github.com/flashbots/kube-sidecar-injector/operation" | ||
core_v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func AddInitContainerVolumeMounts( | ||
idx int, | ||
container *core_v1.Container, | ||
volumeMounts []core_v1.VolumeMount, | ||
) (json_patch.Patch, error) { | ||
if len(volumeMounts) == 0 { | ||
return nil, nil | ||
} | ||
|
||
res := make(json_patch.Patch, 0, len(volumeMounts)) | ||
|
||
notEmpty := len(container.VolumeMounts) > 0 | ||
for _, vm := range volumeMounts { | ||
var ( | ||
op json_patch.Operation | ||
err error | ||
) | ||
|
||
if notEmpty { | ||
op, err = operation.Add("/spec/initContainers/"+strconv.Itoa(idx)+"/volumeMounts/-", vm) | ||
} else { | ||
notEmpty = true | ||
op, err = operation.Add("/spec/initContainers/"+strconv.Itoa(idx)+"/volumeMounts", []core_v1.VolumeMount{vm}) | ||
} | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
res = append(res, op) | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters