From c67927496d93301846ae0161757ff76ac895c3ce Mon Sep 17 00:00:00 2001 From: tamirdavid1 Date: Mon, 23 Dec 2024 13:58:51 +0200 Subject: [PATCH] chore: add comments + timeout for containerStatus request --- .../crd/bases/odigos.io_instrumentationconfigs.yaml | 9 +++++++++ .../bases/odigos.io_instrumentedapplications.yaml | 9 +++++++++ .../v1alpha1/instrumentedapplication_types.go | 13 ++++++------- k8sutils/pkg/cri/criwrapper.go | 6 +++++- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/api/config/crd/bases/odigos.io_instrumentationconfigs.yaml b/api/config/crd/bases/odigos.io_instrumentationconfigs.yaml index a42f3241b..8fb450866 100644 --- a/api/config/crd/bases/odigos.io_instrumentationconfigs.yaml +++ b/api/config/crd/bases/odigos.io_instrumentationconfigs.yaml @@ -431,8 +431,13 @@ spec: containerName: type: string criErrorMessage: + description: Stores the error message from the CRI runtime if + returned to prevent instrumenting the container if an error + exists. type: string envFromContainerRuntime: + description: Holds the environment variables retrieved from + the container runtime. items: properties: name: @@ -479,6 +484,10 @@ spec: type: string type: object runtimeUpdateState: + description: A temporary variable used during migration to track + whether the new runtime detection process has been executed. + If empty, it indicates the process has not yet been run. This + field may be removed later. type: string runtimeVersion: type: string diff --git a/api/config/crd/bases/odigos.io_instrumentedapplications.yaml b/api/config/crd/bases/odigos.io_instrumentedapplications.yaml index fdda57716..c8b17a444 100644 --- a/api/config/crd/bases/odigos.io_instrumentedapplications.yaml +++ b/api/config/crd/bases/odigos.io_instrumentedapplications.yaml @@ -91,8 +91,13 @@ spec: containerName: type: string criErrorMessage: + description: Stores the error message from the CRI runtime if + returned to prevent instrumenting the container if an error + exists. type: string envFromContainerRuntime: + description: Holds the environment variables retrieved from + the container runtime. items: properties: name: @@ -139,6 +144,10 @@ spec: type: string type: object runtimeUpdateState: + description: A temporary variable used during migration to track + whether the new runtime detection process has been executed. + If empty, it indicates the process has not yet been run. This + field may be removed later. type: string runtimeVersion: type: string diff --git a/api/odigos/v1alpha1/instrumentedapplication_types.go b/api/odigos/v1alpha1/instrumentedapplication_types.go index 099c86829..cbedca502 100644 --- a/api/odigos/v1alpha1/instrumentedapplication_types.go +++ b/api/odigos/v1alpha1/instrumentedapplication_types.go @@ -60,13 +60,12 @@ type RuntimeDetailsByContainer struct { OtherAgent *OtherAgent `json:"otherAgent,omitempty"` LibCType *common.LibCType `json:"libCType,omitempty"` - // These three fields are used to facilitate a new runtime detection process for the container runtime. - // - CriErrorMessage: Stores the error message from the CRI runtime to prevent instrumenting the container if an error exists. - // - EnvFromContainerRuntime: Holds the environment variables retrieved from the container runtime. - // - RuntimeUpdateState: A temporary variable used during migration to track whether the new runtime detection process has been executed. If empty, it indicates the process has not yet been run. This field may be removed later. - CriErrorMessage *string `json:"criErrorMessage,omitempty"` - EnvFromContainerRuntime []EnvVar `json:"envFromContainerRuntime,omitempty"` - RuntimeUpdateState *ProcessingState `json:"runtimeUpdateState,omitempty"` // Tracks whether the new runtime detection process has been executed. If empty, the process has not been executed. + // Stores the error message from the CRI runtime if returned to prevent instrumenting the container if an error exists. + CriErrorMessage *string `json:"criErrorMessage,omitempty"` + // Holds the environment variables retrieved from the container runtime. + EnvFromContainerRuntime []EnvVar `json:"envFromContainerRuntime,omitempty"` + // A temporary variable used during migration to track whether the new runtime detection process has been executed. If empty, it indicates the process has not yet been run. This field may be removed later. + RuntimeUpdateState *ProcessingState `json:"runtimeUpdateState,omitempty"` } // +kubebuilder:object:generate=true diff --git a/k8sutils/pkg/cri/criwrapper.go b/k8sutils/pkg/cri/criwrapper.go index 600818442..4f4ad8632 100644 --- a/k8sutils/pkg/cri/criwrapper.go +++ b/k8sutils/pkg/cri/criwrapper.go @@ -86,12 +86,16 @@ func (rc *CriClient) GetContainerInfo(ctx context.Context, containerID string) ( if rc.client == nil { return nil, fmt.Errorf("runtime client is not connected") } + // Set a timeout for the request + timeoutCtx, cancel := context.WithTimeout(ctx, 5*time.Second) + defer cancel() // Call the ContainerStatus API - response, err := rc.client.ContainerStatus(ctx, &criapi.ContainerStatusRequest{ + response, err := rc.client.ContainerStatus(timeoutCtx, &criapi.ContainerStatusRequest{ ContainerId: containerID, Verbose: true, }) + if err != nil { return nil, err }