Skip to content

Commit eee8119

Browse files
committed
chore: Reuse existing error variant, and reformat it
1 parent 17a2764 commit eee8119

File tree

1 file changed

+6
-8
lines changed
  • rust/stackable-cockpit/src/utils/k8s

1 file changed

+6
-8
lines changed

rust/stackable-cockpit/src/utils/k8s/client.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,16 @@ pub enum Error {
5050
#[snafu(display("failed to run GVK discovery"))]
5151
GVKDiscoveryRun { source: kube::error::Error },
5252

53-
#[snafu(display("GVK {gvk:?} is not known"))]
54-
GVKUnknown { gvk: GroupVersionKind },
55-
5653
#[snafu(display("failed to deploy manifest because type of object {object:?} is not set"))]
5754
ObjectType { object: DynamicObject },
5855

59-
#[snafu(display("failed to deploy manifest because GVK {group}/{kind}@{version} cannot be resolved",
56+
// Using output close to Display for ObjectRef https://docs.rs/kube-runtime/0.99.0/src/kube_runtime/reflector/object_ref.rs.html#292-296
57+
#[snafu(display("failed to resolve GVK: {kind}.{version}.{group}",
6058
group = gvk.group,
6159
version = gvk.version,
6260
kind = gvk.kind
6361
))]
64-
DiscoveryResolve { gvk: GroupVersionKind },
62+
GVKResolve { gvk: GroupVersionKind },
6563

6664
#[snafu(display("failed to convert byte string into UTF-8 string"))]
6765
ByteStringConvert { source: FromUtf8Error },
@@ -134,7 +132,7 @@ impl Client {
134132
let (resource, capabilities) = self
135133
.resolve_gvk(&gvk)
136134
.await?
137-
.context(GVKUnknownSnafu { gvk })?;
135+
.context(GVKResolveSnafu { gvk })?;
138136

139137
let api: Api<DynamicObject> = match capabilities.scope {
140138
Scope::Cluster => {
@@ -176,7 +174,7 @@ impl Client {
176174
let (resource, _) = self
177175
.resolve_gvk(&gvk)
178176
.await?
179-
.context(GVKUnknownSnafu { gvk: gvk.clone() })?;
177+
.with_context(|| GVKResolveSnafu { gvk: gvk.clone() })?;
180178

181179
// CRDs are cluster scoped
182180
let api: Api<DynamicObject> = Api::all_with(self.client.clone(), &resource);
@@ -189,7 +187,7 @@ impl Client {
189187
object.metadata.resource_version = resource.resource_version();
190188
api.replace(&object.name_any(), &PostParams::default(), &object)
191189
.await
192-
.context(KubeClientReplaceSnafu { gvk })?;
190+
.with_context(|_| KubeClientReplaceSnafu { gvk })?;
193191
} else {
194192
// Create CRD if a previous version wasn't found
195193
api.create(&PostParams::default(), &object)

0 commit comments

Comments
 (0)