From 441c4016f5f9ba8f554ab58f26d1e4132150161c Mon Sep 17 00:00:00 2001 From: bragi92 Date: Mon, 14 Oct 2024 17:32:18 -0700 Subject: [PATCH] fix: ccp fixes (#993) [comment]: # (Note that your PR title should follow the conventional commit format: https://conventionalcommits.org/en/v1.0.0/#summary) # PR Description [comment]: # (The below checklist is for PRs adding new features. If a box is not checked, add a reason why it's not needed.) # New Feature Checklist - [ ] List telemetry added about the feature. - [ ] Link to the one-pager about the feature. - [ ] List any tasks necessary for release (3P docs, AKS RP chart changes, etc.) after merging the PR. - [ ] Attach results of scale and perf testing. [comment]: # (The below checklist is for code changes. Not all boxes necessarily need to be checked. Build, doc, and template changes do not need to fill out the checklist.) # Tests Checklist - [ ] Have end-to-end Ginkgo tests been run on your cluster and passed? To bootstrap your cluster to run the tests, follow [these instructions](/otelcollector/test/README.md#bootstrap-a-dev-cluster-to-run-ginkgo-tests). - Labels used when running the tests on your cluster: - [ ] `operator` - [ ] `windows` - [ ] `arm64` - [ ] `arc-extension` - [ ] `fips` - [ ] Have new tests been added? For features, have tests been added for this feature? For fixes, is there a test that could have caught this issue and could validate that the fix works? - [ ] Is a new scrape job needed? - [ ] The scrape job was added to the folder [test-cluster-yamls](/otelcollector/test/test-cluster-yamls/) in the correct configmap or as a CR. - [ ] Was a new test label added? - [ ] A string constant for the label was added to [constants.go](/otelcollector/test/utils/constants.go). - [ ] The label and description was added to the [test README](/otelcollector/test/README.md). - [ ] The label was added to this [PR checklist](/.github/pull_request_template). - [ ] The label was added as needed to [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml). - [ ] Are additional API server permissions needed for the new tests? - [ ] These permissions have been added to [api-server-permissions.yaml](/otelcollector/test/testkube/api-server-permissions.yaml). - [ ] Was a new test suite (a new folder under `/tests`) added? - [ ] The new test suite is included in [testkube-test-crs.yaml](/otelcollector/test/testkube/testkube-test-crs.yaml). --------- Co-authored-by: Vishwanath --- otelcollector/build/linux/ccp/Dockerfile | 4 ++-- otelcollector/shared/process_utilities.go | 28 ++++++++++++++--------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/otelcollector/build/linux/ccp/Dockerfile b/otelcollector/build/linux/ccp/Dockerfile index 1a763e3b0..8ba0aeb77 100644 --- a/otelcollector/build/linux/ccp/Dockerfile +++ b/otelcollector/build/linux/ccp/Dockerfile @@ -54,7 +54,7 @@ WORKDIR /main RUN go version RUN go mod download RUN apt-get update && apt-get install gcc-aarch64-linux-gnu -y -RUN go build -o ccpmain.exe ./main.go +RUN go build -o ccpmain ./main.go FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 as builder ENV OS_TYPE "linux" @@ -76,7 +76,7 @@ COPY ./LICENSE $tmpdir/microsoft COPY ./NOTICE $tmpdir/microsoft COPY ./mdsd/envmdsd $tmpdir/ COPY ./build/linux/rpm-repos/ /etc/yum.repos.d/ -COPY --from=ccpmain-builder --chmod=777 /main/ccpmain.exe $tmpdir/main/ +COPY --from=ccpmain-builder --chmod=777 /main/ccpmain $tmpdir/main/ COPY ./react /static/react ARG TARGETARCH diff --git a/otelcollector/shared/process_utilities.go b/otelcollector/shared/process_utilities.go index 794cf68b0..ec7027d75 100644 --- a/otelcollector/shared/process_utilities.go +++ b/otelcollector/shared/process_utilities.go @@ -46,6 +46,23 @@ func IsProcessRunning(processName string) bool { // SetEnvAndSourceBashrc sets a key-value pair as an environment variable in the .bashrc file // and sources the file to apply changes immediately. If echo is true, it calls EchoVar func SetEnvAndSourceBashrc(key, value string, echo bool) error { + + // Set the environment variable + err := os.Setenv(key, value) + if err != nil { + return fmt.Errorf("failed to set environment variable: %v", err) + } + + // Conditionally call EchoVar + if echo { + EchoVar(key, value) + } + + if GetEnv("CCP_METRICS_ENABLED", "false") == "true" { + // return if in ccp mode as no bash shell present here + return nil + } + // Get user's home directory homeDir, err := os.UserHomeDir() if err != nil { @@ -83,17 +100,6 @@ func SetEnvAndSourceBashrc(key, value string, echo bool) error { return fmt.Errorf("failed to source .bashrc: %v", err) } - // Set the environment variable - err = os.Setenv(key, value) - if err != nil { - return fmt.Errorf("failed to set environment variable: %v", err) - } - - // Conditionally call EchoVar - if echo { - EchoVar(key, value) - } - return nil }