Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const (
DefaultConsoleImage = "quay.io/redhat-developer/gitops-console-plugin"
// Default console plugin version
DefaultConsoleVersion = "v0.1.0"
// Default console plugin installation OCP version
DefaultDynamicPluginStartOCPVersion = "4.15.0"
)

// InfraNodeSelector returns openshift label for infrastructure nodes
Expand Down
56 changes: 46 additions & 10 deletions controllers/gitopsservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"log"
"os"
"reflect"
"strings"
Expand All @@ -28,6 +29,7 @@ import (
argocdcontroller "github.com/argoproj-labs/argocd-operator/controllers/argocd"
argocdutil "github.com/argoproj-labs/argocd-operator/controllers/argoutil"
"github.com/go-logr/logr"
version "github.com/hashicorp/go-version"
routev1 "github.com/openshift/api/route/v1"
pipelinesv1alpha1 "github.com/redhat-developer/gitops-operator/api/v1alpha1"
"github.com/redhat-developer/gitops-operator/common"
Expand Down Expand Up @@ -57,15 +59,16 @@ var logs = logf.Log.WithName("controller_gitopsservice")

// defaults must some somewhere else..
var (
port int32 = 8080
portTLS int32 = 8443
backendImage string = "quay.io/redhat-developer/gitops-backend:v0.0.1"
backendImageEnvName = "BACKEND_IMAGE"
serviceName = "cluster"
insecureEnvVar = "INSECURE"
insecureEnvVarValue = "true"
serviceNamespace = "openshift-gitops"
deprecatedServiceNamespace = "openshift-pipelines-app-delivery"
port int32 = 8080
portTLS int32 = 8443
backendImage string = "quay.io/redhat-developer/gitops-backend:v0.0.1"
backendImageEnvName = "BACKEND_IMAGE"
serviceName = "cluster"
insecureEnvVar = "INSECURE"
insecureEnvVarValue = "true"
serviceNamespace = "openshift-gitops"
deprecatedServiceNamespace = "openshift-pipelines-app-delivery"
dynamicPluginStartOCPVersionEnv = "DYNAMIC_PLUGIN_START_OCP_VERSION"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This declaration does not seem to be required.

)

const (
Expand Down Expand Up @@ -224,7 +227,40 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
return result, err
}

return r.reconcilePlugin(instance, request)
dynamicPluginStartOCPVersion := os.Getenv(dynamicPluginStartOCPVersionEnv)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we directly use DYNAMIC_PLUGIN_START_OCP_VERSION here ?

dynamicPluginStartOCPVersion := os.Getenv(DYNAMIC_PLUGIN_START_OCP_VERSION)

if dynamicPluginStartOCPVersion == "" {
dynamicPluginStartOCPVersion = common.DefaultDynamicPluginStartOCPVersion
}

OCPVersion, err := util.GetClusterVersion(r.Client)
if err != nil {
log.Printf("Unable to get cluster version: %v", err)
return reconcile.Result{}, nil
}

v1, err := version.NewVersion(OCPVersion)
if err != nil {
log.Printf("Unable to retrieve current OCP version: %v", err)
return reconcile.Result{}, nil
}
realVersion := v1.Segments()
realMajorVersion := realVersion[0]
realMinorVersion := realVersion[1]

v2, err := version.NewVersion(dynamicPluginStartOCPVersion)
if err != nil {
return reconcile.Result{}, nil
}
startVersion := v2.Segments()
startMajorVersion := startVersion[0]
startMinorVersion := startVersion[1]

if realMajorVersion < startMajorVersion || (realMajorVersion == startMajorVersion && realMinorVersion < startMinorVersion) {
// Skip plugin reconciliation if real OCP version is less than dynamic plugin start OCP version
return reconcile.Result{}, nil
} else {
return r.reconcilePlugin(instance, request)
}
}

func (r *ReconcileGitopsService) ensureDefaultArgoCDInstanceDoesntExist(instance *pipelinesv1alpha1.GitopsService, reqLogger logr.Logger) error {
Expand Down
34 changes: 33 additions & 1 deletion controllers/gitopsservice_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestReconcile(t *testing.T) {
s := scheme.Scheme
addKnownTypesToScheme(s)

fakeClient := fake.NewFakeClient(newGitopsService())
fakeClient := fake.NewFakeClient(util.NewClusterVersion("4.15.1"), newGitopsService())
reconciler := newReconcileGitOpsService(fakeClient, s)

_, err := reconciler.Reconcile(context.TODO(), newRequest("test", "test"))
Expand Down Expand Up @@ -327,6 +327,38 @@ func TestReconcile_consoleAPINotFound(t *testing.T) {
assert.Error(t, err, "configmaps \"httpd-cfg\" not found")
}

func TestReconcile_ocpVersionLowerThan4_15(t *testing.T) {
defer util.SetConsoleAPIFound(util.IsConsoleAPIFound())
util.SetConsoleAPIFound(false)

logf.SetLogger(argocd.ZapLogger(true))
s := scheme.Scheme
addKnownTypesToScheme(s)

fakeClient := fake.NewFakeClient(util.NewClusterVersion("4.11.1"), newGitopsService())
reconciler := newReconcileGitOpsService(fakeClient, s)

_, err := reconciler.Reconcile(context.TODO(), newRequest("test", "test"))
assertNoError(t, err)

// Check consolePlugin and other resources are not created
consolePlugin := &consolepluginv1.ConsolePlugin{}
err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName}, consolePlugin)
assert.Error(t, err, "consoleplugins.console.openshift.io \"gitops-plugin\" not found")

pluginDeploy := &appsv1.Deployment{}
err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, pluginDeploy)
assert.Error(t, err, "deployments.apps \"gitops-plugin\" not found")

pluginService := &corev1.Service{}
err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: gitopsPluginName, Namespace: serviceNamespace}, pluginService)
assert.Error(t, err, "services \"gitops-plugin\" not found")

pluginConfigMap := &corev1.ConfigMap{}
err = fakeClient.Get(context.TODO(), types.NamespacedName{Name: httpdConfigMapName, Namespace: serviceNamespace}, pluginConfigMap)
assert.Error(t, err, "configmaps \"httpd-cfg\" not found")
}

func TestReconcile_GitOpsNamespace(t *testing.T) {
logf.SetLogger(argocd.ZapLogger(true))
s := scheme.Scheme
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/coreos/prometheus-operator v0.40.0
github.com/go-logr/logr v1.2.3
github.com/google/go-cmp v0.5.8
github.com/hashicorp/go-version v1.2.1
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.17.0
github.com/openshift/api v3.9.1-0.20190916204813-cdbe64fb0c91+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,8 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down