Repository: apache/camel-k
Pull request #2786 (2021-11-25 13:54:49)

fix(lint): error return value are not checked
<!-- Description -->




<!--
Enter your extended release note in the below block. If the PR requires
additional action from users switching to the new release, include the string
"action required". If no release note is required, write "NONE". 

You can (optionally) mark this PR with labels "kind/bug" or "kind/feature" to make sure
the text is added to the right section of the release notes. 
-->

**Release Note**
```release-note
NONE
```



Patch:
diff --git a/.github/workflows/upgrade.yml b/.github/workflows/upgrade.yml
index f63ef9f1b..313362825 100644
--- a/.github/workflows/upgrade.yml
+++ b/.github/workflows/upgrade.yml
@@ -79,7 +79,7 @@ jobs:
         go-version: 1.16.x
     - name: Set up opm tool
       run: |
-        curl -L https://github.com/operator-framework/operator-registry/releases/download/v1.16.1/linux-amd64-opm -o opm
+        curl -L https://github.com/operator-framework/operator-registry/releases/download/v1.19.5/linux-amd64-opm -o opm
         chmod +x opm
         sudo mv opm /usr/local/bin/
     - name: Kubernetes KinD Cluster
@@ -127,15 +127,15 @@ jobs:
         BASE_VERSION=$(echo ${{ env.LOCAL_IMAGE_VERSION }} | grep -Po "\d.\d.\d")
         sed -i "/  version: ${BASE_VERSION}/a \ \ replaces: camel-k-operator.v$(make get-last-released-version)" config/manifests/bases/camel-k.clusterserviceversion.yaml
         export CUSTOM_IMAGE=${{ env.LOCAL_IMAGE_NAME }}
-        export LOCAL_IMAGE_BUNDLE=$KIND_REGISTRY/apache/camel-k-bundle:${{ env.LOCAL_IMAGE_VERSION }}
+        export LOCAL_IMAGE_BUNDLE=${KIND_REGISTRY}/apache/camel-k-bundle:${{ env.LOCAL_IMAGE_VERSION }}
         echo "LOCAL_IMAGE_BUNDLE=${LOCAL_IMAGE_BUNDLE}" >> $GITHUB_ENV
         make bundle-build BUNDLE_IMAGE_NAME=${LOCAL_IMAGE_BUNDLE} DEFAULT_CHANNEL="stable" CHANNELS="stable"
         docker push ${LOCAL_IMAGE_BUNDLE}
     - name: Create new index image
       run: |
-        export LOCAL_IIB=$KIND_REGISTRY/apache/camel-k-iib:${{ env.LOCAL_IMAGE_VERSION }}
+        export LOCAL_IIB=${KIND_REGISTRY}/apache/camel-k-iib:${{ env.LOCAL_IMAGE_VERSION }}
         echo "LOCAL_IIB=${LOCAL_IIB}" >> $GITHUB_ENV
-        opm index add --bundles ${{ env.LOCAL_IMAGE_BUNDLE }} -c docker --from-index quay.io/operatorhubio/catalog:latest --tag ${LOCAL_IIB} --skip-tls
+        sudo opm index add --bundles ${{ env.LOCAL_IMAGE_BUNDLE }} -c docker --from-index quay.io/operatorhubio/catalog:latest --tag ${LOCAL_IIB} --skip-tls
         docker push ${LOCAL_IIB}
     - name: Run IT
       run: |
@@ -147,7 +147,7 @@ jobs:
         export CUSTOM_VERSION=${{ env.LOCAL_IMAGE_VERSION }}
         export KAMEL_INSTALL_BUILD_PUBLISH_STRATEGY=Spectrum
         export KAMEL_INSTALL_MAVEN_REPOSITORIES=$(make get-staging-repo)
