Skip to content

Commit 8940cc2

Browse files
committed
Fix operator config ConfigMap watching
o Add operator config detection in configMapUpdatePredicate o Update feature flags when operator config changes o Trigger reconciliation of all LlamaStackDistributions on operator config change Signed-off-by: Derek Higgins <derekh@redhat.com>
1 parent 260731c commit 8940cc2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

controllers/llamastackdistribution_controller.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ const (
8383
// When a ConfigMap's data changes, it automatically triggers reconciliation of the referencing
8484
// LlamaStackDistribution, which recalculates a content-based hash and updates the deployment's
8585
// pod template annotations. This causes Kubernetes to restart the pods with the updated configuration.
86+
//
87+
// Operator ConfigMap Watching Feature:
88+
// This reconciler also watches for changes to the operator configuration ConfigMap. When the operator
89+
// config changes, it triggers reconciliation of all LlamaStackDistribution resources.
8690
type LlamaStackDistributionReconciler struct {
8791
client.Client
8892
Scheme *runtime.Scheme
@@ -593,6 +597,21 @@ func (r *LlamaStackDistributionReconciler) configMapUpdatePredicate(e event.Upda
593597
return false
594598
}
595599

600+
// Parse the feature flags if the operator config ConfigMap has changed
601+
operatorNamespace, err := deploy.GetOperatorNamespace()
602+
if err != nil {
603+
return false
604+
}
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
613+
}
614+
596615
// Only proceed if this ConfigMap is referenced by any LlamaStackDistribution
597616
if !r.isConfigMapReferenced(newConfigMap) {
598617
return false
@@ -758,6 +777,27 @@ func (r *LlamaStackDistributionReconciler) manuallyCheckConfigMapReference(confi
758777

759778
// findLlamaStackDistributionsForConfigMap maps ConfigMap changes to LlamaStackDistribution reconcile requests.
760779
func (r *LlamaStackDistributionReconciler) findLlamaStackDistributionsForConfigMap(ctx context.Context, configMap client.Object) []reconcile.Request {
780+
logger := log.FromContext(ctx).WithValues(
781+
"configMapName", configMap.GetName(),
782+
"configMapNamespace", configMap.GetNamespace())
783+
784+
operatorNamespace, err := deploy.GetOperatorNamespace()
785+
if err != nil {
786+
log.FromContext(context.Background()).Error(err, "Failed to get operator namespace for config map event processing")
787+
return nil
788+
}
789+
// If the operator config was changed, we reconcile all LlamaStackDistributions
790+
if configMap.GetName() == operatorConfigData && configMap.GetNamespace() == operatorNamespace {
791+
// List all LlamaStackDistribution resources across all namespaces
792+
allLlamaStacks := llamav1alpha1.LlamaStackDistributionList{}
793+
err = r.List(ctx, &allLlamaStacks)
794+
if err != nil {
795+
logger.Error(err, "Failed to list all LlamaStackDistributions for operator config change")
796+
return nil
797+
}
798+
return r.convertToReconcileRequests(allLlamaStacks)
799+
}
800+
761801
// Try field indexer lookup first
762802
attachedLlamaStacks, found := r.tryFieldIndexerLookup(ctx, configMap)
763803
if !found {

0 commit comments

Comments
 (0)