@@ -3,16 +3,17 @@ use kube::{Resource, ResourceExt};
33use snafu:: { ResultExt , Snafu } ;
44use tracing:: warn;
55
6- use crate :: {
7- error:: { Error , OperatorResult } ,
8- kvp:: { Annotation , Annotations , Label , LabelError , Labels , ObjectLabels } ,
9- } ;
6+ use crate :: kvp:: { Annotation , Annotations , Label , LabelError , Labels , ObjectLabels } ;
7+
8+ type Result < T , E = Error > = std:: result:: Result < T , E > ;
109
11- // NOTE (Techassi): Think about that name
1210#[ derive( Debug , PartialEq , Snafu ) ]
13- pub enum ObjectMetaBuilderError {
11+ pub enum Error {
1412 #[ snafu( display( "failed to set recommended labels" ) ) ]
1513 RecommendedLabels { source : LabelError } ,
14+
15+ #[ snafu( display( "object is missing key {key:?}" ) ) ]
16+ MissingObjectKey { key : & ' static str } ,
1617}
1718
1819/// A builder to build [`ObjectMeta`] objects.
@@ -89,7 +90,7 @@ impl ObjectMetaBuilder {
8990 resource : & T ,
9091 block_owner_deletion : Option < bool > ,
9192 controller : Option < bool > ,
92- ) -> OperatorResult < & mut Self > {
93+ ) -> Result < & mut Self > {
9394 self . ownerreference = Some (
9495 OwnerReferenceBuilder :: new ( )
9596 . initialize_from_resource ( resource)
@@ -151,7 +152,7 @@ impl ObjectMetaBuilder {
151152 pub fn with_recommended_labels < T : Resource > (
152153 & mut self ,
153154 object_labels : ObjectLabels < T > ,
154- ) -> Result < & mut Self , ObjectMetaBuilderError > {
155+ ) -> Result < & mut Self > {
155156 let recommended_labels =
156157 Labels :: recommended ( object_labels) . context ( RecommendedLabelsSnafu ) ?;
157158
@@ -284,24 +285,24 @@ impl OwnerReferenceBuilder {
284285 self
285286 }
286287
287- pub fn build ( & self ) -> OperatorResult < OwnerReference > {
288+ pub fn build ( & self ) -> Result < OwnerReference > {
288289 Ok ( OwnerReference {
289290 api_version : match self . api_version {
290- None => return Err ( Error :: MissingObjectKey { key : "api_version" } ) ,
291+ None => return MissingObjectKeySnafu { key : "api_version" } . fail ( ) ,
291292 Some ( ref api_version) => api_version. clone ( ) ,
292293 } ,
293294 block_owner_deletion : self . block_owner_deletion ,
294295 controller : self . controller ,
295296 kind : match self . kind {
296- None => return Err ( Error :: MissingObjectKey { key : "kind" } ) ,
297+ None => return MissingObjectKeySnafu { key : "kind" } . fail ( ) ,
297298 Some ( ref kind) => kind. clone ( ) ,
298299 } ,
299300 name : match self . name {
300- None => return Err ( Error :: MissingObjectKey { key : "name" } ) ,
301+ None => return MissingObjectKeySnafu { key : "name" } . fail ( ) ,
301302 Some ( ref name) => name. clone ( ) ,
302303 } ,
303304 uid : match self . uid {
304- None => return Err ( Error :: MissingObjectKey { key : "uid" } ) ,
305+ None => return MissingObjectKeySnafu { key : "uid" } . fail ( ) ,
305306 Some ( ref uid) => uid. clone ( ) ,
306307 } ,
307308 } )
0 commit comments