@@ -454,7 +454,11 @@ func NewBucketRequest(
454454 r .AccountName = ob .Spec .AdditionalState ["account" ]
455455 bucketClassName := ob .Spec .AdditionalState ["bucketclass" ]
456456
457- bucketClass , exists := getBucketClass (r .OBC , bucketOptions , p .Namespace , util .KubeCheck )
457+ obcNamespace := ""
458+ if ob .Spec .ClaimRef != nil {
459+ obcNamespace = ob .Spec .ClaimRef .Namespace
460+ }
461+ bucketClass , exists := getBucketClassByName (bucketClassName , obcNamespace , p .Namespace , util .KubeCheck )
458462 if ! exists {
459463 p .Logger .Warnf ("BucketClass %q not found in namespace %q" , bucketClassName , p .Namespace )
460464 }
@@ -910,16 +914,10 @@ func (r *BucketRequest) updateReplicationPolicy(ob *nbv1.ObjectBucket) error {
910914 return nil
911915}
912916
913- // getBucketClass takes an OBC, bucketoptions and provisioner namespace and returns the bucketClass
914- //
915- // If BucketClass name is not specified in the OBC, then the empty string is returned with exists=false
916- // If BucketClass name is specified in the OBC, then:
917- // - if the bucketclass is found in the obc namespace, then that bucketclass is returned
918- // with exists=true
919- // - if the bucketclass is found in the provisioner namespace, then that buckeclass is
920- // returned with exists=true
921- // - if the bucketclass is not found in the obc namespace or the provisioner namespace, then the
922- // bucketclass with namespace set to provisioner namespace is returned with exists=false
917+ // getBucketClass extracts the bucket class name from an OBC (or StorageClass parameters)
918+ // and delegates to getBucketClassByName. Used by the create/provision path where a full
919+ // ObjectBucketClaim is available. On the update path (ObjectBucket only), callers should
920+ // use getBucketClassByName directly with values from AdditionalState and ClaimRef.
923921func getBucketClass (
924922 obc * nbv1.ObjectBucketClaim ,
925923 bucketOptions * obAPI.BucketOptions ,
@@ -942,16 +940,40 @@ func getBucketClass(
942940 if bucketclassName == "" && bucketOptions != nil {
943941 bucketclassName = bucketOptions .Parameters ["bucketclass" ]
944942 }
945- if bucketclassName == "" {
943+ return getBucketClassByName (bucketclassName , obc .Namespace , provisionerNS , checkExists )
944+ }
945+
946+ // getBucketClassByName looks up a BucketClass by name in the OBC namespace first,
947+ // then in the provisioner (NooBaa system) namespace.
948+ //
949+ // If bucketClassName is empty, returns exists=false.
950+ // If found in obcNamespace, returns that BucketClass with exists=true.
951+ // If found in provisionerNS, returns that BucketClass with exists=true.
952+ // If not found, returns a BucketClass with namespace set to provisionerNS and exists=false.
953+ func getBucketClassByName (
954+ bucketClassName , obcNamespace , provisionerNS string ,
955+ checkExists func (client.Object ) bool ,
956+ ) (bc * nbv1.BucketClass , exists bool ) {
957+ bucketClass := & nbv1.BucketClass {
958+ TypeMeta : metav1.TypeMeta {Kind : "BucketClass" },
959+ ObjectMeta : metav1.ObjectMeta {
960+ Name : "" ,
961+ Namespace : "" ,
962+ },
963+ }
964+
965+ if bucketClassName == "" {
946966 return bucketClass , false
947967 }
948968
949- bucketClass .SetName (bucketclassName )
969+ bucketClass .SetName (bucketClassName )
950970
951971 // Find the bucketclass in the same namespace as the OBC
952- bucketClass .SetNamespace (obc .Namespace )
953- if checkExists (bucketClass ) {
954- return bucketClass , true
972+ if obcNamespace != "" {
973+ bucketClass .SetNamespace (obcNamespace )
974+ if checkExists (bucketClass ) {
975+ return bucketClass , true
976+ }
955977 }
956978
957979 // Find the bucketclass in the provisioner namespace
0 commit comments