This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 84d320cc4 feat(cmd): add gitops "all" profile
84d320cc4 is described below

commit 84d320cc4955faf8d9408215702feab6d72d55a2
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Sat Jan 31 14:21:20 2026 +0100

    feat(cmd): add gitops "all" profile
    
    Useful to include more Integrations in the same repo and be able to create 
a single CICD for all integrations
---
 pkg/cmd/promote_test.go   | 24 +++++++++++++++++++++
 pkg/util/gitops/gitops.go | 54 +++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 76 insertions(+), 2 deletions(-)

diff --git a/pkg/cmd/promote_test.go b/pkg/cmd/promote_test.go
index 4c55880db..9f4f65125 100644
--- a/pkg/cmd/promote_test.go
+++ b/pkg/cmd/promote_test.go
@@ -544,6 +544,13 @@ spec:
 status: {}
 `
 
+const allKustItContent = `apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: prod-namespace
+resources:
+- ../../../my-it-test/overlays/prod-namespace/
+`
+
 func TestIntegrationGitOps(t *testing.T) {
        srcPlatform := v1.NewIntegrationPlatform("default", 
platform.DefaultPlatformName)
        srcPlatform.Status.Version = defaults.Version
@@ -609,6 +616,11 @@ func TestIntegrationGitOps(t *testing.T) {
        patchIt, err := os.ReadFile(filepath.Join(tmpDir, "my-it-test", 
"overlays", "prod-namespace", "patch-integration.yaml"))
        require.NoError(t, err)
        assert.Equal(t, expectedGitOpsItPatch, string(patchIt))
+
+       // Verify also the "all" profile
+       allIts, err := os.ReadFile(filepath.Join(tmpDir, "all", "overlays", 
"prod-namespace", "kustomization.yaml"))
+       require.NoError(t, err)
+       assert.Equal(t, allKustItContent, string(allIts))
 }
 
 const expectedGitOpsPipe = `apiVersion: camel.apache.org/v1
@@ -696,6 +708,13 @@ spec:
 status: {}
 `
 
+const allKustPipeContent = `apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: prod-namespace
+resources:
+- ../../../my-pipe-test/overlays/prod-namespace/
+`
+
 func TestPipeGitOps(t *testing.T) {
        srcPlatform := v1.NewIntegrationPlatform("default", 
platform.DefaultPlatformName)
        srcPlatform.Status.Version = defaults.Version
@@ -769,4 +788,9 @@ func TestPipeGitOps(t *testing.T) {
        patchPipe, err := os.ReadFile(filepath.Join(tmpDir, "my-pipe-test", 
"overlays", "prod-namespace", "patch-pipe.yaml"))
        require.NoError(t, err)
        assert.Equal(t, expectedGitOpsPipePatch, string(patchPipe))
+
+       // Verify also the "all" profile
+       allPipes, err := os.ReadFile(filepath.Join(tmpDir, "all", "overlays", 
"prod-namespace", "kustomization.yaml"))
+       require.NoError(t, err)
+       assert.Equal(t, allKustPipeContent, string(allPipes))
 }
diff --git a/pkg/util/gitops/gitops.go b/pkg/util/gitops/gitops.go
index 330021585..c28efd764 100644
--- a/pkg/util/gitops/gitops.go
+++ b/pkg/util/gitops/gitops.go
@@ -275,7 +275,57 @@ patches:
                }
        }
 
-       return err
+       return createOrAppendAll(destinationDir, dstIt.Name, namespaceDest)
+}
+
+// createOrAppendAll create or append this integration into an "all" 
directory. Useful for
+// those CICD which wants to include all Integrations at once.
+func createOrAppendAll(destinationDir, resourceName, resourceNamespace string) 
error {
+       allpath := filepath.Join(destinationDir, "all", "overlays", 
resourceNamespace)
+       err := os.MkdirAll(allpath, io.FilePerm755)
+       if err != nil {
+               return err
+       }
+       kustomizeFile := filepath.Join(allpath, "kustomization.yaml")
+       if _, err = os.Stat(kustomizeFile); err != nil && !os.IsNotExist(err) {
+               return err
+       }
+       resource := "- ../../../" + resourceName + "/overlays/" + 
resourceNamespace + "/"
+       //nolint:nestif
+       if os.IsNotExist(err) {
+               // does not exist, create a new file
+               kustCnt := `apiVersion: kustomize.config.k8s.io/v1beta1
+kind: Kustomization
+namespace: ` + resourceNamespace + `
+resources:
+- ../../../` + resourceName + `/overlays/` + resourceNamespace + `/
+`
+               if err := os.WriteFile(kustomizeFile, []byte(kustCnt), 
io.FilePerm755); err != nil {
+                       return err
+               }
+       } else {
+               // Append this integration with overlay (if it does not exist 
already)
+               data, err := os.ReadFile(kustomizeFile)
+               if err != nil {
+                       return nil
+               }
+
+               contentStr := string(data)
+
+               if !strings.Contains(contentStr, resource) {
+                       f, err := os.OpenFile(kustomizeFile, 
os.O_APPEND|os.O_WRONLY, io.FilePerm755)
+                       if err != nil {
+                               return nil
+                       }
+                       defer f.Close()
+
+                       if _, err := f.WriteString(resource); err != nil {
+                               return err
+                       }
+               }
+       }
+
+       return nil
 }
 
 func dirExists(path string) bool {
@@ -416,7 +466,7 @@ patches:
                }
        }
 
-       return err
+       return createOrAppendAll(destinationDir, dstPipe.Name, namespaceDest)
 }
 
 // GitToken read the first secret data provided by the Integration Git Secret.

Reply via email to