You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/11/25 07:57:11 UTC

[camel-k] 06/06: chore(lint): fix findings

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

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

commit bb51a9984e0d58aa134b110fc212c9d30d9b1788
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Wed Nov 24 16:05:05 2021 +0100

    chore(lint): fix findings
---
 pkg/cmd/run.go               |  4 ++--
 pkg/cmd/run_help.go          | 16 ++++++++--------
 pkg/cmd/util_content_test.go | 12 ++++++------
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go
index ba01178..153c13c 100644
--- a/pkg/cmd/run.go
+++ b/pkg/cmd/run.go
@@ -570,7 +570,7 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 
 	for _, resource := range o.Resources {
 		if config, parseErr := ParseResourceOption(resource); parseErr == nil {
-			if applyResourceOptionErr := ApplyResourceOption(config, &integration.Spec, c, namespace, o.Compression); applyResourceOptionErr != nil {
+			if applyResourceOptionErr := ApplyResourceOption(o.Context, config, &integration.Spec, c, namespace, o.Compression); applyResourceOptionErr != nil {
 				return nil, applyResourceOptionErr
 			}
 		} else {
@@ -621,7 +621,7 @@ func (o *runCmdOptions) createOrUpdateIntegration(cmd *cobra.Command, c client.C
 
 	for _, item := range o.Configs {
 		if config, parseErr := ParseConfigOption(item); parseErr == nil {
-			if applyConfigOptionErr := ApplyConfigOption(config, &integration.Spec, c, namespace, o.Compression); applyConfigOptionErr != nil {
+			if applyConfigOptionErr := ApplyConfigOption(o.Context, config, &integration.Spec, c, namespace, o.Compression); applyConfigOptionErr != nil {
 				return nil, applyConfigOptionErr
 			}
 		} else {
diff --git a/pkg/cmd/run_help.go b/pkg/cmd/run_help.go
index 9521555..5104ac9 100644
--- a/pkg/cmd/run_help.go
+++ b/pkg/cmd/run_help.go
@@ -181,11 +181,11 @@ func parseOption(item string) (*RunConfigOption, error) {
 	return configurationOption, nil
 }
 
-func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
+func applyOption(ctx context.Context, config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
 	c client.Client, namespace string, enableCompression bool, resourceType v1.ResourceType) error {
 	switch config.configType {
 	case ConfigOptionTypeConfigmap:
-		cm := kubernetes.LookupConfigmap(context.Background(), c, namespace, config.Name())
+		cm := kubernetes.LookupConfigmap(ctx, c, namespace, config.Name())
 		if cm == nil {
 			fmt.Printf("Warn: %s Configmap not found in %s namespace, make sure to provide it before the Integration can run\n",
 				config.Name(), namespace)
@@ -194,7 +194,7 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
 		}
 		integrationSpec.AddConfigurationAsResource(config.Type(), config.Name(), string(resourceType), config.DestinationPath(), config.Key())
 	case ConfigOptionTypeSecret:
-		secret := kubernetes.LookupSecret(context.Background(), c, namespace, config.Name())
+		secret := kubernetes.LookupSecret(ctx, c, namespace, config.Name())
 		if secret == nil {
 			fmt.Printf("Warn: %s Secret not found in %s namespace, make sure to provide it before the Integration can run\n",
 				config.Name(), namespace)
@@ -210,7 +210,7 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
 			return fmt.Errorf("you cannot provide a file larger than 1 MB (it was %s MB), check configmap option or --volume instead", printSize)
 		}
 		// Don't allow a binary non compressed resource
-		rawData, contentType, err := loadRawContent(context.Background(), config.Name())
+		rawData, contentType, err := loadRawContent(ctx, config.Name())
 		if err != nil {
 			return err
 		}
@@ -231,17 +231,17 @@ func applyOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec,
 }
 
 // ApplyConfigOption will set the proper --config option behavior to the IntegrationSpec.
-func ApplyConfigOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
+func ApplyConfigOption(ctx context.Context, config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
 	// A config option cannot specify destination path
 	if config.DestinationPath() != "" {
 		return fmt.Errorf("cannot specify a destination path for this option type")
 	}
-	return applyOption(config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeConfig)
+	return applyOption(ctx, config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeConfig)
 }
 
 // ApplyResourceOption will set the proper --resource option behavior to the IntegrationSpec.
-func ApplyResourceOption(config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
-	return applyOption(config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeData)
+func ApplyResourceOption(ctx context.Context, config *RunConfigOption, integrationSpec *v1.IntegrationSpec, c client.Client, namespace string, enableCompression bool) error {
+	return applyOption(ctx, config, integrationSpec, c, namespace, enableCompression, v1.ResourceTypeData)
 }
 
 func binaryOrTextResource(fileName string, data []byte, contentType string, base64Compression bool, resourceType v1.ResourceType, destinationPath string) (v1.ResourceSpec, error) {
diff --git a/pkg/cmd/util_content_test.go b/pkg/cmd/util_content_test.go
index 388c867..a0548c0 100644
--- a/pkg/cmd/util_content_test.go
+++ b/pkg/cmd/util_content_test.go
@@ -31,7 +31,7 @@ import (
 )
 
 func TestRawContentFileMissing(t *testing.T) {
-	_, _, err := loadRawContent(context.TODO(), "dsadas")
+	_, _, err := loadRawContent(context.Background(), "dsadas")
 	assert.NotNil(t, err)
 }
 
@@ -44,7 +44,7 @@ func TestRawBinaryContentType(t *testing.T) {
 	assert.Nil(t, tmpFile.Close())
 	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte{1, 2, 3, 4, 5, 6}, 0o400))
 
-	data, contentType, err := loadRawContent(context.TODO(), tmpFile.Name())
+	data, contentType, err := loadRawContent(context.Background(), tmpFile.Name())
 	assert.Nil(t, err)
 	assert.Equal(t, []byte{1, 2, 3, 4, 5, 6}, data)
 	assert.True(t, isBinary(contentType))
@@ -59,7 +59,7 @@ func TestRawApplicationContentType(t *testing.T) {
 	assert.Nil(t, tmpFile.Close())
 	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o400))
 
-	data, contentType, err := loadRawContent(context.TODO(), tmpFile.Name())
+	data, contentType, err := loadRawContent(context.Background(), tmpFile.Name())
 	assert.Nil(t, err)
 	assert.Equal(t, `{"hello":"world"}`, string(data))
 	assert.False(t, isBinary(contentType))
@@ -74,7 +74,7 @@ func TestTextContentType(t *testing.T) {
 	assert.Nil(t, tmpFile.Close())
 	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o400))
 
-	data, contentType, compressed, err := loadTextContent(context.TODO(), tmpFile.Name(), false)
+	data, contentType, compressed, err := loadTextContent(context.Background(), tmpFile.Name(), false)
 	assert.Nil(t, err)
 	assert.Equal(t, `{"hello":"world"}`, data)
 	assert.False(t, isBinary(contentType))
@@ -90,7 +90,7 @@ func TestTextCompressed(t *testing.T) {
 	assert.Nil(t, tmpFile.Close())
 	assert.Nil(t, ioutil.WriteFile(tmpFile.Name(), []byte(`{"hello":"world"}`), 0o400))
 
-	data, contentType, compressed, err := loadTextContent(context.TODO(), tmpFile.Name(), true)
+	data, contentType, compressed, err := loadTextContent(context.Background(), tmpFile.Name(), true)
 	assert.Nil(t, err)
 	assert.NotEqual(t, `{"hello":"world"}`, data)
 	assert.False(t, isBinary(contentType))
@@ -113,7 +113,7 @@ func TestContentHttp(t *testing.T) {
 	u, err := url.Parse(svr.URL)
 	assert.Nil(t, err)
 
-	data, err := loadContentHTTP(context.TODO(), u)
+	data, err := loadContentHTTP(context.Background(), u)
 	assert.Nil(t, err)
 	assert.NotEmpty(t, data)
 	assert.Equal(t, expected, string(data))