You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/08/19 09:53:26 UTC

[camel-k] branch 3445/rebuild-filtering updated (c7616dad9 -> 9c18699aa)

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

nfilotto pushed a change to branch 3445/rebuild-filtering
in repository https://gitbox.apache.org/repos/asf/camel-k.git


 discard c7616dad9 feat(cli): Force arguments for the rebuild command
     new 9c18699aa feat(cli): Force arguments for the rebuild command

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (c7616dad9)
            \
             N -- N -- N   refs/heads/3445/rebuild-filtering (9c18699aa)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pkg/cmd/rebuild.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[camel-k] 01/01: feat(cli): Force arguments for the rebuild command

Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

nfilotto pushed a commit to branch 3445/rebuild-filtering
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 9c18699aab8e47a0055c316d86e3d3a8b865f666
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Aug 19 11:43:03 2022 +0200

    feat(cli): Force arguments for the rebuild command
---
 pkg/cmd/rebuild.go         | 37 +++++++++++++++++++++-----
 pkg/cmd/rebuild_test.go    | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 pkg/resources/resources.go | 20 +++++++-------
 3 files changed, 107 insertions(+), 16 deletions(-)

diff --git a/pkg/cmd/rebuild.go b/pkg/cmd/rebuild.go
index 7ea427923..29ac8288a 100644
--- a/pkg/cmd/rebuild.go
+++ b/pkg/cmd/rebuild.go
@@ -27,6 +27,7 @@ import (
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/client"
+	"github.com/apache/camel-k/pkg/util/kubernetes"
 )
 
 func newCmdRebuild(rootCmdOptions *RootCmdOptions) (*cobra.Command, *rebuildCmdOptions) {
@@ -34,18 +35,41 @@ func newCmdRebuild(rootCmdOptions *RootCmdOptions) (*cobra.Command, *rebuildCmdO
 		RootCmdOptions: rootCmdOptions,
 	}
 	cmd := cobra.Command{
-		Use:     "rebuild [integration]",
+		Use:     "rebuild [integration1] [integration2] ...",
 		Short:   "Clear the state of integrations to rebuild them",
 		Long:    `Clear the state of one or more integrations causing a rebuild.`,
 		PreRunE: decode(&options),
-		RunE:    options.rebuild,
+		RunE: func(cmd *cobra.Command, args []string) error {
+			if err := options.validate(args); err != nil {
+				return err
+			}
+			if err := options.rebuild(cmd, args); err != nil {
+				fmt.Fprintln(cmd.ErrOrStderr(), err.Error())
+			}
+
+			return nil
+		},
 	}
 
+	cmd.Flags().Bool("all", false, "Rebuild all integrations")
+
 	return &cmd, &options
 }
 
 type rebuildCmdOptions struct {
 	*RootCmdOptions
+	RebuildAll bool `mapstructure:"all"`
+}
+
+func (command *rebuildCmdOptions) validate(args []string) error {
+	if command.RebuildAll && len(args) > 0 {
+		return errors.New("invalid combination: both all flag and named integrations are set")
+	}
+	if !command.RebuildAll && len(args) == 0 {
+		return errors.New("invalid combination: neither all flag nor named integrations are set")
+	}
+
+	return nil
 }
 
 func (o *rebuildCmdOptions) rebuild(cmd *cobra.Command, args []string) error {
@@ -55,11 +79,11 @@ func (o *rebuildCmdOptions) rebuild(cmd *cobra.Command, args []string) error {
 	}
 
 	var integrations []v1.Integration
-	if len(args) == 0 {
+	if o.RebuildAll {
 		if integrations, err = o.listAllIntegrations(c); err != nil {
 			return err
 		}
-	} else {
+	} else if len(args) > 0 {
 		if integrations, err = o.getIntegrations(c, args); err != nil {
 			return err
 		}
@@ -84,9 +108,10 @@ func (o *rebuildCmdOptions) listAllIntegrations(c client.Client) ([]v1.Integrati
 func (o *rebuildCmdOptions) getIntegrations(c client.Client, names []string) ([]v1.Integration, error) {
 	ints := make([]v1.Integration, 0, len(names))
 	for _, n := range names {
-		it := v1.NewIntegration(o.Namespace, n)
+		name := kubernetes.SanitizeName(n)
+		it := v1.NewIntegration(o.Namespace, name)
 		key := k8sclient.ObjectKey{
-			Name:      n,
+			Name:      name,
 			Namespace: o.Namespace,
 		}
 		if err := c.Get(o.Context, key, &it); err != nil {
diff --git a/pkg/cmd/rebuild_test.go b/pkg/cmd/rebuild_test.go
new file mode 100644
index 000000000..e6e0c95a4
--- /dev/null
+++ b/pkg/cmd/rebuild_test.go
@@ -0,0 +1,66 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package cmd
+
+import (
+	"testing"
+
+	"github.com/apache/camel-k/pkg/util/test"
+	"github.com/spf13/cobra"
+	"github.com/stretchr/testify/assert"
+)
+
+const cmdRebuild = "rebuild"
+
+// nolint: unparam
+func initializeRebuildCmdOptions(t *testing.T) (*rebuildCmdOptions, *cobra.Command, RootCmdOptions) {
+	t.Helper()
+
+	options, rootCmd := kamelTestPreAddCommandInit()
+	rebuildCmdOptions := addTestRebuildCmd(*options, rootCmd)
+	kamelTestPostAddCommandInit(t, rootCmd)
+
+	return rebuildCmdOptions, rootCmd, *options
+}
+
+func addTestRebuildCmd(options RootCmdOptions, rootCmd *cobra.Command) *rebuildCmdOptions {
+	// add a testing version of rebuild Command
+	rebuildCmd, rebuildOptions := newCmdRebuild(&options)
+	rebuildCmd.RunE = func(c *cobra.Command, args []string) error {
+		return nil
+	}
+	rebuildCmd.PostRunE = func(c *cobra.Command, args []string) error {
+		return nil
+	}
+	rebuildCmd.Args = test.ArbitraryArgs
+	rootCmd.AddCommand(rebuildCmd)
+	return rebuildOptions
+}
+
+func TestRebuildNonExistingFlag(t *testing.T) {
+	_, rootCmd, _ := initializeRebuildCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdRebuild, "--nonExistingFlag")
+	assert.NotNil(t, err)
+}
+
+func TestRebuildAllFlag(t *testing.T) {
+	rebuildCmdOptions, rootCmd, _ := initializeRebuildCmdOptions(t)
+	_, err := test.ExecuteCommand(rootCmd, cmdRebuild, "--all")
+	assert.Nil(t, err)
+	assert.Equal(t, true, rebuildCmdOptions.RebuildAll)
+}
diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index 44e677f71..f8419d0c9 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -138,23 +138,23 @@ var assets = func() http.FileSystem {
 		"/crd/bases/camel.apache.org_integrationplatforms.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_integrationplatforms.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 174371,
+			uncompressedSize: 177901,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\xdb\x36\xb6\x30\xfe\x7f\x3e\x05\xc6\xfd\x23\x4e\xc6\x92\x9b\xdd\xdb\xdd\x5e\xdf\xe9\x3c\x8f\xd7\x49\x5b\x37\x71\xec\x6b\x39\xb9\x77\xa7\xed\x54\x10\x79\x24\x21\x22\x01\x2e\x00\xca\x51\x7f\xfb\xfb\xee\xcf\xe0\x00\x20\x29\x89\x04\x29\xc9\x6f\x6d\xc4\xce\xec\xc6\x36\x01\x1e\x1c\x1c\x9c\x37\x9c\x97\xaf\x48\xef\xee\x9e\x67\x5f\x91\x77\x2c\x02\xae\x20\x26\x5a\x10\x3d\x05\x72\x9a\xd1\x68\x0a\x64\x20\xc6\xfa\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\xdb\x36\xb6\x30\x8e\xff\x9e\xbf\x02\xe3\xce\x9d\x38\x19\x49\x4e\xba\xb7\xbb\xbd\x7e\xa6\xf3\x3c\xae\x93\xb6\x6e\xe2\xd8\xd7\x76\x72\xef\x4e\xdb\xa9\x20\xf2\x48\x42\x4c\x02\x5c\x00\x94\xad\x7e\xf7\xfb\xbf\x7f\x06\x07\x00\x49\x49\x24\x48\x49\x7e\x6b\x23\x76\x66\x37\xb6\x09\xf0\xe0\xe0\xe0\xbc\xe1\xbc\x7c\x45\xfa\x77\xf7\x3c\xfb\x8a\xbc\x67\x11\x70\x05\x31\xd1\x82\xe8\x29\x90\xa3\x8c\x46\x53\x20\x97\x62\x [...]
 		},
 		"/crd/bases/camel.apache.org_integrations.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_integrations.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 470929,
+			uncompressedSize: 472694,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x37\xf6\x28\xf8\xbf\x3f\x05\x4a\x49\x5d\x49\x13\x91\xb2\x33\x73\x53\xbf\xf1\x4e\xdd\x94\x46\x92\x13\x6d\x6c\x99\x65\x29\xc9\x4d\x39\x9e\x04\xec\x06\x49\x5c\x35\x81\x1e\x00\x4d\x89\xbf\xf5\x7e\xf7\x2d\x1c\x00\xfd\xe0\xab\x0f\x5a\xa2\xe3\xcc\x36\xa6\x6a\x62\x52\xec\xd3\x78\x1c\x9c\xf7\xe3\x0b\x32\x78\xba\xf1\xec\x0b\xf2\x9a\x27\x4c\x68\x96\x12\x23\x89\x99\x31\x72\x96\xd3\x64\xc6\xc8\x8d\x9c\x98\x7b\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\x37\xf6\x28\xf8\xbf\x3f\x05\x4a\x49\x5d\x49\x13\x91\xb2\x33\x73\x53\xbf\xf1\x4e\xdd\x94\x46\x92\x13\x6d\x6c\x99\x65\x29\xc9\x4d\x39\x9e\x04\xec\x06\x49\x5c\x35\x81\x1e\x00\x4d\x89\xbf\xf5\x7e\xf7\x2d\x1c\x00\xfd\xe0\xab\x0f\x5a\xa2\xe3\xcc\x36\xa6\x6a\x62\x52\xec\xd3\x78\x1c\x9c\xf7\xe3\x0b\x32\x78\xba\xf1\xec\x0b\xf2\x9a\x27\x4c\x68\x96\x12\x23\x89\x99\x31\x72\x96\xd3\x64\xc6\xc8\x8d\x9c\x98\x7b\x [...]
 		},
 		"/crd/bases/camel.apache.org_kameletbindings.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_kameletbindings.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 543879,
+			uncompressedSize: 545786,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\x1b\x37\xb2\x2f\x8c\xff\xee\xbf\x02\x25\xa7\xae\xa4\x13\x92\xb2\xb3\xbb\xa9\xb3\xfe\x6e\xdd\x94\x56\x96\x13\x7d\x63\xcb\x2c\x4b\x71\x6e\xca\xc9\x49\xc0\x19\x90\xc4\xd5\x10\x98\x05\x30\x94\xb8\x8f\x9f\xff\xfd\x29\x34\x80\x79\xe1\x9b\xd0\x43\x51\x51\x36\x83\x53\x75\x36\x92\x35\x3d\x18\x00\xdd\xe8\xee\x4f\xbf\x3c\x27\xfd\x87\x1b\xcf\x9e\x93\xb7\x3c\x61\x42\xb3\x94\x18\x49\xcc\x94\x91\xd3\x9c\x26\x53\x46\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xfd\xfd\x73\x1b\x37\xb2\x2f\x8c\xff\xee\xbf\x02\x25\xa7\xae\xa4\x13\x92\xb2\xb3\xbb\xa9\xb3\xfe\x6e\xdd\x94\x56\x96\x13\x7d\x63\xcb\x2c\x4b\x71\x6e\xca\xc9\x49\xc0\x19\x90\xc4\xd5\x10\x98\x05\x30\x94\xb8\x8f\x9f\xff\xfd\x29\x34\x80\x79\xe1\x9b\xd0\x43\x51\x51\x36\x83\x53\x75\x36\x92\x35\x3d\x18\x00\xdd\xe8\xee\x4f\xbf\x3c\x27\xfd\x87\x1b\xcf\x9e\x93\xb7\x3c\x61\x42\xb3\x94\x18\x49\xcc\x94\x91\xd3\x9c\x26\x53\x46\x [...]
 		},
 		"/crd/bases/camel.apache.org_kamelets.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "camel.apache.org_kamelets.yaml",
@@ -420,9 +420,9 @@ var assets = func() http.FileSystem {
 		"/rbac/operator-role.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "operator-role.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 2928,
+			uncompressedSize: 2952,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x56\xc1\x6e\xe3\x36\x10\xbd\xeb\x2b\x06\xd6\x65\x17\x88\xed\xb6\xa7\xc2\x3d\xb9\xbb\x49\x6b\x74\x61\x03\x91\xb7\x8b\x3d\x8e\xc8\xb1\x3c\x35\xc5\x61\x49\x2a\x8e\xfb\xf5\x05\x65\x29\x76\x22\x3b\x28\xba\x8b\x6e\x7d\x09\x45\x4e\xde\xbc\x79\xef\x51\x50\x0e\xe3\xaf\xf7\xcb\x72\xf8\xc0\x8a\x6c\x20\x0d\x51\x20\x6e\x09\xe6\x0e\xd5\x96\xa0\x90\x4d\xdc\xa3\x27\xb8\x93\xc6\x6a\x8c\x2c\x16\xde\xcc\x8b\xbb\xb7\xd0\x58\x4d\x1e\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x56\xc1\x6e\xdb\x46\x10\xbd\xf3\x2b\x06\xe2\x25\x01\x2c\xa9\xed\xa9\x50\x4f\x6a\x62\xb7\x42\x03\x09\xb0\x94\x06\x39\x0e\x97\x23\x6a\xaa\xe5\xce\x76\x76\x69\x59\xfd\xfa\x62\x29\x32\x92\x4d\x2b\x28\x9a\xa0\xa9\x2e\x5e\xee\x8e\xdf\xbc\x79\xef\x2d\xc1\x1c\xc6\x5f\xef\x97\xe5\xf0\x8e\x0d\xb9\x40\x25\x44\x81\xb8\x23\x98\x7b\x34\x3b\x82\xb5\x6c\xe3\x01\x95\xe0\x4e\x1a\x57\x62\x64\x71\xf0\x6a\xbe\xbe\x7b\x0d\x8d\x2b\x49\x [...]
 		},
 		"/rbac/patch-role-to-clusterrole.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "patch-role-to-clusterrole.yaml",
@@ -604,9 +604,9 @@ var assets = func() http.FileSystem {
 		"/traits.yaml": &vfsgen۰CompressedFileInfo{
 			name:             "traits.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 51862,
+			uncompressedSize: 53036,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfb\x73\x1b\xb9\xd1\xe0\xef\xfb\x57\xa0\x94\xab\xb2\xa4\x22\x29\xef\xe6\x4b\xb2\xa7\xbb\xfd\x72\x5a\xdb\x9b\x68\xd7\x0f\x9d\xa5\xdd\x7c\x29\x9f\x2b\x04\x67\x9a\x24\xcc\x21\x30\x01\x30\x92\x99\xcb\xfd\xef\x57\xe8\x6e\x3c\x86\x0f\x89\xb2\xad\xbd\xe8\xea\xcb\x56\xc5\x22\x39\x03\x34\x1a\xdd\x8d\x7e\xc3\x5b\xa9\xbc\x3b\xfd\x6a\x28\xb4\x5c\xc2\xa9\xf8\xad\xab\x64\x03\x5f\x09\xd1\x36\xd2\x4f\x8d\x5d\x9e\x8a\xa9\x6c\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7b\x73\x1b\xb9\xb5\x20\xfe\xff\x7c\x0a\x94\xee\xef\x96\x25\x17\x49\x79\x26\x77\x72\xe7\xa7\xdd\xb9\x59\x8d\xed\x49\x34\xe3\x87\xd6\xf2\x4c\x6e\xca\xeb\x0a\xc1\x6e\x90\x84\xd9\x04\x3a\x00\x5a\x32\xb3\xd9\xef\xbe\x85\xf3\x00\xd0\x64\x4b\xa2\x6c\x6b\x36\xda\xda\x4c\x55\x2c\x92\xdd\xc0\xc1\xc1\x39\x07\xe7\x8d\xe0\xa4\x0e\xfe\xe4\xab\xb1\x30\x72\xad\x4e\xc4\xef\x7c\x25\x1b\xf5\x95\x10\x6d\x23\xc3\xdc\xba\xf5\x89\x [...]
 		},
 	}
 	fs["/"].(*vfsgen۰DirInfo).entries = []os.FileInfo{