From 1081d08de1c61562efec4a797ba39c3e1ff20419 Mon Sep 17 00:00:00 2001 From: Nigel Foucha Date: Thu, 19 Dec 2024 17:09:22 -0500 Subject: [PATCH 1/2] feature: support zarf image modification in reconciliation --- pkg/resources/nifi/nifi.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pkg/resources/nifi/nifi.go b/pkg/resources/nifi/nifi.go index c758c6e280..46038127f1 100644 --- a/pkg/resources/nifi/nifi.go +++ b/pkg/resources/nifi/nifi.go @@ -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 { From 0a8dbc8cfefc34bd3fe33c1778306ed27ef736a0 Mon Sep 17 00:00:00 2001 From: Nigel Foucha Date: Thu, 19 Dec 2024 17:20:32 -0500 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e2f295e5d..932e72b690 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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