66 "os"
77 "reflect"
88
9+ argocommon "github.com/argoproj-labs/argocd-operator/common"
10+ argocdutil "github.com/argoproj-labs/argocd-operator/controllers/argoutil"
911 consolev1 "github.com/openshift/api/console/v1"
1012 pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
1113 "github.com/redhat-developer/gitops-operator/controllers/util"
@@ -241,16 +243,30 @@ func pluginConfigMap() *corev1.ConfigMap {
241243 }
242244}
243245
244- func (r * ReconcileGitopsService ) reconcileDeployment (instance * pipelinesv1alpha1.GitopsService , request reconcile.Request ) (reconcile.Result , error ) {
246+ func (r * ReconcileGitopsService ) reconcileDeployment (cr * pipelinesv1alpha1.GitopsService , request reconcile.Request ) (reconcile.Result , error ) {
245247 reqLogger := logs .WithValues ("Request.Namespace" , request .Namespace , "Request.Name" , request .Name )
246248 newPluginDeployment := pluginDeployment ()
247249
248- if err := controllerutil .SetControllerReference (instance , newPluginDeployment , r .Scheme ); err != nil {
250+ if err := controllerutil .SetControllerReference (cr , newPluginDeployment , r .Scheme ); err != nil {
249251 return reconcile.Result {}, err
250252 }
251253
254+ newPluginDeployment .Spec .Template .Spec .NodeSelector = argocommon .DefaultNodeSelector ()
255+
256+ if cr .Spec .RunOnInfra {
257+ newPluginDeployment .Spec .Template .Spec .NodeSelector [common .InfraNodeLabelSelector ] = ""
258+ }
259+ if len (cr .Spec .NodeSelector ) > 0 {
260+ newPluginDeployment .Spec .Template .Spec .NodeSelector = argocdutil .AppendStringMap (newPluginDeployment .Spec .Template .Spec .NodeSelector , cr .Spec .NodeSelector )
261+ }
262+
263+ if len (cr .Spec .Tolerations ) > 0 {
264+ newPluginDeployment .Spec .Template .Spec .Tolerations = cr .Spec .Tolerations
265+ }
266+
252267 // Check if this Deployment already exists
253268 existingPluginDeployment := & appsv1.Deployment {}
269+
254270 err := r .Client .Get (context .TODO (), types.NamespacedName {Name : newPluginDeployment .Name , Namespace : newPluginDeployment .Namespace }, existingPluginDeployment )
255271 if err != nil {
256272 if errors .IsNotFound (err ) {
@@ -272,7 +288,9 @@ func (r *ReconcileGitopsService) reconcileDeployment(instance *pipelinesv1alpha1
272288 ! reflect .DeepEqual (existingSpecTemplate .Spec .Containers , newSpecTemplate .Spec .Containers ) ||
273289 ! reflect .DeepEqual (existingSpecTemplate .Spec .Volumes , newSpecTemplate .Spec .Volumes ) ||
274290 ! reflect .DeepEqual (existingSpecTemplate .Spec .RestartPolicy , newSpecTemplate .Spec .RestartPolicy ) ||
275- ! reflect .DeepEqual (existingSpecTemplate .Spec .DNSPolicy , newSpecTemplate .Spec .DNSPolicy )
291+ ! reflect .DeepEqual (existingSpecTemplate .Spec .DNSPolicy , newSpecTemplate .Spec .DNSPolicy ) ||
292+ ! reflect .DeepEqual (existingPluginDeployment .Spec .Template .Spec .NodeSelector , newPluginDeployment .Spec .Template .Spec .NodeSelector ) ||
293+ ! reflect .DeepEqual (existingPluginDeployment .Spec .Template .Spec .Tolerations , newPluginDeployment .Spec .Template .Spec .Tolerations )
276294
277295 if changed {
278296 reqLogger .Info ("Reconciling plugin deployment" , "Namespace" , existingPluginDeployment .Namespace , "Name" , existingPluginDeployment .Name )
@@ -284,6 +302,8 @@ func (r *ReconcileGitopsService) reconcileDeployment(instance *pipelinesv1alpha1
284302 existingSpecTemplate .Spec .Volumes = newSpecTemplate .Spec .Volumes
285303 existingSpecTemplate .Spec .RestartPolicy = newSpecTemplate .Spec .RestartPolicy
286304 existingSpecTemplate .Spec .DNSPolicy = newSpecTemplate .Spec .DNSPolicy
305+ existingPluginDeployment .Spec .Template .Spec .NodeSelector = newPluginDeployment .Spec .Template .Spec .NodeSelector
306+ existingPluginDeployment .Spec .Template .Spec .Tolerations = newPluginDeployment .Spec .Template .Spec .Tolerations
287307 return reconcile.Result {}, r .Client .Update (context .TODO (), newPluginDeployment )
288308 }
289309 }
0 commit comments