-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UDTF that detects linux kernel header installation and add column…
… to `GetAgentStatus` (#2052) Summary: Add UDTF that detects linux kernel header installation and add column to `GetAgentStatus` This is a prerequisite to accomplish #2051. The `px deploy` command uses the GetAgentStatus UDTF in its final [healthcheck step](https://github.com/pixie-io/pixie/blob/854062111cf4b91a40649a2e2647c88c0a68b0db/src/pixie_cli/pkg/cmd/deploy.go#L607-L613). With this kernel header detection in place, the `px` cli can use the results from the `px/agent_status` script to print a warning message if kernel headers aren't detected. The helm install flow needs to be covered as well. My hope is that this UDTF could be used for that use case as well, but I need to further investigate the details of that. Relevant Issues: #2051 Type of change: /kind feature Test Plan: Skaffolded to a Ubuntu GKE cluster and tested the following - [x] Kelvin always reports `false` as it doesn't bind mount `/` to `/host` - [x] PEM running on host without `linux-headers-$(uname -r)` package reports `false` - [x] PEM running on host with `linux-headers-$(uname -r)` package reports `true` ``` $ gcloud compute ssh gke-dev-cluster-ddelnano-default-pool-a27c1ac2-x5k2 --internal-ip -- 'ls -alh /lib/modules/$(uname -r)/build' lrwxrwxrwx 1 root root 38 Aug 9 15:25 /lib/modules/5.15.0-1065-gke/build -> /usr/src/linux-headers-5.15.0-1065-gke $ gcloud compute ssh gke-dev-cluster-ddelnano-default-pool-a27c1ac2-j6pg --internal-ip -- 'ls -alh /lib/modules/$(uname -r)/build' ls: cannot access '/lib/modules/5.15.0-1065-gke/build': No such file or directory ``` ![Screen Shot 2024-12-02 at 9 30 29 AM](https://github.com/user-attachments/assets/9fa862f8-5a6c-46d6-8899-bfaf2bdf3371) Changelog Message: Add `GetLinuxHeadersStatus` UDTF and add `kernel_headers_installed` column to `GetAgentStatus` --------- Signed-off-by: Dom Del Nano <[email protected]>
- Loading branch information
Showing
17 changed files
with
353 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2018- The Pixie Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "src/common/system/linux_headers_utils.h" | ||
|
||
#include <fstream> | ||
#include <limits> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include "src/common/base/file.h" | ||
#include "src/common/fs/fs_wrapper.h" | ||
#include "src/common/system/config.h" | ||
|
||
namespace px { | ||
namespace system { | ||
|
||
StatusOr<std::filesystem::path> ResolvePossibleSymlinkToHostPath(const std::filesystem::path p) { | ||
// Check if "p" is a symlink. | ||
std::error_code ec; | ||
const bool is_symlink = std::filesystem::is_symlink(p, ec); | ||
if (ec) { | ||
return error::NotFound(absl::Substitute("Did not find the host headers at path: $0, $1.", | ||
p.string(), ec.message())); | ||
} | ||
|
||
if (!is_symlink) { | ||
// Not a symlink, we are good now. | ||
return p; | ||
} | ||
|
||
// Resolve the symlink, and re-convert to a host path.. | ||
const std::filesystem::path resolved = std::filesystem::read_symlink(p, ec); | ||
if (ec) { | ||
return error::Internal(ec.message()); | ||
} | ||
|
||
// Relative paths containing "../" can result in an invalid host mount path when using | ||
// ToHostPath. Therefore, we need to treat the absolute and relative cases differently. | ||
std::filesystem::path resolved_host_path; | ||
if (resolved.is_absolute()) { | ||
resolved_host_path = system::Config::GetInstance().ToHostPath(resolved); | ||
VLOG(1) << absl::Substitute( | ||
"Symlink target is an absolute path. Converting that to host path: $0 -> $1.", | ||
resolved.string(), resolved_host_path.string()); | ||
} else { | ||
resolved_host_path = p.parent_path(); | ||
resolved_host_path /= resolved.string(); | ||
VLOG(1) << absl::Substitute( | ||
"Symlink target is a relative path. Concatenating it to parent directory: $0", | ||
resolved_host_path.string()); | ||
} | ||
|
||
// Downstream won't be ok unless the resolved host path exists; return an error if needed. | ||
if (!fs::Exists(resolved_host_path)) { | ||
return error::NotFound(absl::Substitute("Did not find host headers at resolved path: $0.", | ||
resolved_host_path.string())); | ||
} | ||
return resolved_host_path; | ||
} | ||
|
||
} // namespace system | ||
} // namespace px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2018- The Pixie Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <filesystem> | ||
|
||
#include "src/common/base/base.h" | ||
|
||
namespace px { | ||
namespace system { | ||
|
||
constexpr std::string_view kLinuxModulesDir = "/lib/modules/"; | ||
|
||
/** | ||
* Resolves a possible symlink path to its corresponding host filesystem path. | ||
* | ||
* This function takes a filesystem path and checks if it is a symbolic link. If it is, | ||
* the symlink is resolved to its target path. Depending on whether the target is an absolute | ||
* or relative path, it is further processed to convert it into a valid host path (as in | ||
* Config::ToHostPath(...) path). | ||
* | ||
* If the input path is not a symlink, it is returned as-is. The function ensures that | ||
* the final resolved path exists in the host filesystem before returning it. Errors are | ||
* returned when the path does not exist, the resolution fails, or when there is an issue | ||
* accessing the filesystem. | ||
*/ | ||
StatusOr<std::filesystem::path> ResolvePossibleSymlinkToHostPath(const std::filesystem::path p); | ||
|
||
} // namespace system | ||
} // namespace px |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.