From 6c7d66f548edf83b8ecff296587fae1afc218710 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Wed, 6 Nov 2024 16:02:33 +0000 Subject: [PATCH 1/2] build: build static binaries with latest pkgs On nixpkgs bug where windows platform is set incorrectly for static packages: 281596 This can be worked around by using pkgStatic.pkgsCross rather than the other way around, or simply by replacing the package. As it happens, the tls build for windows doesn't need openssl, so we can remove it entirely and skip this issue altogether. On darwin, libiconv is failing to build, but also seems to not be required anymore, and so also removing it! Signed-off-by: Tiago Castro --- nix/lib/rust.nix | 12 +++--------- nix/pkgs/utils/default.nix | 12 +----------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/nix/lib/rust.nix b/nix/lib/rust.nix index 4725dbbe5..7d8ac6628 100644 --- a/nix/lib/rust.nix +++ b/nix/lib/rust.nix @@ -1,6 +1,7 @@ { pkgs }: let lib = pkgs.lib; + sources = import ../sources.nix; in rec { makeRustTarget = platform: pkgs.rust.toRustTargetSpec platform; @@ -30,7 +31,7 @@ rec { os = platform: builtins.replaceStrings [ "${platform.qemuArch}-" ] [ "" ] platform.system; hostPlatform = "${pkgs.rust.toRustTargetSpec pkgs.pkgsStatic.hostPlatform}"; targetPlatform = "${pkgs.rust.toRustTargetSpec pkgs.pkgsCross."${target}".hostPlatform}"; - pkgsTarget = if hostPlatform == targetPlatform then pkgs.pkgsStatic else pkgs.pkgsCross."${target}"; + pkgsTarget = if hostPlatform == targetPlatform then pkgs else pkgs.pkgsCross."${target}"; pkgsTargetNative = if hostPlatform == targetPlatform then pkgs else if hostOs == targetOs then import sources.nixpkgs { @@ -63,14 +64,7 @@ rec { addPreBuild = ""; nativeBuildInputs = with pkgs; [ pkg-config protobuf paperclip which git ] ++ - [ rustPlatformDeps.pkgsTarget.stdenv.cc ] ++ - lib.optional (rustPlatformDeps.pkgsTarget.hostPlatform.isDarwin) - [ - (rustPlatformDeps.pkgsTarget.libiconv.override { - enableStatic = true; - enableShared = false; - }) - ]; + [ rustPlatformDeps.pkgsTarget.stdenv.cc ]; addNativeBuildInputs = [ ]; buildInputs = if (rustPlatformDeps.pkgsTarget.hostPlatform.isWindows) then with rustPlatformDeps.pkgsTargetNative.windows; [ mingw_w64_pthreads pthreads ] else [ ]; }; diff --git a/nix/pkgs/utils/default.nix b/nix/pkgs/utils/default.nix index 455f13491..593d1364c 100644 --- a/nix/pkgs/utils/default.nix +++ b/nix/pkgs/utils/default.nix @@ -15,19 +15,9 @@ let buildKubectlPlugin = { target, release, addBuildOptions ? [ ] }: let platformDeps = channel.rustPlatformDeps { inherit target sources; }; - # required for darwin because its pkgsStatic is not static! - static_ssl = (platformDeps.pkgsTarget.pkgsStatic.openssl.override { - static = true; - }); rustBuildOpts = channel.rustBuilderOpts { rustPlatformDeps = platformDeps; } // { buildOptions = [ "-p" "kubectl-plugin" ] ++ addBuildOptions; - ${if !pkgs.hostPlatform.isDarwin then "addNativeBuildInputs" else null} = [ platformDeps.pkgsTargetNative.pkgsStatic.openssl.dev ]; - addPreBuild = preBuildOpenApi + '' - export OPENSSL_STATIC=1 - '' + lib.optionalString (pkgs.hostPlatform.isDarwin) '' - export OPENSSL_LIB_DIR=${static_ssl.out}/lib - export OPENSSL_INCLUDE_DIR=${static_ssl.dev}/include - ''; + addPreBuild = preBuildOpenApi; }; name = "kubectl-plugin"; in From 0a7448dc33d9bfa4f73881b7a328451ae8734a29 Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Thu, 7 Nov 2024 01:16:26 +0000 Subject: [PATCH 2/2] fix(kubectl-plugin): add more namespace error information Add more interesting info when using wrong namespace, rather simply stating service not found! Previous error: Service 'app=api-rest' not found New error: Service 'app=api-rest' not found on 'NameSpace(Some("mayastor"))' Are you on the correct namespace? Signed-off-by: Tiago Castro --- Cargo.lock | 4 ++++ dependencies/control-plane | 2 +- k8s/plugin/Cargo.toml | 1 + k8s/plugin/src/resources/mod.rs | 13 +++++++++++++ .../src/collect/persistent_store/mod.rs | 2 +- k8s/upgrade/src/plugin/error.rs | 2 +- 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e17be3f0..30e2cb947 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2144,6 +2144,7 @@ dependencies = [ "kube 0.94.2", "serde_json", "shutdown", + "thiserror", "tokio", "tokio-stream", "tower 0.5.1", @@ -2162,8 +2163,10 @@ dependencies = [ "kube 0.94.2", "kube-forward", "openapi", + "thiserror", "tonic", "tower 0.5.1", + "url", "utils", ] @@ -2231,6 +2234,7 @@ dependencies = [ "console-logger", "constants", "humantime", + "kube-forward", "kube-proxy", "openapi", "rest-plugin", diff --git a/dependencies/control-plane b/dependencies/control-plane index 4ec8c0841..dd21e4e27 160000 --- a/dependencies/control-plane +++ b/dependencies/control-plane @@ -1 +1 @@ -Subproject commit 4ec8c0841521d0394a8a2272864e06d7663d81d0 +Subproject commit dd21e4e276d2d8701d3935c2299219a234ccd955 diff --git a/k8s/plugin/Cargo.toml b/k8s/plugin/Cargo.toml index e95daf15e..e53a41748 100644 --- a/k8s/plugin/Cargo.toml +++ b/k8s/plugin/Cargo.toml @@ -25,6 +25,7 @@ console-logger = { path = "../../console-logger" } supportability = { path = "../supportability" } upgrade = { path = "../upgrade" } kube-proxy = { path = "../../dependencies/control-plane/k8s/proxy" } +kube-forward = { path = "../../dependencies/control-plane/k8s/forward" } tokio = { version = "1.41.0" } anyhow = "1.0.92" clap = { version = "4.5.20", features = ["color", "derive"] } diff --git a/k8s/plugin/src/resources/mod.rs b/k8s/plugin/src/resources/mod.rs index a40d95739..da075cd27 100644 --- a/k8s/plugin/src/resources/mod.rs +++ b/k8s/plugin/src/resources/mod.rs @@ -1,3 +1,4 @@ +use anyhow::anyhow; use clap::Parser; use openapi::tower::client::Url; use plugin::{ @@ -160,6 +161,18 @@ impl From for Error { } } +impl From for Error { + fn from(e: kube_proxy::Error) -> Self { + if let error @ kube_proxy::Error::Forward { + source: kube_forward::Error::ServiceNotFound { .. }, + } = e + { + return Error::Generic(anyhow!("{error}\n Are you on the correct namespace?")); + } + Error::Generic(anyhow!(e)) + } +} + /// Initialise the REST client. pub async fn init_rest(cli_args: &CliArgs) -> Result<(), Error> { // Use the supplied URL if there is one otherwise obtain one from the kubeconfig file. diff --git a/k8s/supportability/src/collect/persistent_store/mod.rs b/k8s/supportability/src/collect/persistent_store/mod.rs index 4f563f3f1..5a79e34d3 100644 --- a/k8s/supportability/src/collect/persistent_store/mod.rs +++ b/k8s/supportability/src/collect/persistent_store/mod.rs @@ -13,7 +13,7 @@ pub(crate) enum EtcdError { K8sResource(K8sResourceError), IOError(std::io::Error), Custom(String), - CreateClient(anyhow::Error), + CreateClient(kube_proxy::Error), } impl From for EtcdError { diff --git a/k8s/upgrade/src/plugin/error.rs b/k8s/upgrade/src/plugin/error.rs index e7b9e0fd1..b3c381887 100644 --- a/k8s/upgrade/src/plugin/error.rs +++ b/k8s/upgrade/src/plugin/error.rs @@ -206,7 +206,7 @@ pub enum Error { /// Openapi configuration error. #[snafu(display("openapi configuration Error: {}", source))] - OpenapiClientConfiguration { source: anyhow::Error }, + OpenapiClientConfiguration { source: kube_proxy::Error }, /// Error when opening a file. #[snafu(display("Failed to open file {}: {}", filepath.display(), source))]