Skip to content

Commit 5680bca

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 b0b5d93 commit 5680bca

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
@@ -79,6 +79,10 @@ const (
7979
// When a ConfigMap's data changes, it automatically triggers reconciliation of the referencing
8080
// LlamaStackDistribution, which recalculates a content-based hash and updates the deployment's
8181
// pod template annotations. This causes Kubernetes to restart the pods with the updated configuration.
82+
//
83+
// Operator ConfigMap Watching Feature:
84+
// This reconciler also watches for changes to the operator configuration ConfigMap. When the operator
85+
// config changes, it triggers reconciliation of all LlamaStackDistribution resources.
8286
type LlamaStackDistributionReconciler struct {
8387
client.Client
8488
Scheme *runtime.Scheme
@@ -532,6 +536,21 @@ func (r *LlamaStackDistributionReconciler) configMapUpdatePredicate(e event.Upda
532536
return false
533537
}
534538

539+
// Parse the feature flags if the operator config ConfigMap has changed
540+
operatorNamespace, err := deploy.GetOperatorNamespace()
541+
if err != nil {
542+
return false
543+
}
544+
if newConfigMap.Name == operatorConfigData && newConfigMap.Namespace == operatorNamespace {
545+
EnableNetworkPolicy, err := parseFeatureFlags(newConfigMap.Data)
546+
if err != nil {
547+
log.FromContext(context.Background()).Error(err, "Failed to parse feature flags")
548+
} else {
549+
r.EnableNetworkPolicy = EnableNetworkPolicy
550+
}
551+
return true
552+
}
553+
535554
// Only proceed if this ConfigMap is referenced by any LlamaStackDistribution
536555
if !r.isConfigMapReferenced(newConfigMap) {
537556
return false
@@ -697,6 +716,27 @@ func (r *LlamaStackDistributionReconciler) manuallyCheckConfigMapReference(confi
697716

698717
// findLlamaStackDistributionsForConfigMap maps ConfigMap changes to LlamaStackDistribution reconcile requests.
699718
func (r *LlamaStackDistributionReconciler) findLlamaStackDistributionsForConfigMap(ctx context.Context, configMap client.Object) []reconcile.Request {
719+
logger := log.FromContext(ctx).WithValues(
720+
"configMapName", configMap.GetName(),
721+
"configMapNamespace", configMap.GetNamespace())
722+
723+
operatorNamespace, err := deploy.GetOperatorNamespace()
724+
if err != nil {
725+
log.FromContext(context.Background()).Error(err, "Failed to get operator namespace for config map event processing")
726+
return nil
727+
}
728+
// If the operator config was changed, we reconcile all LlamaStackDistributions
729+
if configMap.GetName() == operatorConfigData && configMap.GetNamespace() == operatorNamespace {
730+
// List all LlamaStackDistribution resources across all namespaces
731+
allLlamaStacks := llamav1alpha1.LlamaStackDistributionList{}
732+
err = r.List(ctx, &allLlamaStacks)
733+
if err != nil {
734+
logger.Error(err, "Failed to list all LlamaStackDistributions for operator config change")
735+
return nil
736+
}
737+
return r.convertToReconcileRequests(allLlamaStacks)
738+
}
739+
700740
// Try field indexer lookup first
701741
attachedLlamaStacks, found := r.tryFieldIndexerLookup(ctx, configMap)
702742
if !found {

0 commit comments

Comments
 (0)