@@ -19,6 +19,7 @@ package controllers
1919import (
2020 "context"
2121 "fmt"
22+ "log"
2223 "os"
2324 "reflect"
2425 "strings"
@@ -28,6 +29,7 @@ import (
2829 argocdcontroller "github.com/argoproj-labs/argocd-operator/controllers/argocd"
2930 argocdutil "github.com/argoproj-labs/argocd-operator/controllers/argoutil"
3031 "github.com/go-logr/logr"
32+ version "github.com/hashicorp/go-version"
3133 routev1 "github.com/openshift/api/route/v1"
3234 pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
3335 "github.com/redhat-developer/gitops-operator/common"
@@ -57,15 +59,16 @@ var logs = logf.Log.WithName("controller_gitopsservice")
5759
5860// defaults must some somewhere else..
5961var (
60- port int32 = 8080
61- portTLS int32 = 8443
62- backendImage string = "quay.io/redhat-developer/gitops-backend:v0.0.1"
63- backendImageEnvName = "BACKEND_IMAGE"
64- serviceName = "cluster"
65- insecureEnvVar = "INSECURE"
66- insecureEnvVarValue = "true"
67- serviceNamespace = "openshift-gitops"
68- deprecatedServiceNamespace = "openshift-pipelines-app-delivery"
62+ port int32 = 8080
63+ portTLS int32 = 8443
64+ backendImage string = "quay.io/redhat-developer/gitops-backend:v0.0.1"
65+ backendImageEnvName = "BACKEND_IMAGE"
66+ serviceName = "cluster"
67+ insecureEnvVar = "INSECURE"
68+ insecureEnvVarValue = "true"
69+ serviceNamespace = "openshift-gitops"
70+ deprecatedServiceNamespace = "openshift-pipelines-app-delivery"
71+ dynamicPluginStartOCPVersionEnv = "DYNAMIC_PLUGIN_START_OCP_VERSION"
6972)
7073
7174const (
@@ -224,7 +227,40 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
224227 return result , err
225228 }
226229
227- return r .reconcilePlugin (instance , request )
230+ dynamicPluginStartOCPVersion := os .Getenv (dynamicPluginStartOCPVersionEnv )
231+ if dynamicPluginStartOCPVersion == "" {
232+ dynamicPluginStartOCPVersion = common .DefaultDynamicPluginStartOCPVersion
233+ }
234+
235+ OCPVersion , err := util .GetClusterVersion (r .Client )
236+ if err != nil {
237+ log .Printf ("Unable to get cluster version: %v" , err )
238+ return reconcile.Result {}, nil
239+ }
240+
241+ v1 , err := version .NewVersion (OCPVersion )
242+ if err != nil {
243+ log .Printf ("Unable to retrieve current OCP version: %v" , err )
244+ return reconcile.Result {}, nil
245+ }
246+ realVersion := v1 .Segments ()
247+ realMajorVersion := realVersion [0 ]
248+ realMinorVersion := realVersion [1 ]
249+
250+ v2 , err := version .NewVersion (dynamicPluginStartOCPVersion )
251+ if err != nil {
252+ return reconcile.Result {}, nil
253+ }
254+ startVersion := v2 .Segments ()
255+ startMajorVersion := startVersion [0 ]
256+ startMinorVersion := startVersion [1 ]
257+
258+ if realMajorVersion < startMajorVersion || (realMajorVersion == startMajorVersion && realMinorVersion < startMinorVersion ) {
259+ // Skip plugin reconciliation if real OCP version is less than dynamic plugin start OCP version
260+ return reconcile.Result {}, nil
261+ } else {
262+ return r .reconcilePlugin (instance , request )
263+ }
228264}
229265
230266func (r * ReconcileGitopsService ) ensureDefaultArgoCDInstanceDoesntExist (instance * pipelinesv1alpha1.GitopsService , reqLogger logr.Logger ) error {
0 commit comments