Skip to content

Commit

Permalink
Moved CPPCinformer to pod placement controller
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaZivkovic committed Feb 6, 2025
1 parent 7063704 commit d3b7b94
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ import (
"errors"
"flag"
"fmt"
"k8s.io/apimachinery/pkg/fields"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -113,10 +114,25 @@ func main() {
}
if enableClusterPodPlacementConfigOperandControllers {
leaderId = fmt.Sprintf("ppc-controllers-%s", leaderId)

// Set a default field selector, but ensure ClusterPodPlacementConfig overrides it
// We need to watch the pods with the status.phase equal to Pending to be able to update the nodeAffinity.
// We can discard the other pods because they are already scheduled.
cacheOpts.DefaultFieldSelector = fields.OneTermEqualSelector("status.phase", "Pending")

//override DefaultFieldSelector for CRD
cacheOpts.ByObject = map[client.Object]cache.ByObject{
&multiarchv1beta1.ClusterPodPlacementConfig{}: {
// Override to remove any field selector for this resource
Field: fields.Everything(),
},
&multiarchv1alpha1.ClusterPodPlacementConfig{}: {
// Override to remove any field selector for this resource
Field: fields.Everything(),
},
}
}

// Rapid Reset CVEs. For more information see:
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
// - https://github.com/advisories/GHSA-4374-p667-p6c8
Expand Down Expand Up @@ -189,15 +205,6 @@ func RunOperator(mgr ctrl.Manager) {
config := ctrl.GetConfigOrDie()
clientset := kubernetes.NewForConfigOrDie(config)

if enableCPPCInformer {
cppcSyncer := podplacement.NewCPPCSyncer(mgr)
if err := mgr.Add(cppcSyncer); err != nil {
setupLog.Error(err, "unable to add CPPCSyncer")
os.Exit(1)
}
setupLog.Info("CPPCSyncer is enabled")
}

// Get GVK for ClusterPodPlacementConfig
gvk, _ := apiutil.GVKForObject(&multiarchv1beta1.ClusterPodPlacementConfig{}, mgr.GetScheme())

Expand Down Expand Up @@ -230,6 +237,15 @@ func RunClusterPodPlacementConfigOperandControllers(mgr ctrl.Manager) {
}).SetupWithManager(mgr),
unableToCreateController, controllerKey, "PodReconciler")

if enableCPPCInformer {
cppcSyncer := podplacement.NewCPPCSyncer(mgr)
if err := mgr.Add(cppcSyncer); err != nil {
setupLog.Error(err, "unable to add CPPCSyncer")
os.Exit(1)
}
setupLog.Info("CPPCSyncer is enabled")
}

must(mgr.Add(podplacement.NewGlobalPullSecretSyncer(clientset, globalPullSecretNamespace, globalPullSecretName)),
unableToAddRunnable, runnableKey, "GlobalPullSecretSyncer")
}
Expand Down Expand Up @@ -277,7 +293,7 @@ func bindFlags() {
flag.BoolVar(&enableClusterPodPlacementConfigOperandWebHook, "enable-ppc-webhook", false, "Enable the pod placement config operand webhook")
flag.BoolVar(&enableClusterPodPlacementConfigOperandControllers, "enable-ppc-controllers", false, "Enable the pod placement config operand controllers")
flag.BoolVar(&enableOperator, "enable-operator", false, "Enable the operator")
flag.BoolVar(&enableCPPCInformer, "enable-ppc-informer", true, "Enable informer for ClusterPodPlacementConfig")
flag.BoolVar(&enableCPPCInformer, "enable-ppc-informer", false, "Enable informer for ClusterPodPlacementConfig")
// This may be deprecated in the future. It is used to support the current way of setting the log level for operands
// If operands will start to support a controller that watches the ClusterPodPlacementConfig, this flag may be removed
// and the log level will be set in the ClusterPodPlacementConfig at runtime (with no need for reconciliation)
Expand Down

0 comments on commit d3b7b94

Please sign in to comment.