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

feature: support zarf image modification in reconciliation #500

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Added

- [PR #476](https://github.com/konpyutaika/nifikop/pull/476) - **[Operator/NifiCluster]** Added logic to include injected containers and init containers in desired pod spec.
- [PR #500](https://github.com/konpyutaika/nifikop/pull/500) - **[Operator/NiFiCluster]** Added support for [Zarf](https://zarf.dev/) patched container images

### Changed

Expand Down
28 changes: 28 additions & 0 deletions pkg/resources/nifi/nifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,34 @@ func (r *Reconciler) reconcileNifiPod(log zap.Logger, desiredPod *corev1.Pod) (e
}
currentPod.Spec.Containers = currentContainers
}
// Patch image name if Zarf has modified the pod spec
if _, ok := currentPod.Labels["zarf-agent"]; ok {
var oldImage, currentImage string
for _, c := range currentPod.Spec.Containers {
if c.Name == "nifi" {
imageChunks := strings.Split(c.Image, "/")
oldTag := strings.Split(imageChunks[len(imageChunks)-1], "-zarf")[0]
oldRepoChunks := imageChunks[1 : len(imageChunks)-1]
oldImage = fmt.Sprintf("%s/%s", strings.Join(oldRepoChunks, "/"), oldTag)
currentImage = c.Image
}
}
log.Debug("Patching Nifi container image for Zarf",
zap.String("current", currentImage),
zap.String("original", oldImage))
desiredContainers := []corev1.Container{}
for _, c := range desiredPod.Spec.Containers {
if c.Name == "nifi" {
// If the incoming image matches the spec from before the zarf patch then the pod is in sync
if c.Image == oldImage {
// We want to prevent a reconcile loop by setting the incoming image to the zarf image spec
c.Image = currentImage
}
}
desiredContainers = append(desiredContainers, c)
}
desiredPod.Spec.Containers = desiredContainers
}
// Check if the resource actually updated
patchResult, err := patch.DefaultPatchMaker.Calculate(currentPod, desiredPod, opts...)
if err != nil {
Expand Down