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

commit 35708255bbe84dbe92538f33aee8101036dcf435
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Fri Jul 28 14:52:17 2023 +0200

    fix(cmd): don't validate on dry-run
    
    Closes #4534
---
 pkg/cmd/promote.go      | 52 ++++++++++++++++++++++++++++---------------------
 pkg/cmd/promote_test.go |  7 ++-----
 2 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/pkg/cmd/promote.go b/pkg/cmd/promote.go
index b87170f73..e332f4da2 100644
--- a/pkg/cmd/promote.go
+++ b/pkg/cmd/promote.go
@@ -88,19 +88,23 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
        if err != nil {
                return fmt.Errorf("could not retrieve cluster client: %w", err)
        }
-       opSource, err := operatorInfo(o.Context, c, o.Namespace)
-       if err != nil {
-               return fmt.Errorf("could not retrieve info for Camel K operator 
source: %w", err)
-       }
-       opDest, err := operatorInfo(o.Context, c, o.To)
-       if err != nil {
-               return fmt.Errorf("could not retrieve info for Camel K operator 
destination: %w", err)
-       }
+       if o.OutputFormat == "" {
+               // Skip these checks if in dry mode
+               opSource, err := operatorInfo(o.Context, c, o.Namespace)
+               if err != nil {
+                       return fmt.Errorf("could not retrieve info for Camel K 
operator source: %w", err)
+               }
+               opDest, err := operatorInfo(o.Context, c, o.To)
+               if err != nil {
+                       return fmt.Errorf("could not retrieve info for Camel K 
operator destination: %w", err)
+               }
 
-       err = checkOpsCompatibility(cmd, opSource, opDest)
-       if err != nil {
-               return fmt.Errorf("could not verify operators compatibility: 
%w", err)
+               err = checkOpsCompatibility(cmd, opSource, opDest)
+               if err != nil {
+                       return fmt.Errorf("could not verify operators 
compatibility: %w", err)
+               }
        }
+
        promotePipe := false
        var sourceIntegration *v1.Integration
        // We first look if a Pipe with the name exists
@@ -118,41 +122,45 @@ func (o *promoteCmdOptions) run(cmd *cobra.Command, args 
[]string) error {
        if sourceIntegration.Status.Phase != v1.IntegrationPhaseRunning {
                return fmt.Errorf("could not promote an Integration in %s 
status", sourceIntegration.Status.Phase)
        }
-       err = o.validateDestResources(c, sourceIntegration)
-       if err != nil {
-               return fmt.Errorf("could not validate destination resources: 
%w", err)
+
+       if o.OutputFormat == "" {
+               // Skip these checks if in dry mode
+               err = o.validateDestResources(c, sourceIntegration)
+               if err != nil {
+                       return fmt.Errorf("could not validate destination 
resources: %w", err)
+               }
        }
 
        // Pipe promotion
        if promotePipe {
                destPipe := o.editPipe(sourcePipe, sourceIntegration)
+               if o.OutputFormat != "" {
+                       return showPipeOutput(cmd, destPipe, o.OutputFormat, 
c.GetScheme())
+               }
                // Ensure the destination namespace has access to the source 
namespace images
                err = addSystemPullerRoleBinding(o.Context, c, 
sourceIntegration.Namespace, destPipe.Namespace)
                if err != nil {
                        return err
                }
                replaced, err := o.replaceResource(destPipe)
-               if o.OutputFormat != "" {
-                       return showPipeOutput(cmd, destPipe, o.OutputFormat, 
c.GetScheme())
-               }
                if !replaced {
-                       fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration 
"`+name+`" created`)
+                       fmt.Fprintln(cmd.OutOrStdout(), `Promoted Pipe 
"`+name+`" created`)
                } else {
-                       fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration 
"`+name+`" updated`)
+                       fmt.Fprintln(cmd.OutOrStdout(), `Promoted Pipe 
"`+name+`" updated`)
                }
                return err
        }
 
        // Plain Integration promotion
        destIntegration := o.editIntegration(sourceIntegration)
+       if o.OutputFormat != "" {
+               return showIntegrationOutput(cmd, destIntegration, 
o.OutputFormat)
+       }
        // Ensure the destination namespace has access to the source namespace 
images
        err = addSystemPullerRoleBinding(o.Context, c, 
sourceIntegration.Namespace, destIntegration.Namespace)
        if err != nil {
                return err
        }
-       if o.OutputFormat != "" {
-               return showIntegrationOutput(cmd, destIntegration, 
o.OutputFormat)
-       }
        replaced, err := o.replaceResource(destIntegration)
        if !replaced {
                fmt.Fprintln(cmd.OutOrStdout(), `Promoted Integration 
"`+name+`" created`)
diff --git a/pkg/cmd/promote_test.go b/pkg/cmd/promote_test.go
index de35de413..22529788a 100644
--- a/pkg/cmd/promote_test.go
+++ b/pkg/cmd/promote_test.go
@@ -65,9 +65,8 @@ func TestIntegrationNotCompatible(t *testing.T) {
        srcCatalog := createTestCamelCatalog(srcPlatform)
        dstCatalog := createTestCamelCatalog(dstPlatform)
 
-       promoteCmdOptions, promoteCmd, _ := initializePromoteCmdOptions(t, 
&srcPlatform, &dstPlatform, &defaultIntegration, &srcCatalog, &dstCatalog)
-       _, err := test.ExecuteCommand(promoteCmd, cmdPromote, "my-it-test", 
"--to", "prod-namespace", "-o", "yaml", "-n", "default")
-       assert.Equal(t, "yaml", promoteCmdOptions.OutputFormat)
+       _, promoteCmd, _ := initializePromoteCmdOptions(t, &srcPlatform, 
&dstPlatform, &defaultIntegration, &srcCatalog, &dstCatalog)
+       _, err := test.ExecuteCommand(promoteCmd, cmdPromote, "my-it-test", 
"--to", "prod-namespace", "-n", "default")
        assert.NotNil(t, err)
        assert.Equal(t,
                fmt.Sprintf("could not verify operators compatibility: source 
(%s) and destination (0.0.1) Camel K operator versions are not compatible", 
defaults.Version),
@@ -137,7 +136,6 @@ metadata:
   creationTimestamp: null
   name: my-kb-test
   namespace: prod-namespace
-  resourceVersion: "1"
 spec:
   integration:
     traits:
@@ -238,7 +236,6 @@ metadata:
     my-label: my-value
   name: my-kb-test
   namespace: prod-namespace
-  resourceVersion: "1"
 spec:
   integration:
     traits:

Reply via email to