@@ -73,6 +73,9 @@ var getWebhookTracer func() trace.Tracer = sync.OnceValue(func() trace.Tracer {
73
73
const (
74
74
IMAGE_STREAM_NOT_FOUND_EVENT = "imagestream-not-found"
75
75
IMAGE_STREAM_TAG_NOT_FOUND_EVENT = "imagestream-tag-not-found"
76
+
77
+ WorkbenchImageNamespaceAnnotation = "opendatahub.io/workbench-image-namespace"
78
+ LastImageSelectionAnnotation = "notebooks.opendatahub.io/last-image-selection"
76
79
)
77
80
78
81
// InjectReconciliationLock injects the kubeflow notebook controller culling
@@ -716,7 +719,7 @@ func SetContainerImageFromRegistry(ctx context.Context, cli client.Client, noteb
716
719
717
720
annotations := notebook .GetAnnotations ()
718
721
if annotations != nil {
719
- if imageSelection , exists := annotations ["notebooks.opendatahub.io/last-image-selection" ]; exists {
722
+ if imageSelection , exists := annotations [LastImageSelectionAnnotation ]; exists {
720
723
721
724
containerFound := false
722
725
// Iterate over containers to find the one matching the notebook name
@@ -743,35 +746,37 @@ func SetContainerImageFromRegistry(ctx context.Context, cli client.Client, noteb
743
746
imagestreamName := imageSelected [0 ]
744
747
imgSelection := & imagev1.ImageStream {}
745
748
746
- // Search for the ImageStream in the controller namespace first
747
- // As default, the ImageStream is created in the controller namespace
748
- // if not found, search in the notebook namespace
749
- // Note: This is in this order, so users should not overwrite the ImageStream
750
- err := cli .Get (ctx , types.NamespacedName {Name : imagestreamName , Namespace : controllerNamespace }, imgSelection )
749
+ // in user-created Notebook CRs, the annotation may be missing
750
+ // Dashboard creates it with an empty value (null in TypeScript) when the controllerNamespace is intended
751
+ // https://github.com/opendatahub-io/odh-dashboard/blob/2692224c3157f00a6fe93a2ca5bd267e3ff964ca/frontend/src/api/k8s/notebooks.ts#L215-L216
752
+ imageNamespace , nsExists := annotations [WorkbenchImageNamespaceAnnotation ]
753
+ if ! nsExists || strings .TrimSpace (imageNamespace ) == "" {
754
+ log .Info ("Unable to find the namespace annotation in the Notebook CR, or the value of it is an empty string. Will search in controller namespace" ,
755
+ "annotationName" , WorkbenchImageNamespaceAnnotation ,
756
+ "controllerNamespace" , controllerNamespace )
757
+ imageNamespace = controllerNamespace
758
+ }
759
+
760
+ // Search for the ImageStream in the specified namespace
761
+ // As default when no namespace specified, the ImageStream is searched for in the controller namespace
762
+ err := cli .Get (ctx , types.NamespacedName {Name : imagestreamName , Namespace : imageNamespace }, imgSelection )
751
763
if apierrs .IsNotFound (err ) {
752
- log .Info ("Unable to find the ImageStream in controller namespace, try finding in notebook namespace" , "imagestream" , imagestreamName , "controllerNamespace" , controllerNamespace )
753
- // Check if the ImageStream is present in the notebook namespace
754
- err = cli .Get (ctx , types.NamespacedName {Name : imagestreamName , Namespace : notebook .Namespace }, imgSelection )
755
- if err != nil {
756
- log .Error (err , "Error getting ImageStream" , "imagestream" , imagestreamName , "controllerNamespace" , controllerNamespace )
757
- span .AddEvent (IMAGE_STREAM_NOT_FOUND_EVENT )
758
- } else {
759
- // ImageStream found in the notebook namespace
760
- imagestreamFound = true
761
- log .Info ("ImageStream found in notebook namespace" , "imagestream" , imagestreamName , "namespace" , notebook .Namespace )
762
- }
764
+ span .AddEvent (IMAGE_STREAM_NOT_FOUND_EVENT )
765
+ log .Info ("Unable to find the ImageStream in the expected namespace" ,
766
+ "imagestream" , imagestreamName ,
767
+ "imageNamespace" , imageNamespace )
763
768
} else if err != nil {
764
- log .Error (err , "Error getting ImageStream" , "imagestream" , imagestreamName , "controllerNamespace " , controllerNamespace )
769
+ log .Error (err , "Error getting ImageStream" , "imagestream" , imagestreamName , "imageNamespace " , imageNamespace )
765
770
} else {
766
- // ImageStream found in the controller namespace
771
+ // ImageStream found
767
772
imagestreamFound = true
768
- log .Info ("ImageStream found in controller namespace " , "imagestream" , imagestreamName , "controllerNamespace " , controllerNamespace )
773
+ log .Info ("ImageStream found" , "imagestream" , imagestreamName , "namespace " , imageNamespace )
769
774
}
770
775
771
776
if imagestreamFound {
772
777
// Check if the ImageStream has a status and tags
773
778
if imgSelection .Status .Tags == nil {
774
- log .Error (nil , "ImageStream has no status or tags" , "name" , imagestreamName , "namespace" , controllerNamespace )
779
+ log .Error (nil , "ImageStream has no status or tags" , "name" , imagestreamName , "namespace" , imageNamespace )
775
780
span .AddEvent (IMAGE_STREAM_TAG_NOT_FOUND_EVENT )
776
781
return fmt .Errorf ("ImageStream has no status or tags" )
777
782
}
0 commit comments