-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
loop over init containers as well #96
Closed
asad-awadia
wants to merge
7
commits into
estahn:main
from
asad-awadia:issue-73-handle-init-containers
Closed
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
82240cc
loop over init containers as well
asad-awadia 471fb60
fix container swap
asad-awadia d6e70ce
refactor out into function
asad-awadia e3547a1
change to containers[i]
asad-awadia 36d4bfc
rename function
asad-awadia 8c03449
resolve merge conflict
asad-awadia d1b4e7a
check return
asad-awadia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||||
---|---|---|---|---|---|---|
|
@@ -33,7 +33,7 @@ type ImageSwapper struct { | |||||
filters []config.JMESPathFilter | ||||||
|
||||||
// copier manages the jobs copying the images to the target registry | ||||||
copier *pond.WorkerPool | ||||||
copier *pond.WorkerPool | ||||||
|
||||||
imageSwapPolicy types.ImageSwapPolicy | ||||||
imageCopyPolicy types.ImageCopyPolicy | ||||||
|
@@ -42,9 +42,9 @@ type ImageSwapper struct { | |||||
// NewImageSwapper returns a new ImageSwapper initialized. | ||||||
func NewImageSwapper(registryClient registry.Client, filters []config.JMESPathFilter, imageSwapPolicy types.ImageSwapPolicy, imageCopyPolicy types.ImageCopyPolicy) mutating.Mutator { | ||||||
return &ImageSwapper{ | ||||||
registryClient: registryClient, | ||||||
filters: filters, | ||||||
copier: pond.New(100, 1000), | ||||||
registryClient: registryClient, | ||||||
filters: filters, | ||||||
copier: pond.New(100, 1000), | ||||||
imageSwapPolicy: imageSwapPolicy, | ||||||
imageCopyPolicy: imageCopyPolicy, | ||||||
} | ||||||
|
@@ -90,10 +90,15 @@ func (p *ImageSwapper) Mutate(ctx context.Context, obj metav1.Object) (bool, err | |||||
Logger() | ||||||
//spew.Dump() | ||||||
|
||||||
lctx := logger. | ||||||
WithContext(ctx) | ||||||
lctx := logger.WithContext(ctx) | ||||||
|
||||||
for i, container := range pod.Spec.Containers { | ||||||
p.replaceContainerImages(lctx, ar, pod, pod.Spec.Containers) | ||||||
p.replaceContainerImages(lctx, ar, pod, pod.Spec.InitContainers) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
return false, nil | ||||||
} | ||||||
|
||||||
func (p *ImageSwapper) replaceContainerImages(lctx context.Context, ar *v1beta1.AdmissionRequest, pod *corev1.Pod, containers []corev1.Container) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
for i, container := range containers { | ||||||
srcRef, err := alltransports.ParseImageName("docker://" + container.Image) | ||||||
if err != nil { | ||||||
log.Ctx(lctx).Warn().Msgf("invalid source name %s: %v", container.Image, err) | ||||||
|
@@ -152,18 +157,16 @@ func (p *ImageSwapper) Mutate(ctx context.Context, obj metav1.Object) (bool, err | |||||
switch p.imageSwapPolicy { | ||||||
case types.ImageSwapPolicyAlways: | ||||||
log.Ctx(lctx).Debug().Str("image", targetImage).Msg("set new container image") | ||||||
pod.Spec.Containers[i].Image = targetImage | ||||||
containers[i].Image = targetImage | ||||||
case types.ImageSwapPolicyExists: | ||||||
if p.registryClient.ImageExists(targetImage) { | ||||||
log.Ctx(lctx).Debug().Str("image", targetImage).Msg("set new container image") | ||||||
pod.Spec.Containers[i].Image = targetImage | ||||||
containers[i].Image = targetImage | ||||||
} | ||||||
default: | ||||||
panic("unknown imageSwapPolicy") | ||||||
} | ||||||
} | ||||||
|
||||||
return false, nil | ||||||
} | ||||||
|
||||||
// filterMatch returns true if one of the filters matches the context | ||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.