You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/05/24 13:50:27 UTC

[camel-k] 06/09: chore(lint): fixes

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 e49064758f17d897227f83cdc40b644624227752
Author: Pasquale Congiusti <pa...@gmail.com>
AuthorDate: Fri May 19 15:11:25 2023 +0200

    chore(lint): fixes
---
 pkg/controller/build/monitor_pod.go | 35 ++++++++++++++++++-----------------
 pkg/trait/builder.go                |  8 ++++----
 pkg/trait/quarkus.go                |  9 ---------
 3 files changed, 22 insertions(+), 30 deletions(-)

diff --git a/pkg/controller/build/monitor_pod.go b/pkg/controller/build/monitor_pod.go
index 439cacf0f..d16928e00 100644
--- a/pkg/controller/build/monitor_pod.go
+++ b/pkg/controller/build/monitor_pod.go
@@ -301,7 +301,7 @@ func (action *monitorPodAction) getTerminatedTime(pod *corev1.Pod) metav1.Time {
 	return finishedAt
 }
 
-// setConditionsFromTerminationMessages sets a condition for all those containers which have been terminated (successfully or not)
+// setConditionsFromTerminationMessages sets a condition for all those containers which have been terminated (successfully or not).
 func (action *monitorPodAction) setConditionsFromTerminationMessages(ctx context.Context, pod *corev1.Pod, buildStatus *v1.BuildStatus) {
 	var containers []corev1.ContainerStatus
 	containers = append(containers, pod.Status.InitContainerStatuses...)
@@ -309,6 +309,7 @@ func (action *monitorPodAction) setConditionsFromTerminationMessages(ctx context
 
 	for _, container := range containers {
 		if t := container.State.Terminated; t != nil {
+			var err error
 			terminationMessage := t.Message
 			// Dynamic condition type (it depends on each container name)
 			containerConditionType := v1.BuildConditionType(fmt.Sprintf("Container %s succeeded", container.Name))
@@ -316,22 +317,22 @@ func (action *monitorPodAction) setConditionsFromTerminationMessages(ctx context
 			if t.ExitCode != 0 {
 				containerSucceeded = corev1.ConditionFalse
 			}
-
-			var maxLines int64
-			// TODO we can make it a user variable !?
-			maxLines = 10
-			logOptions := corev1.PodLogOptions{
-				Container: container.Name,
-				TailLines: &maxLines,
-			}
-			terminationMessage, err := log.DumpLog(ctx, action.client, pod, logOptions)
-			if err != nil {
-				action.L.Errorf(err, "Dumping log for %s container in %s Pod failed", container.Name, pod.Name)
-				terminationMessage = fmt.Sprintf(
-					"Operator was not able to retrieve the error message, please, check the container %s log directly from %s Pod",
-					container.Name,
-					pod.Name,
-				)
+			if terminationMessage == "" {
+				// TODO we can make it a user variable !?
+				var maxLines int64 = 10
+				logOptions := corev1.PodLogOptions{
+					Container: container.Name,
+					TailLines: &maxLines,
+				}
+				terminationMessage, err = log.DumpLog(ctx, action.client, pod, logOptions)
+				if err != nil {
+					action.L.Errorf(err, "Dumping log for %s container in %s Pod failed", container.Name, pod.Name)
+					terminationMessage = fmt.Sprintf(
+						"Operator was not able to retrieve the error message, please, check the container %s log directly from %s Pod",
+						container.Name,
+						pod.Name,
+					)
+				}
 			}
 
 			terminationReason := fmt.Sprintf("%s (%d)", t.Reason, t.ExitCode)
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index bd20b38f1..a96ddee15 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -245,11 +245,11 @@ func getImageName(e *Environment) string {
 }
 
 func (t *builderTrait) customTasks() []v1.Task {
-	var customTasks []v1.Task
-	for _, t := range t.Tasks {
+	customTasks := make([]v1.Task, 0, len(t.Tasks))
+	for i, t := range t.Tasks {
 		// TODO, better strategy than a simple split!
 		splitted := strings.Split(t, ";")
-		customTasks = append(customTasks, v1.Task{
+		customTasks[i] = v1.Task{
 			Custom: &v1.UserTask{
 				BaseTask: v1.BaseTask{
 					Name: splitted[0],
@@ -257,7 +257,7 @@ func (t *builderTrait) customTasks() []v1.Task {
 				ContainerImage:   splitted[1],
 				ContainerCommand: splitted[2],
 			},
-		})
+		}
 	}
 	return customTasks
 }
diff --git a/pkg/trait/quarkus.go b/pkg/trait/quarkus.go
index c310e0a00..fb78962ba 100644
--- a/pkg/trait/quarkus.go
+++ b/pkg/trait/quarkus.go
@@ -347,15 +347,6 @@ func (t *quarkusTrait) isNativeKit(e *Environment) (bool, error) {
 	}
 }
 
-func (t *quarkusTrait) hasKitNativeType() bool {
-	for _, v := range t.PackageTypes {
-		if v == traitv1.NativePackageType {
-			return true
-		}
-	}
-	return false
-}
-
 func (t *quarkusTrait) applyWhenKitReady(e *Environment) error {
 	if e.IntegrationInRunningPhases() && t.isNativeIntegration(e) {
 		container := e.GetIntegrationContainer()