@@ -92,6 +92,8 @@ type LlamaStackDistributionReconciler struct {
9292 Scheme * runtime.Scheme
9393 // Feature flags
9494 EnableNetworkPolicy bool
95+ // Image mapping overrides
96+ ImageMappingOverrides map [string ]string
9597 // Cluster info
9698 ClusterInfo * cluster.ClusterInfo
9799 httpClient * http.Client
@@ -597,21 +599,40 @@ func (r *LlamaStackDistributionReconciler) configMapUpdatePredicate(e event.Upda
597599 return false
598600 }
599601
600- // Parse the feature flags if the operator config ConfigMap has changed
602+ // Check if this is the operator config ConfigMap
603+ if r .handleOperatorConfigUpdate (newConfigMap ) {
604+ return true
605+ }
606+
607+ // Handle referenced ConfigMap updates
608+ return r .handleReferencedConfigMapUpdate (oldConfigMap , newConfigMap )
609+ }
610+
611+ // handleOperatorConfigUpdate processes updates to the operator config ConfigMap.
612+ func (r * LlamaStackDistributionReconciler ) handleOperatorConfigUpdate (configMap * corev1.ConfigMap ) bool {
601613 operatorNamespace , err := deploy .GetOperatorNamespace ()
602614 if err != nil {
603615 return false
604616 }
605- if newConfigMap .Name == operatorConfigData && newConfigMap .Namespace == operatorNamespace {
606- EnableNetworkPolicy , err := parseFeatureFlags (newConfigMap .Data )
607- if err != nil {
608- log .FromContext (context .Background ()).Error (err , "Failed to parse feature flags" )
609- } else {
610- r .EnableNetworkPolicy = EnableNetworkPolicy
611- }
612- return true
617+
618+ if configMap .Name != operatorConfigData || configMap .Namespace != operatorNamespace {
619+ return false
620+ }
621+
622+ // Update feature flags
623+ EnableNetworkPolicy , err := parseFeatureFlags (configMap .Data )
624+ if err != nil {
625+ log .FromContext (context .Background ()).Error (err , "Failed to parse feature flags" )
626+ } else {
627+ r .EnableNetworkPolicy = EnableNetworkPolicy
613628 }
614629
630+ r .ImageMappingOverrides = ParseImageMappingOverrides (configMap .Data )
631+ return true
632+ }
633+
634+ // handleReferencedConfigMapUpdate processes updates to referenced ConfigMaps.
635+ func (r * LlamaStackDistributionReconciler ) handleReferencedConfigMapUpdate (oldConfigMap , newConfigMap * corev1.ConfigMap ) bool {
615636 // Only proceed if this ConfigMap is referenced by any LlamaStackDistribution
616637 if ! r .isConfigMapReferenced (newConfigMap ) {
617638 return false
@@ -783,7 +804,7 @@ func (r *LlamaStackDistributionReconciler) findLlamaStackDistributionsForConfigM
783804
784805 operatorNamespace , err := deploy .GetOperatorNamespace ()
785806 if err != nil {
786- log . FromContext ( context . Background ()) .Error (err , "Failed to get operator namespace for config map event processing" )
807+ logger .Error (err , "Failed to get operator namespace for config map event processing" )
787808 return nil
788809 }
789810 // If the operator config was changed, we reconcile all LlamaStackDistributions
@@ -1672,53 +1693,92 @@ func NewLlamaStackDistributionReconciler(ctx context.Context, client client.Clie
16721693 return nil , fmt .Errorf ("failed to get operator namespace: %w" , err )
16731694 }
16741695
1675- // Get the ConfigMap
1676- // If the ConfigMap doesn't exist, create it with default feature flags
1677- // If the ConfigMap exists, parse the feature flags from the Configmap
1696+ // Initialize operator config ConfigMap
1697+ configMap , err := initializeOperatorConfigMap (ctx , client , operatorNamespace )
1698+ if err != nil {
1699+ return nil , err
1700+ }
1701+
1702+ // Parse feature flags from ConfigMap
1703+ enableNetworkPolicy , err := parseFeatureFlags (configMap .Data )
1704+ if err != nil {
1705+ return nil , fmt .Errorf ("failed to parse feature flags: %w" , err )
1706+ }
1707+
1708+ // Parse image mapping overrides from ConfigMap
1709+ imageMappingOverrides := ParseImageMappingOverrides (configMap .Data )
1710+
1711+ return & LlamaStackDistributionReconciler {
1712+ Client : client ,
1713+ Scheme : scheme ,
1714+ EnableNetworkPolicy : enableNetworkPolicy ,
1715+ ImageMappingOverrides : imageMappingOverrides ,
1716+ ClusterInfo : clusterInfo ,
1717+ httpClient : & http.Client {Timeout : 5 * time .Second },
1718+ }, nil
1719+ }
1720+
1721+ // initializeOperatorConfigMap gets or creates the operator config ConfigMap.
1722+ func initializeOperatorConfigMap (ctx context.Context , c client.Client , operatorNamespace string ) (* corev1.ConfigMap , error ) {
16781723 configMap := & corev1.ConfigMap {}
16791724 configMapName := types.NamespacedName {
16801725 Name : operatorConfigData ,
16811726 Namespace : operatorNamespace ,
16821727 }
16831728
1684- if err = client .Get (ctx , configMapName , configMap ); err != nil {
1685- if ! k8serrors . IsNotFound ( err ) {
1686- return nil , fmt . Errorf ( "failed to get ConfigMap: %w" , err )
1687- }
1729+ err := c .Get (ctx , configMapName , configMap )
1730+ if err == nil {
1731+ return configMap , nil
1732+ }
16881733
1689- // ConfigMap doesn't exist, create it with defaults
1690- configMap , err = createDefaultConfigMap (configMapName )
1691- if err != nil {
1692- return nil , fmt .Errorf ("failed to generate default configMap: %w" , err )
1734+ if ! k8serrors .IsNotFound (err ) {
1735+ return nil , fmt .Errorf ("failed to get ConfigMap: %w" , err )
1736+ }
1737+
1738+ // ConfigMap doesn't exist, create it with defaults
1739+ configMap , err = createDefaultConfigMap (configMapName )
1740+ if err != nil {
1741+ return nil , fmt .Errorf ("failed to generate default configMap: %w" , err )
1742+ }
1743+
1744+ if err = c .Create (ctx , configMap ); err != nil {
1745+ return nil , fmt .Errorf ("failed to create ConfigMap: %w" , err )
1746+ }
1747+
1748+ return configMap , nil
1749+ }
1750+
1751+ func ParseImageMappingOverrides (configMapData map [string ]string ) map [string ]string {
1752+ imageMappingOverrides := make (map [string ]string )
1753+
1754+ // Look for the image-overrides key in the ConfigMap data
1755+ if overridesYAML , exists := configMapData ["image-overrides" ]; exists {
1756+ // Parse the YAML content
1757+ var overrides map [string ]string
1758+ if err := yaml .Unmarshal ([]byte (overridesYAML ), & overrides ); err != nil {
1759+ // Log error but continue with empty overrides
1760+ fmt .Printf ("failed to parse image-overrides YAML: %v\n " , err )
1761+ return imageMappingOverrides
16931762 }
16941763
1695- if err = client .Create (ctx , configMap ); err != nil {
1696- return nil , fmt .Errorf ("failed to create ConfigMap: %w" , err )
1764+ // Copy the parsed overrides to our result map
1765+ for version , image := range overrides {
1766+ imageMappingOverrides [version ] = image
16971767 }
16981768 }
16991769
1700- // Parse feature flags from ConfigMap
1701- enableNetworkPolicy , err := parseFeatureFlags (configMap .Data )
1702- if err != nil {
1703- return nil , fmt .Errorf ("failed to parse feature flags: %w" , err )
1704- }
1705- return & LlamaStackDistributionReconciler {
1706- Client : client ,
1707- Scheme : scheme ,
1708- EnableNetworkPolicy : enableNetworkPolicy ,
1709- ClusterInfo : clusterInfo ,
1710- httpClient : & http.Client {Timeout : 5 * time .Second },
1711- }, nil
1770+ return imageMappingOverrides
17121771}
17131772
17141773// NewTestReconciler creates a reconciler for testing, allowing injection of a custom http client and feature flags.
17151774func NewTestReconciler (client client.Client , scheme * runtime.Scheme , clusterInfo * cluster.ClusterInfo ,
17161775 httpClient * http.Client , enableNetworkPolicy bool ) * LlamaStackDistributionReconciler {
17171776 return & LlamaStackDistributionReconciler {
1718- Client : client ,
1719- Scheme : scheme ,
1720- ClusterInfo : clusterInfo ,
1721- httpClient : httpClient ,
1722- EnableNetworkPolicy : enableNetworkPolicy ,
1777+ Client : client ,
1778+ Scheme : scheme ,
1779+ ClusterInfo : clusterInfo ,
1780+ httpClient : httpClient ,
1781+ EnableNetworkPolicy : enableNetworkPolicy ,
1782+ ImageMappingOverrides : make (map [string ]string ),
17231783 }
17241784}
0 commit comments