-        export KAMEL_INSTALL_REGISTRY=$KIND_REGISTRY
+        export KAMEL_INSTALL_REGISTRY=${KIND_REGISTRY}
         export KAMEL_INSTALL_REGISTRY_INSECURE=true
 
         # Configure test options
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2c638da8d..1c8a0f1e7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,11 +8,13 @@
 
 - Dry run kamel run [\#2769](https://github.com/apache/camel-k/issues/2769)
 - Is there any resources requirements for camel-k operator Deployment? [\#2768](https://github.com/apache/camel-k/issues/2768)
+- Jitpack still configured with `master` branch [\#2764](https://github.com/apache/camel-k/issues/2764)
 - How can I find the log file location in the integration pod?  [\#2762](https://github.com/apache/camel-k/issues/2762)
 - Add 1.7.x documentation tag [\#2753](https://github.com/apache/camel-k/issues/2753)
 - Could not pull base image - Build kit failed \(No matching credentials were found, falling back on anonymous\) [\#2748](https://github.com/apache/camel-k/issues/2748)
 - Cannot deploy XML integration with undertow [\#2746](https://github.com/apache/camel-k/issues/2746)
 - Release 1.7.0 [\#2743](https://github.com/apache/camel-k/issues/2743)
+- topicName [\#2567](https://github.com/apache/camel-k/issues/2567)
 - Kamelet: default KameletBindings configuration settings [\#2558](https://github.com/apache/camel-k/issues/2558)
 - Camel-K - uninstall and namespace deletion w/ k8s let all Camel-K Integrations in this namespace alive [\#2533](https://github.com/apache/camel-k/issues/2533)
 - Reduce time for first Integration start [\#2520](https://github.com/apache/camel-k/issues/2520)
@@ -27,8 +29,14 @@
 
 **Merged pull requests:**
 
+- fix\(doc\): header complain [\#2787](https://github.com/apache/camel-k/pull/2787) ([squakez](https://github.com/squakez))
+- doc: no CLI integration run [\#2783](https://github.com/apache/camel-k/pull/2783) ([squakez](https://github.com/squakez))
+- fix\(ci\): Fix OLM upgrade e2e tests [\#2782](https://github.com/apache/camel-k/pull/2782) ([astefanutti](https://github.com/astefanutti))
+- fix\(doc\): broken links [\#2781](https://github.com/apache/camel-k/pull/2781) ([squakez](https://github.com/squakez))
+- lint [\#2780](https://github.com/apache/camel-k/pull/2780) ([lburgazzoli](https://github.com/lburgazzoli))
 - chore: Upgrade Spectrum and go-containerregistry [\#2779](https://github.com/apache/camel-k/pull/2779) ([astefanutti](https://github.com/astefanutti))
 - doc: cleaning [\#2778](https://github.com/apache/camel-k/pull/2778) ([squakez](https://github.com/squakez))
+- fix\(build\): default jitpack to main [\#2775](https://github.com/apache/camel-k/pull/2775) ([squakez](https://github.com/squakez))
 - doc\(install\): suggested resource configuration [\#2774](https://github.com/apache/camel-k/pull/2774) ([squakez](https://github.com/squakez))
 - chore\(release\): Update latest released version and OLM base CSV manifest [\#2770](https://github.com/apache/camel-k/pull/2770) ([astefanutti](https://github.com/astefanutti))
 - chore\(build\): Upgrade Maven to version 3.8.4 [\#2767](https://github.com/apache/camel-k/pull/2767) ([astefanutti](https://github.com/astefanutti))
diff --git a/cmd/util/license-check/main.go b/cmd/util/license-check/main.go
index 417acc2c1..c2300e511 100644
--- a/cmd/util/license-check/main.go
+++ b/cmd/util/license-check/main.go
@@ -36,23 +36,20 @@ func main() {
 
 	fileBin, err := util.ReadFile(fileName)
 	if err != nil {
-		// #nosec G104
-		os.Stderr.WriteString(fmt.Sprintf("cannot read file %s: %v\n", fileName, err))
+		_, _ = fmt.Fprintf(os.Stderr, "cannot read file %s: %v\n", fileName, err)
 		os.Exit(1)
 	}
 	file := string(fileBin)
 
 	licenseBin, err := util.ReadFile(licenseName)
 	if err != nil {
-		// #nosec G104
-		os.Stderr.WriteString(fmt.Sprintf("cannot read file %s: %v\n", licenseName, err))
+		_, _ = fmt.Fprintf(os.Stderr, "cannot read file %s: %v\n", licenseName, err)
 		os.Exit(1)
 	}
 	license := string(licenseBin)
 
 	if !strings.Contains(file, license) {
-		// #nosec G104
-		os.Stderr.WriteString(fmt.Sprintf("file %s does not contain license\n", fileName))
+		_, _ = fmt.Fprintf(os.Stderr, "file %s does not contain license\n", fileName)
 		os.Exit(1)
 	}
 }
diff --git a/docs/modules/ROOT/pages/installation/advanced/multi.adoc b/docs/modules/ROOT/pages/installation/advanced/multi.adoc
index 007574832..c95da15ba 100644
--- a/docs/modules/ROOT/pages/installation/advanced/multi.adoc
+++ b/docs/modules/ROOT/pages/installation/advanced/multi.adoc
@@ -1,5 +1,5 @@
 [[advanced-installation-multiple-operators]]
-== Multiple Operators and Selective Upgrades
+= Multiple Operators and Selective Upgrades
 
 It's possible to setup multiple Camel K operators in a cluster to watch the same namespaces. It's not
 possible to configure Camel K this way using OLM (Operator Hub), since OLM prevents two operators from watching the same namespaces,
diff --git a/pkg/builder/s2i.go b/pkg/builder/s2i.go
index 153d0a332..625444123 100644
--- a/pkg/builder/s2i.go
+++ b/pkg/builder/s2i.go
@@ -19,11 +19,12 @@ package builder
 
 import (
 	"archive/tar"
+	"bufio"
 	"compress/gzip"
 	"context"
+	"encoding/json"
 	"fmt"
 	"io"
-	"io/ioutil"
 	"os"
 	"path"
 	"path/filepath"
@@ -38,8 +39,6 @@ import (
 	apierrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
-	"k8s.io/apimachinery/pkg/util/json"
-
 	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 	ctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
 
@@ -143,94 +142,97 @@ func (t *s2iTask) Do(ctx context.Context) v1.BuildStatus {
 		return status.Failed(errors.Wrap(err, "cannot create image stream"))
 	}
 
-	tmpDir, err := ioutil.TempDir(os.TempDir(), t.build.Name+"-s2i-")
-	if err != nil {
-		return status.Failed(err)
-	}
-	archive := path.Join(tmpDir, "archive.tar.gz")
-	defer os.RemoveAll(tmpDir)
-
-	contextDir := t.task.ContextDir
-	if contextDir == "" {
-		// Use the working directory.
-		// This is useful when the task is executed in-container,
-		// so that its WorkingDir can be used to share state and
-		// coordinate with other tasks.
-		pwd, err := os.Getwd()
-		if err != nil {
-			return status.Failed(err)
+	err = util.WithTempDir(t.build.Name+"-s2i-", func(tmpDir string) error {
+		archive := path.Join(tmpDir, "archive.tar.gz")
+
+		contextDir := t.task.ContextDir
+		if contextDir == "" {
+			// Use the working directory.
+			// This is useful when the task is executed in-container,
+			// so that its WorkingDir can be used to share state and
+			// coordinate with other tasks.
+			pwd, err := os.Getwd()
+			if err != nil {
+				return err
+			}
+			contextDir = path.Join(pwd, ContextDir)
 		}
-		contextDir = path.Join(pwd, ContextDir)
-	}
 
-	archiveFile, err := os.Create(archive)
-	if err != nil {
-		return status.Failed(errors.Wrap(err, "cannot create tar archive"))
-	}
+		archiveFile, err := os.Create(archive)
+		if err != nil {
+			return errors.Wrap(err, "cannot create tar archive")
+		}
 
-	err = tarDir(contextDir, archiveFile)
-	if err != nil {
-		return status.Failed(errors.Wrap(err, "cannot tar context directory"))
-	}
+		err = tarDir(contextDir, archiveFile)
+		if err != nil {
+			return errors.Wrap(err, "cannot tar context directory")
+		}
 
-	resource, err := util.ReadFile(archive)
-	if err != nil {
-		return status.Failed(errors.Wrap(err, "cannot read tar file "+archive))
-	}
+		f, err := util.Open(archive)
+		if err != nil {
+			return err
+		}
 
-	restClient, err := kubernetes.GetClientFor(t.c, "build.openshift.io", "v1")
-	if err != nil {
-		return status.Failed(err)
-	}
+		restClient, err := kubernetes.GetClientFor(t.c, "build.openshift.io", "v1")
+		if err != nil {
+			return err
+		}
 
-	r := restClient.Post().
-		Namespace(t.build.Namespace).
-		Body(resource).
-		Resource("buildconfigs").
-		Name("camel-k-" + t.build.Name).
-		SubResource("instantiatebinary").
-		Do(ctx)
+		r := restClient.Post().
+			Namespace(t.build.Namespace).
+			Body(bufio.NewReader(f)).
+			Resource("buildconfigs").
+			Name("camel-k-" + t.build.Name).
+			SubResource("instantiatebinary").
+			Do(ctx)
 
-	if r.Error() != nil {
-		return status.Failed(errors.Wrap(r.Error(), "cannot instantiate binary"))
-	}
+		if r.Error() != nil {
+			return errors.Wrap(r.Error(), "cannot instantiate binary")
+		}
 
-	data, err := r.Raw()
-	if err != nil {
-		return status.Failed(errors.Wrap(err, "no raw data retrieved"))
-	}
+		data, err := r.Raw()
+		if err != nil {
+			return errors.Wrap(err, "no raw data retrieved")
+		}
 
-	s2iBuild := buildv1.Build{}
-	err = json.Unmarshal(data, &s2iBuild)
-	if err != nil {
-		return status.Failed(errors.Wrap(err, "cannot unmarshal instantiated binary response"))
-	}
+		s2iBuild := buildv1.Build{}
+		err = json.Unmarshal(data, &s2iBuild)
+		if err != nil {
+			return errors.Wrap(err, "cannot unmarshal instantiated binary response")
+		}
 
-	err = t.waitForS2iBuildCompletion(ctx, t.c, &s2iBuild)
-	if err != nil {
-		if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
-			// nolint: contextcheck
-			if err := t.cancelBuild(context.Background(), &s2iBuild); err != nil {
-				log.Errorf(err, "cannot cancel s2i Build: %s/%s", s2iBuild.Namespace, s2iBuild.Name)
+		err = t.waitForS2iBuildCompletion(ctx, t.c, &s2iBuild)
+		if err != nil {
+			if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
+				// nolint: contextcheck
+				if err := t.cancelBuild(context.Background(), &s2iBuild); err != nil {
+					log.Errorf(err, "cannot cancel s2i Build: %s/%s", s2iBuild.Namespace, s2iBuild.Name)
+				}
 			}
+			return err
+		}
+		if s2iBuild.Status.Output.To != nil {
+			status.Digest = s2iBuild.Status.Output.To.ImageDigest
+		}
+
+		err = t.c.Get(ctx, ctrl.ObjectKeyFromObject(is), is)
+		if err != nil {
+			return err
+		}
+
+		if is.Status.DockerImageRepository == "" {
+			return errors.New("dockerImageRepository not available in ImageStream")
 		}
-		return status.Failed(err)
-	}
-	if s2iBuild.Status.Output.To != nil {
-		status.Digest = s2iBuild.Status.Output.To.ImageDigest
-	}
 
-	err = t.c.Get(ctx, ctrl.ObjectKeyFromObject(is), is)
+		status.Image = is.Status.DockerImageRepository + ":" + t.task.Tag
+
+		return f.Close()
+	})
+
 	if err != nil {
 		return status.Failed(err)
 	}
 
-	if is.Status.DockerImageRepository == "" {
-		return status.Failed(errors.New("dockerImageRepository not available in ImageStream"))
-	}
-
-	status.Image = is.Status.DockerImageRepository + ":" + t.task.Tag
-
 	return status
 }
 
@@ -298,10 +300,10 @@ func tarDir(src string, writers ...io.Writer) error {
 	mw := io.MultiWriter(writers...)
 
 	gzw := gzip.NewWriter(mw)
-	defer gzw.Close()
+	defer util.CloseQuietly(gzw)
 
 	tw := tar.NewWriter(gzw)
-	defer tw.Close()
+	defer util.CloseQuietly(tw)
 
 	return filepath.Walk(src, func(file string, fi os.FileInfo, err error) error {
 		if err != nil {
diff --git a/pkg/builder/spectrum.go b/pkg/builder/spectrum.go
index a7c149ec1..5aedbf488 100644
--- a/pkg/builder/spectrum.go
+++ b/pkg/builder/spectrum.go
@@ -103,12 +103,10 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
 		if err != nil {
 			return status.Failed(err)
 		}
-		defer os.RemoveAll(registryConfigDir)
 	}
 
 	newStdR, newStdW, pipeErr := os.Pipe()
-	// #nosec G307
-	defer newStdW.Close()
+	defer util.CloseQuietly(newStdW)
 
 	if pipeErr != nil {
 		// In the unlikely case of an error, use stdout instead of aborting
@@ -131,12 +129,19 @@ func (t *spectrumTask) Do(ctx context.Context) v1.BuildStatus {
 	go readSpectrumLogs(newStdR)
 	digest, err := spectrum.Build(options, contextDir+":"+path.Join(DeploymentDir))
 	if err != nil {
+		_ = os.RemoveAll(registryConfigDir)
 		return status.Failed(err)
 	}
 
 	status.Image = t.task.Image
 	status.Digest = digest
 
+	if registryConfigDir != "" {
+		if err := os.RemoveAll(registryConfigDir); err != nil {
+			return status.Failed(err)
+		}
+	}
+
 	return status
 }
 
diff --git a/pkg/cmd/dump.go b/pkg/cmd/dump.go
index c0d8f4ed3..9fa22420c 100644
--- a/pkg/cmd/dump.go
+++ b/pkg/cmd/dump.go
@@ -188,7 +188,7 @@ func dumpLogs(ctx context.Context, c client.Client, prefix string, ns string, na
 	if err != nil {
 		return err
 	}
-	defer stream.Close()
+
 	scanner := bufio.NewScanner(stream)
 	printed := false
 	for scanner.Scan() {
@@ -198,5 +198,5 @@ func dumpLogs(ctx context.Context, c client.Client, prefix string, ns string, na
 	if !printed {
 		fmt.Fprintf(out, "%s[no logs available]\n", prefix)
 	}
-	return nil
+	return stream.Close()
 }
diff --git a/pkg/cmd/init.go b/pkg/cmd/init.go
index 0a2f06c07..52d32f65f 100644
--- a/pkg/cmd/init.go
+++ b/pkg/cmd/init.go
@@ -92,7 +92,11 @@ func (o *initCmdOptions) writeFromTemplate(language v1.Language, fileName string
 	params := TemplateParameters{
 		Name: simpleName,
 	}
-	rawData := resources.ResourceAsString(fmt.Sprintf("/templates/%s.tmpl", language))
+
+	rawData, err := resources.ResourceAsString(fmt.Sprintf("/templates/%s.tmpl", language))
+	if err != nil {
+		return err
+	}
 	if rawData == "" {
 		return fmt.Errorf("cannot find template for language %s", string(language))
 	}
diff --git a/pkg/cmd/trait_help.go b/pkg/cmd/trait_help.go
index 7a29c7255..0ef7bc9af 100644
--- a/pkg/cmd/trait_help.go
+++ b/pkg/cmd/trait_help.go
@@ -101,8 +101,13 @@ func (command *traitHelpCommandOptions) run(cmd *cobra.Command, args []string) e
 	var traitDescriptions []*traitDescription
 	catalog := trait.NewCatalog(nil)
 
-	traitMetaData := &traitMetaData{}
-	err := yaml.Unmarshal(resources.Resource("/traits.yaml"), traitMetaData)
+	content, err := resources.Resource("/traits.yaml")
+	if err != nil {
+		return err
+	}
+
+	traitMetaData := traitMetaData{}
+	err = yaml.Unmarshal(content, &traitMetaData)
 	if err != nil {
 		return err
 	}
diff --git a/pkg/cmd/util_containerization.go b/pkg/cmd/util_containerization.go
index 4868e5a66..aae4f1336 100644
--- a/pkg/cmd/util_containerization.go
+++ b/pkg/cmd/util_containerization.go
@@ -50,9 +50,7 @@ func createDockerBaseWorkingDirectory() error {
 
 func deleteDockerBaseWorkingDirectory() error {
 	// Remove directory used for computing the dependencies.
-	defer os.RemoveAll(docker.BaseWorkingDirectory)
-
-	return nil
+	return os.RemoveAll(docker.BaseWorkingDirectory)
 }
 
 func createDockerWorkingDirectory() error {
@@ -70,9 +68,7 @@ func createDockerWorkingDirectory() error {
 
 func deleteDockerWorkingDirectory() error {
 	// Remove directory used for computing the dependencies.
-	defer os.RemoveAll(docker.IntegrationWorkingDirectory)
-
-	return nil
+	return os.RemoveAll(docker.IntegrationWorkingDirectory)
 }
 
 func setDockerNetworkName(networkName string) {
diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index 5f0a7585e..8a5e3ea8e 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -498,9 +498,7 @@ func createMavenWorkingDirectory() error {
 
 func deleteMavenWorkingDirectory() error {
 	// Remove directory used for computing the dependencies
-	defer os.RemoveAll(util.MavenWorkingDirectory)
-
-	return nil
+	return os.RemoveAll(util.MavenWorkingDirectory)
 }
 
 func getCustomDependenciesDir(integrationDirectory string) string {
diff --git a/pkg/controller/integrationplatform/create.go b/pkg/controller/integrationplatform/create.go
index aabf9b40d..91e725a36 100644
--- a/pkg/controller/integrationplatform/create.go
+++ b/pkg/controller/integrationplatform/create.go
@@ -46,7 +46,12 @@ func (action *createAction) CanHandle(platform *v1.IntegrationPlatform) bool {
 }
 
 func (action *createAction) Handle(ctx context.Context, platform *v1.IntegrationPlatform) (*v1.IntegrationPlatform, error) {
-	for _, k := range resources.WithPrefix("/camel-catalog-") {
+	paths, err := resources.WithPrefix("/camel-catalog-")
+	if err != nil {
+		return nil, err
+	}
+
+	for _, k := range paths {
 		action.L.Infof("Installing camel catalog: %s", k)
 		err := install.Resources(ctx, action.client, platform.Namespace, true, install.IdentityResourceCustomizer, k)
 		if err != nil {
diff --git a/pkg/install/cluster.go b/pkg/install/cluster.go
index 774caad8d..790298617 100644
--- a/pkg/install/cluster.go
+++ b/pkg/install/cluster.go
@@ -268,7 +268,12 @@ func isCrdInstalled(c client.Client, kind string, version string) (bool, error)
 }
 
 func installCRD(ctx context.Context, c client.Client, kind string, version string, resourceName string, converter ResourceCustomizer, collection *kubernetes.Collection, force bool) error {
-	crd, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), resources.ResourceAsString("/crd/bases/"+resourceName))
+	content, err := resources.ResourceAsString("/crd/bases/" + resourceName)
+	if err != nil {
+		return err
+	}
+
+	crd, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), content)
 	if err != nil {
 		return err
 	}
@@ -319,7 +324,12 @@ func isResourceInstalled(ctx context.Context, c client.Client, object ctrl.Objec
 }
 
 func installResource(ctx context.Context, c client.Client, collection *kubernetes.Collection, resource string) error {
-	obj, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), resources.ResourceAsString(resource))
+	content, err := resources.ResourceAsString(resource)
+	if err != nil {
+		return err
+	}
+
+	obj, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), content)
 	if err != nil {
 		return err
 	}
diff --git a/pkg/install/common.go b/pkg/install/common.go
index 72315ae13..e13129866 100644
--- a/pkg/install/common.go
+++ b/pkg/install/common.go
@@ -81,7 +81,13 @@ func Resource(ctx context.Context, c client.Client, namespace string, force bool
 
 func ResourceOrCollect(ctx context.Context, c client.Client, namespace string, collection *kubernetes.Collection,
 	force bool, customizer ResourceCustomizer, name string) error {
-	obj, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), resources.ResourceAsString(name))
+
+	content, err := resources.ResourceAsString(name)
+	if err != nil {
+		return err
+	}
+
+	obj, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), content)
 	if err != nil {
 		return err
 	}
diff --git a/pkg/install/operator.go b/pkg/install/operator.go
index 5fcb63a11..9492ab189 100644
--- a/pkg/install/operator.go
+++ b/pkg/install/operator.go
@@ -302,12 +302,18 @@ func installClusterRoleBinding(ctx context.Context, c client.Client, collection
 	existing, err := c.RbacV1().ClusterRoleBindings().Get(ctx, name, metav1.GetOptions{})
 	switch {
 	case k8serrors.IsNotFound(err):
+
+		content, err := resources.ResourceAsString(path)
+		if err != nil {
+			return err
+		}
+
 		existing = nil
-		yaml := resources.ResourceAsString(path)
-		if yaml == "" {
+		if content == "" {
 			return errors.Errorf("resource file %v not found", path)
 		}
-		obj, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), yaml)
+
+		obj, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), content)
 		if err != nil {
 			return err
 		}
@@ -436,10 +442,17 @@ func PlatformOrCollect(ctx context.Context, c client.Client, clusterType string,
 	if err != nil {
 		return nil, err
 	}
-	platformObject, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), resources.ResourceAsString("/samples/bases/camel_v1_integrationplatform.yaml"))
+
+	content, err := resources.ResourceAsString("/samples/bases/camel_v1_integrationplatform.yaml")
+	if err != nil {
+		return nil, err
+	}
+
+	platformObject, err := kubernetes.LoadResourceFromYaml(c.GetScheme(), content)
 	if err != nil {
 		return nil, err
 	}
+
 	pl, ok := platformObject.(*v1.IntegrationPlatform)
 	if !ok {
 		return nil, fmt.Errorf("type assertion failed: %v", platformObject)
diff --git a/pkg/resources/resources_support.go b/pkg/resources/resources_support.go
index d9bb2e158..46a8c36b4 100644
--- a/pkg/resources/resources_support.go
+++ b/pkg/resources/resources_support.go
@@ -20,23 +20,27 @@ package resources
 import (
 	"bytes"
 	"io/ioutil"
+	"os"
 	"path/filepath"
 	"strings"
 	"text/template"
 
-	"github.com/apache/camel-k/pkg/util/log"
+	"github.com/apache/camel-k/pkg/util"
+
+	"github.com/pkg/errors"
 )
 
 //
 //go:generate go run ../../cmd/util/vfs-gen resources config
 //
 // ResourceAsString returns the named resource content as string.
-func ResourceAsString(name string) string {
-	return string(Resource(name))
+func ResourceAsString(name string) (string, error) {
+	data, err := Resource(name)
+	return string(data), err
 }
 
-// Resource provides an easy access to embedded assets.
-func Resource(name string) []byte {
+// Resource provides an easy way to access to embedded assets.
+func Resource(name string) ([]byte, error) {
 	name = strings.Trim(name, " ")
 	if !strings.HasPrefix(name, "/") {
 		name = "/" + name
@@ -44,25 +48,28 @@ func Resource(name string) []byte {
 
 	file, err := assets.Open(name)
 	if err != nil {
-		log.Error(err, "cannot access resource file", "file", name)
-		return nil
+		return nil, errors.Wrapf(err, "cannot access resource file %s", name)
 	}
-	defer file.Close()
 
 	data, err := ioutil.ReadAll(file)
 	if err != nil {
-		log.Error(err, "error while reading resource file", "file", name)
-		return nil
+		_ = file.Close()
+		return nil, errors.Wrapf(err, "cannot access resource file %s", name)
 	}
-	return data
+
+	return data, file.Close()
 }
 
 // TemplateResource loads a file resource as go template and processes it using the given parameters.
 func TemplateResource(name string, params interface{}) (string, error) {
-	rawData := ResourceAsString(name)
+	rawData, err := ResourceAsString(name)
+	if err != nil {
+		return "", err
+	}
 	if rawData == "" {
 		return "", nil
 	}
+
 	tmpl, err := template.New(name).Parse(rawData)
 	if err != nil {
 		return "", err
@@ -72,6 +79,7 @@ func TemplateResource(name string, params interface{}) (string, error) {
 	if err := tmpl.Execute(&buf, params); err != nil {
 		return "", err
 	}
+
 	return buf.String(), nil
 }
 
@@ -85,46 +93,56 @@ func DirExists(dirName string) bool {
 
 // WithPrefix lists all file names that begins with the give path prefix
 // If pathPrefix is a path of directories then be sure to end it with a '/'.
-func WithPrefix(pathPrefix string) []string {
+func WithPrefix(pathPrefix string) ([]string, error) {
 	dirPath := filepath.Dir(pathPrefix)
 
+	paths, err := Resources(dirPath)
+	if err != nil {
+		return nil, err
+	}
+
 	var res []string
-	for _, path := range Resources(dirPath) {
-		if result, _ := filepath.Match(pathPrefix+"*", path); result {
-			res = append(res, path)
+	for i := range paths {
+		if result, _ := filepath.Match(pathPrefix+"*", paths[i]); result {
+			res = append(res, paths[i])
 		}
 	}
 
-	return res
+	return res, nil
 }
 
 // Resources lists all file names in the given path (starts with '/').
-func Resources(dirName string) []string {
+func Resources(dirName string) ([]string, error) {
 	dir, err := assets.Open(dirName)
 	if err != nil {
-		log.Error(err, "error while listing resource files", "dir", dirName)
-		return nil
+		if os.IsNotExist(err) {
+			return nil, nil
+		}
+
+		return nil, errors.Wrapf(err, "error while listing resource files %s", dirName)
 	}
-	defer dir.Close()
+
 	info, err := dir.Stat()
 	if err != nil {
-		log.Error(err, "error while doing stat on directory", "dir", dirName)
-		return nil
+		return nil, dir.Close()
 	}
 	if !info.IsDir() {
-		log.Error(err, "location is not a directory", "dir", dirName)
-		return nil
+		util.CloseQuietly(dir)
+		return nil, errors.Wrapf(err, "location %s is not a directory", dirName)
 	}
+
 	files, err := dir.Readdir(-1)
 	if err != nil {
-		log.Error(err, "error while listing files on directory", "dir", dirName)
-		return nil
+		util.CloseQuietly(dir)
+		return nil, errors.Wrapf(err, "error while listing files on directory %s", dirName)
 	}
+
 	var res []string
 	for _, f := range files {
 		if !f.IsDir() {
 			res = append(res, filepath.Join(dirName, f.Name()))
 		}
 	}
-	return res
+
+	return res, dir.Close()
 }
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 272714d79..09d7ab594 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -27,6 +27,8 @@ import (
 	"strconv"
 	"strings"
 
+	"go.uber.org/multierr"
+
 	"github.com/pkg/errors"
 
 	corev1 "k8s.io/api/core/v1"
@@ -95,14 +97,14 @@ func (t *openAPITrait) Apply(e *Environment) error {
 		return err
 	}
 
-	defer os.RemoveAll(tmpDir)
-
 	for i, resource := range e.Integration.Spec.Resources {
 		if resource.Type != v1.ResourceTypeOpenAPI {
 			continue
 		}
 		if resource.Name == "" {
-			return fmt.Errorf("no name defined for the openapi resource: %v", resource)
+			return multierr.Append(
+				fmt.Errorf("no name defined for the openapi resource: %v", resource),
+				os.RemoveAll(tmpDir))
 		}
 
 		generatedContentName := fmt.Sprintf("%s-openapi-%03d", e.Integration.Name, i)
@@ -137,7 +139,7 @@ func (t *openAPITrait) Apply(e *Environment) error {
 		e.Integration.Status.GeneratedSources = generatedSources
 	}
 
-	return nil
+	return os.RemoveAll(tmpDir)
 }
 
 func (t *openAPITrait) generateOpenAPIConfigMap(e *Environment, resource v1.ResourceSpec, tmpDir, generatedContentName string) error {
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index f47cf6101..b6459551b 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -19,8 +19,6 @@ package camel
 
 import (
 	"context"
-	"io/ioutil"
-	"os"
 	"path"
 
 	"github.com/apache/camel-k/pkg/util"
@@ -48,9 +46,20 @@ func QuarkusCatalog() (*RuntimeCatalog, error) {
 func catalogForRuntimeProvider(provider v1.RuntimeProvider) (*RuntimeCatalog, error) {
 	catalogs := make([]v1.CamelCatalog, 0)
 
-	for _, name := range resources.WithPrefix("/camel-catalog-") {
+	names, err := resources.WithPrefix("/camel-catalog-")
+	if err != nil {
+		return nil, err
+	}
+
+	for _, name := range names {
+
+		content, err := resources.Resource(name)
+		if err != nil {
+			return nil, err
+		}
+
 		var c v1.CamelCatalog
-		if err := yaml2.Unmarshal(resources.Resource(name), &c); err != nil {
+		if err := yaml2.Unmarshal(content, &c); err != nil {
 			return nil, err
 		}
 
@@ -96,60 +105,47 @@ func GenerateCatalogCommon(
 	runtime v1.RuntimeSpec,
 	providerDependencies []maven.Dependency) (*RuntimeCatalog, error) {
 
-	root := os.TempDir()
-	tmpDir, err := ioutil.TempDir(root, "camel-catalog")
-	if err != nil {
-		return nil, err
-	}
+	catalog := v1.CamelCatalog{}
 
-	defer os.RemoveAll(tmpDir)
+	err := util.WithTempDir("camel-catalog", func(tmpDir string) error {
+		project := generateMavenProject(runtime.Version, providerDependencies)
 
-	if err := os.MkdirAll(tmpDir, os.ModePerm); err != nil {
-		return nil, err
-	}
+		mc := maven.NewContext(tmpDir)
+		mc.LocalRepository = mvn.LocalRepository
+		mc.AddSystemProperty("catalog.path", tmpDir)
+		mc.AddSystemProperty("catalog.file", "catalog.yaml")
+		mc.AddSystemProperty("catalog.runtime", string(runtime.Provider))
 
-	project := generateMavenProject(runtime.Version, providerDependencies)
+		mc.SettingsContent = nil
+		if settings != "" {
+			mc.SettingsContent = []byte(settings)
+		}
 
-	mc := maven.NewContext(tmpDir)
-	mc.LocalRepository = mvn.LocalRepository
-	mc.AddSystemProperty("catalog.path", tmpDir)
-	mc.AddSystemProperty("catalog.file", "catalog.yaml")
-	mc.AddSystemProperty("catalog.runtime", string(runtime.Provider))
+		if caCert != nil {
+			trustStoreName := "trust.jks"
+			trustStorePass := jvm.NewKeystorePassword()
+			if err := jvm.GenerateKeystore(ctx, tmpDir, trustStoreName, trustStorePass, caCert); err != nil {
+				return err
+			}
+			mc.ExtraMavenOpts = append(mc.ExtraMavenOpts,
+				"-Djavax.net.ssl.trustStore="+trustStoreName,
+				"-Djavax.net.ssl.trustStorePassword="+trustStorePass,
+			)
+		}
 
-	mc.SettingsContent = nil
-	if settings != "" {
-		mc.SettingsContent = []byte(settings)
-	}
+		if err := project.Command(mc).Do(ctx); err != nil {
+			return err
+		}
 
-	if caCert != nil {
-		trustStoreName := "trust.jks"
-		trustStorePass := jvm.NewKeystorePassword()
-		err := jvm.GenerateKeystore(ctx, tmpDir, trustStoreName, trustStorePass, caCert)
+		content, err := util.ReadFile(path.Join(tmpDir, "catalog.yaml"))
 		if err != nil {
-			return nil, err
+			return err
 		}
-		mc.ExtraMavenOpts = append(mc.ExtraMavenOpts,
-			"-Djavax.net.ssl.trustStore="+trustStoreName,
-			"-Djavax.net.ssl.trustStorePassword="+trustStorePass,
-		)
-	}
-
-	err = project.Command(mc).Do(ctx)
-	if err != nil {
-		return nil, err
-	}
 
-	content, err := util.ReadFile(path.Join(tmpDir, "catalog.yaml"))
-	if err != nil {
-		return nil, err
-	}
-
-	catalog := v1.CamelCatalog{}
-	if err := yaml2.Unmarshal(content, &catalog); err != nil {
-		return nil, err
-	}
+		return yaml2.Unmarshal(content, &catalog)
+	})
 
-	return NewRuntimeCatalog(catalog.Spec), nil
+	return NewRuntimeCatalog(catalog.Spec), err
 }
 
 func generateMavenProject(runtimeVersion string, providerDependencies []maven.Dependency) maven.Project {
diff --git a/pkg/util/gzip/compress.go b/pkg/util/gzip/compress.go
index 62201fa6e..5a419f26d 100644
--- a/pkg/util/gzip/compress.go
+++ b/pkg/util/gzip/compress.go
@@ -23,6 +23,8 @@ import (
 	"encoding/base64"
 	"io"
 	"io/ioutil"
+
+	"github.com/apache/camel-k/pkg/util"
 )
 
 // Compress --.
@@ -61,19 +63,19 @@ func Uncompress(buffer io.Writer, data []byte) error {
 		return err
 	}
 
-	defer gz.Close()
-
 	data, err = ioutil.ReadAll(gz)
 	if err != nil {
+		util.CloseQuietly(gz)
 		return err
 	}
 
 	_, err = buffer.Write(data)
 	if err != nil {
+		util.CloseQuietly(gz)
 		return err
 	}
 
-	return nil
+	return gz.Close()
 }
 
 // UncompressBase64 --.
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 1478e291d..2d2f73ef7 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -779,6 +779,12 @@ func Close(err error, closer io.Closer) error {
 	return multierr.Append(err, closer.Close())
 }
 
+// CloseQuietly unconditionally close an io.Closer
+// It should not be used to replace the Close statement(s).
+func CloseQuietly(closer io.Closer) {
+	_ = closer.Close()
+}
+
 // WithFile a safe wrapper to process a file.
 func WithFile(name string, flag int, perm os.FileMode, consumer func(file *os.File) error) error {
 	// #nosec G304
@@ -836,3 +842,16 @@ func WriteFileWithContent(filePath string, content []byte) error {
 
 	return Close(err, file)
 }
+
+// WithTempDir a safe wrapper to deal with temporary directories.
+func WithTempDir(pattern string, consumer func(string) error) error {
+	tmpDir, err := ioutil.TempDir("", pattern)
+	if err != nil {
+		return err
+	}
+
+	consumerErr := consumer(tmpDir)
+	removeErr := os.RemoveAll(tmpDir)
+
+	return multierr.Append(consumerErr, removeErr)
+}


Test patch:
diff --git a/pkg/cmd/modeline_test.go b/pkg/cmd/modeline_test.go
index 966a73772..3907dc392 100644
--- a/pkg/cmd/modeline_test.go
+++ b/pkg/cmd/modeline_test.go
@@ -25,442 +25,485 @@ import (
 	"path"
 	"testing"
 
+	"github.com/apache/camel-k/pkg/util"
+
 	"github.com/stretchr/testify/assert"
 )
 
 func TestModelineRunSimple(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	file := `
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		file := `
 		// camel-k: dependency=mvn:org.my:lib:1.0
 	`
-	fileName := path.Join(dir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(dir, "simple.groovy")
+		err := ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--dependency=mvn:org.my:lib:1.0"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--dependency=mvn:org.my:lib:1.0"}, flags)
 }
 
 func TestModelineRunHelp(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-	// no file created
-	fileName := path.Join(dir, "simple.groovy")
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		// no file created
+		fileName := path.Join(dir, "simple.groovy")
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "--help"})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--help"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "--help"})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--help"}, flags)
 }
 
 func TestModelineRunChain(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	file := `
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		file := `
 		// camel-k: dependency=mvn:org.my:lib:2.0
 	`
-	fileName := path.Join(dir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(dir, "simple.groovy")
+		err := ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", "-d", "mvn:org.my:lib2:1.0", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", "-d", "mvn:org.my:lib2:1.0", fileName, "--dependency=mvn:org.my:lib:2.0"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", "-d", "mvn:org.my:lib2:1.0", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", "-d", "mvn:org.my:lib2:1.0", fileName, "--dependency=mvn:org.my:lib:2.0"}, flags)
 }
 
 func TestModelineRunMultipleFiles(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	file := `
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		file := `
 		// camel-k: dependency=mvn:org.my:lib1:3.0
 	`
-	fileName := path.Join(dir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(dir, "simple.groovy")
+		err := ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
 
-	file2 := `
+		file2 := `
 		// camel-k: dependency=mvn:org.my:lib2:3.0
 	`
-	fileName2 := path.Join(dir, "ext.groovy")
-	err = ioutil.WriteFile(fileName2, []byte(file2), 0o400)
-	assert.NoError(t, err)
+		fileName2 := path.Join(dir, "ext.groovy")
+		err = ioutil.WriteFile(fileName2, []byte(file2), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, fileName2})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, fileName2, "--dependency=mvn:org.my:lib1:3.0", "--dependency=mvn:org.my:lib2:3.0"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, fileName2})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, fileName2, "--dependency=mvn:org.my:lib1:3.0", "--dependency=mvn:org.my:lib2:3.0"}, flags)
 }
 
 func TestModelineRunProperty(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: property=my-prop=my-val
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--property=my-prop=my-val"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--property=my-prop=my-val"}, flags)
 }
 
 func TestModelineRunDuplicatedProperties(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
-
-	file := `
+		file := `
 		// camel-k: property=prop1=false
 		// camel-k: property=prop2=false
 		// camel-k: property=foo=bar
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "-p", "prop1=true", "--property", "prop2=true"})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "-p", "prop1=true", "--property", "prop2=true", "--property=foo=bar"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "-p", "prop1=true", "--property", "prop2=true"})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "-p", "prop1=true", "--property", "prop2=true", "--property=foo=bar"}, flags)
 }
 
 func TestModelineRunDuplicatedBuildProperties(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: build-property=prop1=false
 		// camel-k: build-property=prop2=false
 		// camel-k: build-property=foo=bar
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
-
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{
-		"kamel", "run", fileName,
-		"--build-property", "prop1=true", "--build-property", "prop2=true",
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{
+			"kamel", "run", fileName,
+			"--build-property", "prop1=true", "--build-property", "prop2=true",
+		})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{
+			"run", fileName, "--build-property", "prop1=true", "--build-property", "prop2=true",
+			"--build-property=foo=bar",
+		}, flags)
+
+		return nil
 	})
+
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{
-		"run", fileName, "--build-property", "prop1=true", "--build-property", "prop2=true",
-		"--build-property=foo=bar",
-	}, flags)
 }
 
 func TestModelineRunPropertyFiles(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: property=file:application.properties
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
 
-	propFile := `
+		propFile := `
 		a=b
 	`
-	propFileName := path.Join(subDir, "application.properties")
-	err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
-	assert.NoError(t, err)
+		propFileName := path.Join(subDir, "application.properties")
+		err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--property=file:%s", propFileName)}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--property=file:%s", propFileName)}, flags)
 }
 
 func TestModelineRunBuildProperty(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: build-property=my-build-prop=my-val
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--build-property=my-build-prop=my-val"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--build-property=my-build-prop=my-val"}, flags)
 }
 
 func TestModelineRunBuildPropertyFiles(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
-
-	file := `
+		file := `
 		// camel-k: build-property=file:application.properties
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
 
-	propFile := `
+		propFile := `
 		a=b
 	`
-	propFileName := path.Join(subDir, "application.properties")
-	err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
-	assert.NoError(t, err)
+		propFileName := path.Join(subDir, "application.properties")
+		err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--build-property=file:%s", propFileName)}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--build-property=file:%s", propFileName)}, flags)
 }
 
 func TestModelineRunDuplicateTraits(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
-
-	file := `
+		file := `
 		// camel-k: trait=trait1=false
 		// camel-k: trait=trait2=false
 		// camel-k: trait=foo=bar
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "-t", "trait1=true", "--trait", "trait2=true"})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "-t", "trait1=true", "--trait", "trait2=true", "--trait=foo=bar"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName, "-t", "trait1=true", "--trait", "trait2=true"})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "-t", "trait1=true", "--trait", "trait2=true", "--trait=foo=bar"}, flags)
 }
 
 func TestModelineRunConfigConfigmap(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: config=configmap:my-cm
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--config=configmap:my-cm"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--config=configmap:my-cm"}, flags)
 }
 
 func TestModelineRunConfigSecret(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: config=secret:my-secret
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--config=secret:my-secret"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--config=secret:my-secret"}, flags)
 }
 
 func TestModelineRunConfigFile(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: config=file:application.properties
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
 
-	propFile := `
+		propFile := `
 		a=b
 	`
-	propFileName := path.Join(subDir, "application.properties")
-	err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
-	assert.NoError(t, err)
+		propFileName := path.Join(subDir, "application.properties")
+		err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--config=file:%s", propFileName)}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--config=file:%s", propFileName)}, flags)
 }
 
 func TestModelineRunResourceConfigmap(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: resource=configmap:my-cm
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--resource=configmap:my-cm"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--resource=configmap:my-cm"}, flags)
 }
 
 func TestModelineRunResourceSecret(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
-
-	file := `
+		file := `
 		// camel-k: resource=secret:my-secret
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, "--resource=secret:my-secret"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, "--resource=secret:my-secret"}, flags)
 }
 
 func TestModelineRunResourceFile(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
-
-	subDir := path.Join(dir, "sub")
-	err = os.Mkdir(subDir, 0o700)
-	assert.NoError(t, err)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
+		subDir := path.Join(dir, "sub")
+		err := os.Mkdir(subDir, 0o700)
+		assert.NoError(t, err)
 
-	file := `
+		file := `
 		// camel-k: resource=file:application.properties
 	`
-	fileName := path.Join(subDir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(subDir, "simple.groovy")
+		err = ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
 
-	propFile := `
+		propFile := `
 		a=b
 	`
-	propFileName := path.Join(subDir, "application.properties")
-	err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
-	assert.NoError(t, err)
+		propFileName := path.Join(subDir, "application.properties")
+		err = ioutil.WriteFile(propFileName, []byte(propFile), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--resource=file:%s", propFileName)}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "run", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"run", fileName, fmt.Sprintf("--resource=file:%s", propFileName)}, flags)
 }
 
 func TestModelineInspectSimple(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
 
-	file := `
+		file := `
 		// camel-k: dependency=mvn:org.my:lib:1.0
 	`
-	fileName := path.Join(dir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(dir, "simple.groovy")
+		err := ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "local", "inspect", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"local", "inspect", fileName, "--dependency=mvn:org.my:lib:1.0"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "local", "inspect", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"local", "inspect", fileName, "--dependency=mvn:org.my:lib:1.0"}, flags)
 }
 
 func TestModelineInspectMultipleDeps(t *testing.T) {
-	dir, err := ioutil.TempDir("", "camel-k-test-")
-	assert.NoError(t, err)
-	defer os.RemoveAll(dir)
+	err := util.WithTempDir("camel-k-test-", func(dir string) error {
 
-	file := `
+		file := `
 		// camel-k: dependency=mvn:org.my:lib:1.0
 		// camel-k: dependency=camel-k:camel-dep
 	`
-	fileName := path.Join(dir, "simple.groovy")
-	err = ioutil.WriteFile(fileName, []byte(file), 0o400)
-	assert.NoError(t, err)
+		fileName := path.Join(dir, "simple.groovy")
+		err := ioutil.WriteFile(fileName, []byte(file), 0o400)
+		assert.NoError(t, err)
+
+		cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "local", "inspect", fileName})
+		assert.NoError(t, err)
+		assert.NotNil(t, cmd)
+		assert.Equal(t, []string{"local", "inspect", fileName, "--dependency=mvn:org.my:lib:1.0", "--dependency=camel-k:camel-dep"}, flags)
+
+		return nil
+	})
 
-	cmd, flags, err := NewKamelWithModelineCommand(context.TODO(), []string{"kamel", "local", "inspect", fileName})
 	assert.NoError(t, err)
-	assert.NotNil(t, cmd)
-	assert.Equal(t, []string{"local", "inspect", fileName, "--dependency=mvn:org.my:lib:1.0", "--dependency=camel-k:camel-dep"}, flags)
 }
diff --git a/pkg/cmd/root_test.go b/pkg/cmd/root_test.go
index 19db7171c..2189ed5d6 100644
--- a/pkg/cmd/root_test.go
+++ b/pkg/cmd/root_test.go
@@ -50,7 +50,9 @@ func kamelTestPreAddCommandInit() (*RootCmdOptions, *cobra.Command) {
 
 func TestLoadFromEnvVar(t *testing.T) {
 	// shows how to include a "," character inside an env value see VAR1 value
-	os.Setenv("KAMEL_RUN_ENVS", "\"VAR1=value,\"\"othervalue\"\"\",VAR2=value2")
+	if err := os.Setenv("KAMEL_RUN_ENVS", "\"VAR1=value,\"\"othervalue\"\"\",VAR2=value2"); err != nil {
+		t.Fatalf("Unexpected error: %v", err)
+	}
 
 	runCmdOptions, rootCmd, _ := initializeRunCmdOptions(t)
 
@@ -87,7 +89,10 @@ func TestLoadFromFile(t *testing.T) {
 }
 
 func TestPrecedenceEnvVarOverFile(t *testing.T) {
-	os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar")
+	if err := os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar"); err != nil {
+		t.Fatalf("Unexpected error: %v", err)
+	}
+
 	propertiesFile := []byte(`kamel.run.envs: VAR2=file`)
 	viper.SetConfigType("properties")
 	readViperConfigFromBytes(t, propertiesFile)
@@ -107,7 +112,10 @@ func TestPrecedenceEnvVarOverFile(t *testing.T) {
 }
 
 func TestPrecedenceCommandLineOverEverythingElse(t *testing.T) {
-	os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar")
+	if err := os.Setenv("KAMEL_RUN_ENVS", "VAR1=envVar"); err != nil {
+		t.Fatalf("Unexpected error: %v", err)
+	}
+
 	propertiesFile := []byte(`kamel.run.envs: VAR2=file`)
 	viper.SetConfigType("properties")
 	readViperConfigFromBytes(t, propertiesFile)
diff --git a/pkg/controller/integrationplatform/create_test.go b/pkg/controller/integrationplatform/create_test.go
index b7f038e79..18b19299c 100644
--- a/pkg/controller/integrationplatform/create_test.go
+++ b/pkg/controller/integrationplatform/create_test.go
@@ -59,7 +59,10 @@ func TestCreate(t *testing.T) {
 	assert.Nil(t, err)
 	assert.NotEmpty(t, list.Items)
 
-	for _, k := range resources.WithPrefix("/camel-catelog-") {
+	items, err := resources.WithPrefix("/camel-catelog-")
+	assert.Nil(t, err)
+
+	for _, k := range items {
 		found := false
 
 		for _, c := range list.Items {
diff --git a/pkg/resources/resources_test.go b/pkg/resources/resources_test.go
index 8fc71717d..3f2a544ff 100644
--- a/pkg/resources/resources_test.go
+++ b/pkg/resources/resources_test.go
@@ -22,34 +22,94 @@ import (
 	"strings"
 	"testing"
 
-	"github.com/stretchr/testify/assert"
 	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 	"k8s.io/apimachinery/pkg/util/yaml"
+
+	"github.com/stretchr/testify/assert"
 )
 
+func NoErrorAndNotEmptyBytes(t *testing.T, path string, callable func(path string) ([]byte, error)) {
+	t.Helper()
+
+	object, err := callable(path)
+
+	assert.Nil(t, err)
+	assert.NotEmpty(t, object)
+}
+func NoErrorAndNotEmptyString(t *testing.T, path string, callable func(path string) (string, error)) {
+	t.Helper()
+
+	object, err := callable(path)
+
+	assert.Nil(t, err)
+	assert.NotEmpty(t, object)
+}
+
+func NoErrorAndContains(t *testing.T, path string, contains string, callable func(path string) ([]string, error)) {
+	t.Helper()
+
+	elements, err := callable(path)
+
+	assert.Nil(t, err)
+	assert.Contains(t, elements, contains)
+}
+func NoErrorAndNotContains(t *testing.T, path string, contains string, callable func(path string) ([]string, error)) {
+	t.Helper()
+
+	elements, err := callable(path)
+
+	assert.Nil(t, err)
+	assert.NotContains(t, elements, contains)
+}
+func NoErrorAndEmpty(t *testing.T, path string, callable func(path string) ([]string, error)) {
+	t.Helper()
+
+	elements, err := callable(path)
+
+	assert.Nil(t, err)
+	assert.Empty(t, elements)
+}
+
+func ErrorBytes(t *testing.T, path string, callable func(path string) ([]byte, error)) {
+	t.Helper()
+
+	_, err := callable(path)
+	assert.NotNil(t, err)
+}
+func ErrorString(t *testing.T, path string, callable func(path string) (string, error)) {
+
+	t.Helper()
+
+	_, err := callable(path)
+	assert.NotNil(t, err)
+}
+
 func TestGetResource(t *testing.T) {
-	assert.NotEmpty(t, Resource("manager/operator-service-account.yaml"))
-	assert.NotEmpty(t, Resource("/manager/operator-service-account.yaml"))
-	assert.NotEmpty(t, ResourceAsString("manager/operator-service-account.yaml"))
-	assert.NotEmpty(t, ResourceAsString("/manager/operator-service-account.yaml"))
-	assert.Contains(t, Resources("/manager"), "/manager/operator-service-account.yaml")
+	NoErrorAndNotEmptyBytes(t, "manager/operator-service-account.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/manager/operator-service-account.yaml", Resource)
+	NoErrorAndNotEmptyString(t, "manager/operator-service-account.yaml", ResourceAsString)
+	NoErrorAndNotEmptyString(t, "/manager/operator-service-account.yaml", ResourceAsString)
+	NoErrorAndContains(t, "/manager", "/manager/operator-service-account.yaml", Resources)
 }
 
 func TestGetNoResource(t *testing.T) {
-	assert.Empty(t, Resource("manager/operator-service-account.json"))
-	assert.Empty(t, Resource("/manager/operator-service-account.json"))
-	assert.Empty(t, ResourceAsString("manager/operator-service-account.json"))
-	assert.Empty(t, ResourceAsString("/manager/operator-service-account.json"))
-	assert.NotContains(t, Resources("/"), "/manager/operator-service-account.json")
+	ErrorBytes(t, "manager/operator-service-account.json", Resource)
+	ErrorBytes(t, "/manager/operator-service-account.json", Resource)
+	ErrorString(t, "manager/operator-service-account.json", ResourceAsString)
+	ErrorString(t, "/manager/operator-service-account.json", ResourceAsString)
+	NoErrorAndNotContains(t, "/", "/manager/operator-service-account.json", Resources)
 }
 
 func TestResources(t *testing.T) {
-	assert.Contains(t, Resources("/manager"), "/manager/operator-service-account.yaml")
-	assert.Contains(t, Resources("/manager/"), "/manager/operator-service-account.yaml")
-	assert.NotContains(t, Resources("/manager"), "kustomize.yaml")
-	assert.Empty(t, Resources("/dirnotexist"))
+	NoErrorAndContains(t, "/manager", "/manager/operator-service-account.yaml", Resources)
+	NoErrorAndContains(t, "/manager/", "/manager/operator-service-account.yaml", Resources)
+	NoErrorAndNotContains(t, "/manager/", "kustomize.yaml", Resources)
+	NoErrorAndEmpty(t, "/dirnotexist", Resources)
+
+	items, err := Resources("/")
+	assert.Nil(t, err)
 
-	for _, res := range Resources("/") {
+	for _, res := range items {
 		if strings.Contains(res, "java.tmpl") {
 			assert.Fail(t, "Resources should not return nested files")
 		}
@@ -57,20 +117,21 @@ func TestResources(t *testing.T) {
 			assert.Fail(t, "Resources should not return nested dirs")
 		}
 	}
-	assert.Contains(t, Resources("/templates"), "/templates/java.tmpl")
+
+	NoErrorAndContains(t, "/templates", "/templates/java.tmpl", Resources)
 }
 
 func TestResourcesWithPrefix(t *testing.T) {
-	assert.Contains(t, WithPrefix("/manager/"), "/manager/operator-service-account.yaml")
-	assert.Contains(t, WithPrefix("/manager/op"), "/manager/operator-service-account.yaml")
-	assert.Contains(t, WithPrefix("/manager/operator-service-account"), "/manager/operator-service-account.yaml")
-
-	assert.Contains(t, WithPrefix("/traits"), "/traits.yaml")
+	NoErrorAndContains(t, "/manager/", "/manager/operator-service-account.yaml", WithPrefix)
+	NoErrorAndContains(t, "/manager/op", "/manager/operator-service-account.yaml", WithPrefix)
+	NoErrorAndContains(t, "/manager/operator-service-account", "/manager/operator-service-account.yaml", WithPrefix)
+	NoErrorAndContains(t, "/traits", "/traits.yaml", WithPrefix)
 
 	// directory needs the slash on the end
-	assert.NotContains(t, WithPrefix("/manager"), "/manager/operator-service-account.yaml")
+	NoErrorAndNotContains(t, "/manager", "/manager/operator-service-account.yaml", WithPrefix)
+
 	// need to get to at least the same directory as the required files
-	assert.NotContains(t, WithPrefix("/"), "/manager/operator-service-account.yaml")
+	NoErrorAndNotContains(t, "/", "/manager/operator-service-account.yaml", WithPrefix)
 }
 
 func TestTemplateResource(t *testing.T) {
@@ -103,11 +164,11 @@ func TestTemplateResource(t *testing.T) {
 }
 
 func TestCRDResources(t *testing.T) {
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_builds.yaml"))
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_camelcatalogs.yaml"))
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_integrationkits.yaml"))
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_integrationplatforms.yaml"))
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_integrations.yaml"))
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_kameletbindings.yaml"))
-	assert.NotEmpty(t, Resource("/crd/bases/camel.apache.org_kamelets.yaml"))
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_builds.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_camelcatalogs.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_integrationkits.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_integrationplatforms.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_integrations.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_kameletbindings.yaml", Resource)
+	NoErrorAndNotEmptyBytes(t, "/crd/bases/camel.apache.org_kamelets.yaml", Resource)
 }
diff --git a/pkg/util/sync/file_test.go b/pkg/util/sync/file_test.go
index 792cd6041..aa5815a20 100644
--- a/pkg/util/sync/file_test.go
+++ b/pkg/util/sync/file_test.go
@@ -31,7 +31,9 @@ import (
 func TestFile(t *testing.T) {
 	file, err := os.CreateTemp("", "camel-k-test-*")
 	assert.Nil(t, err)
-	defer os.Remove(file.Name())
+	defer func() {
+		_ = os.Remove(file.Name())
+	}()
 
 	ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(100*time.Second))
 	defer cancel()