<p>I'm attempting to read the contents of a Kubernetes Secret using <code>kube-rs</code>. The secret contains a key named &quot;apiKey&quot;.</p>
<p>I seem to be able to pull the secret from the kube-apiserver (debug logging shows the correct contents of the secret) but I can't get to the value itself as it's returned as a <code>ByteString</code>.</p>
<p>I can't find a way to convert the <code>ByteString</code> to a <code>String</code>.</p>
<p>Could anyone kindly shed some light on this? My code is below, including my failed attempts and the related error messages.</p>
<pre><code>use kube::{Client, api::{Api, ResourceExt, ListParams, PostParams}};
use k8s_openapi::api::core::v1::Secret;
use bytes::Bytes;
use std::collections::BTreeMap;
use k8s_openapi::ByteString;

async fn get_credentials_from_secret(secret_namespace: &amp;String, secret_name: &amp;String) -&gt; Result&lt;String, kube::Error&gt; {

    let client = Client::try_default().await?;

    let secrets: Api&lt;Secret&gt; = Api::namespaced(client, secret_namespace);

    let secret: Secret = secrets.get(secret_name).await?;

    let secret_data: BTreeMap&lt;String, ByteString&gt;  = secret.data.unwrap();

    let api_key = &amp;secret_data[&quot;apiKey&quot;];
    println!(&quot;{:?}&quot;, api_key); // This prints 'ByteString([97, 112, 105, 107, 101, 121])'

//    let api_key_string: String = api_key.into(); // the trait `From&lt;&amp;ByteString&gt;` is not implemented for `std::string::String`
//    let api_key_slice = api_key.as_slice(); //  method not found in `&amp;ByteString
//    let api_key_string: String = api_key.serialize(); // method not found in `&amp;ByteString`
//    let api_key_string = String::from(api_key); // the trait `From&lt;&amp;ByteString&gt;` is not implemented for `std::string::String`

    Ok(&quot;Secret data here ideally!&quot;.to_string())

}
</code></pre>

<p>I faced the same issue. I saw that it had some serialization traits at <a href="https://docs.rs/k8s-openapi/0.13.1/src/k8s_openapi/lib.rs.html#482-506" rel="nofollow noreferrer">https://docs.rs/k8s-openapi/0.13.1/src/k8s_openapi/lib.rs.html#482-506</a>, so I resorted to using the <code>serde_json</code> crate which worked just fine.</p>
<pre><code>use k8s_openapi::ByteString;
...
let some_byte_str = ByteString(&quot;foobar&quot;.as_bytes().to_vec());
serde_json::to_string(&amp;some_byte_str).unwrap();
</code></pre>
