Skip to content

Commit 786df27

Browse files
authored
feat: implement ability to disable default argocd consoleLink (#333)
* feat: implement ability to disable default argocd consolelink * add documentation about all environmental variables
1 parent 8a95530 commit 786df27

File tree

4 files changed

+162
-28
lines changed

4 files changed

+162
-28
lines changed

common/common.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ const (
2121
ArgoCDInstanceName = "openshift-gitops"
2222
// DisableDefaultInstallEnvVar is an env variable to disable the default instance
2323
DisableDefaultInstallEnvVar = "DISABLE_DEFAULT_ARGOCD_INSTANCE"
24+
// DisableDefaultArgoCDConsoleLink is an env variable to disable the default Argo CD ConsoleLink
25+
DisableDefaultArgoCDConsoleLink = "DISABLE_DEFAULT_ARGOCD_CONSOLELINK"
2426
)
2527

2628
// InfraNodeSelector returns openshift label for infrastructure nodes

controllers/argocd_controller.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ import (
2020
"context"
2121
"encoding/base64"
2222
"fmt"
23+
"os"
24+
"strings"
2325

2426
// embed the Argo icon during compile time
2527
_ "embed"
2628

2729
"github.com/go-logr/logr"
2830
console "github.com/openshift/api/console/v1"
2931
routev1 "github.com/openshift/api/route/v1"
32+
"github.com/redhat-developer/gitops-operator/common"
3033
"k8s.io/apimachinery/pkg/api/errors"
3134
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3235
"k8s.io/apimachinery/pkg/runtime"
@@ -59,10 +62,16 @@ func init() {
5962
encodedArgoImage = imageDataURL(base64.StdEncoding.EncodeToString(argoImage))
6063
}
6164

65+
// if DISABLE_DEFAULT_ARGOCD_CONSOLELINK env variable is true, Argo CD ConsoleLink will be deleted
66+
func isConsoleLinkDisabled() bool {
67+
return strings.ToLower(os.Getenv(common.DisableDefaultArgoCDConsoleLink)) == "true"
68+
}
69+
6270
// SetupWithManager sets up the controller with the Manager.
6371
func (r *ReconcileArgoCDRoute) SetupWithManager(mgr ctrl.Manager) error {
6472
// Watch for changes to argocd-server route in the default argocd instance namespace
6573
// The ConsoleLink holds the route URL and should be regenerated when route is updated
74+
6675
return ctrl.NewControllerManagedBy(mgr).
6776
For(&routev1.Route{}, builder.WithPredicates(filterPredicate(filterArgoCDRoute))).
6877
Complete(r)
@@ -119,26 +128,31 @@ func (r *ReconcileArgoCDRoute) Reconcile(ctx context.Context, request reconcile.
119128
}
120129
return reconcile.Result{}, err
121130
}
131+
122132
reqLogger.Info("Route found for argocd-server", "Route.Host", argoCDRoute.Spec.Host)
123133

124-
argocCDRouteURL := fmt.Sprintf("https://%s", argoCDRoute.Spec.Host)
134+
argoCDRouteURL := fmt.Sprintf("https://%s", argoCDRoute.Spec.Host)
125135

126-
consoleLink := newConsoleLink(argocCDRouteURL, "Cluster Argo CD")
136+
consoleLink := newConsoleLink(argoCDRouteURL, "Cluster Argo CD")
127137

128138
found := &console.ConsoleLink{}
129139
err = r.Client.Get(ctx, types.NamespacedName{Name: consoleLink.Name}, found)
140+
130141
if err != nil {
131142
if errors.IsNotFound(err) {
132-
reqLogger.Info("Creating a new ConsoleLink", "ConsoleLink.Name", consoleLink.Name)
133-
return reconcile.Result{}, r.Client.Create(ctx, consoleLink)
143+
if !isConsoleLinkDisabled() {
144+
reqLogger.Info("Creating a new ConsoleLink", "ConsoleLink.Name", consoleLink.Name)
145+
return reconcile.Result{}, r.Client.Create(ctx, consoleLink)
146+
}
134147
}
135-
reqLogger.Error(err, "Failed to create ConsoleLink", "ConsoleLink.Name", consoleLink.Name)
148+
reqLogger.Error(err, "ConsoleLink not found", "ConsoleLink.Name", consoleLink.Name)
136149
return reconcile.Result{}, err
137150
}
138-
139-
if found.Spec.Href != argocCDRouteURL {
151+
if isConsoleLinkDisabled() {
152+
return reconcile.Result{}, r.deleteConsoleLinkIfPresent(ctx, reqLogger)
153+
} else if found.Spec.Href != argoCDRouteURL {
140154
reqLogger.Info("Updating the existing ConsoleLink", "ConsoleLink.Name", consoleLink.Name)
141-
found.Spec.Href = argocCDRouteURL
155+
found.Spec.Href = argoCDRouteURL
142156
return reconcile.Result{}, r.Client.Update(ctx, found)
143157
}
144158

controllers/argocd_controller_test.go

+77-6
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,28 @@ package controllers
1919
import (
2020
"context"
2121
"net/url"
22+
"os"
2223
"testing"
2324

25+
"github.com/argoproj-labs/argocd-operator/controllers/argocd"
2426
"github.com/google/go-cmp/cmp"
2527
configv1 "github.com/openshift/api/config/v1"
2628
console "github.com/openshift/api/console/v1"
2729
routev1 "github.com/openshift/api/route/v1"
30+
"gotest.tools/assert"
2831
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2932
"k8s.io/apimachinery/pkg/runtime"
3033
"k8s.io/apimachinery/pkg/types"
3134
"k8s.io/client-go/kubernetes/scheme"
3235
"sigs.k8s.io/controller-runtime/pkg/client"
3336
"sigs.k8s.io/controller-runtime/pkg/client/fake"
37+
logf "sigs.k8s.io/controller-runtime/pkg/log"
3438
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3539
)
3640

3741
const (
38-
argocdInstanceName = "openshift-gitops"
42+
argocdInstanceName = "openshift-gitops"
43+
disableArgoCDConsoleLink = "DISABLE_DEFAULT_ARGOCD_CONSOLELINK"
3944
)
4045

4146
var (
@@ -66,13 +71,79 @@ func TestReconcile_create_consolelink(t *testing.T) {
6671
}
6772

6873
func TestReconcile_delete_consolelink(t *testing.T) {
69-
reconcileArgoCD, fakeClient := newFakeReconcileArgoCD(argoCDRoute, consoleLink)
74+
logf.SetLogger(argocd.ZapLogger(true))
7075

71-
err := fakeClient.Delete(context.TODO(), &routev1.Route{ObjectMeta: v1.ObjectMeta{Name: argocdRouteName, Namespace: argocdNS}})
72-
assertNoError(t, err)
76+
restoreEnvFunc := func() {
77+
os.Unsetenv(disableArgoCDConsoleLink)
78+
}
79+
80+
tests := []struct {
81+
name string
82+
setEnvVarFunc func(string)
83+
envVar string
84+
consoleLinkShouldExist bool
85+
wantErr bool
86+
Err error
87+
}{
88+
{
89+
name: "DISABLE_DEFAULT_ARGOCD_CONSOLELINK is set to true and consoleLink gets deleted",
90+
setEnvVarFunc: func(envVar string) {
91+
os.Setenv(disableArgoCDConsoleLink, envVar)
92+
},
93+
consoleLinkShouldExist: false,
94+
envVar: "true",
95+
wantErr: false,
96+
},
97+
{
98+
name: "DISABLE_DEFAULT_ARGOCD_CONSOLELINK is set to false and consoleLink doesn't get deleted",
99+
setEnvVarFunc: func(envVar string) {
100+
os.Setenv(disableArgoCDConsoleLink, envVar)
101+
},
102+
envVar: "false",
103+
consoleLinkShouldExist: true,
104+
wantErr: false,
105+
},
106+
{
107+
name: "DISABLE_DEFAULT_ARGOCD_CONSOLELINK isn't set and consoleLink doesn't get deleted",
108+
setEnvVarFunc: nil,
109+
envVar: "",
110+
consoleLinkShouldExist: true,
111+
wantErr: false,
112+
},
113+
}
114+
115+
for _, test := range tests {
116+
t.Run(test.name, func(t *testing.T) {
117+
defer restoreEnvFunc()
118+
119+
reconcileArgoCD, fakeClient := newFakeReconcileArgoCD(argoCDRoute, consoleLink)
120+
consoleLink := newConsoleLink("https://test.com", "Cluster Argo CD")
121+
fakeClient.Create(context.TODO(), consoleLink)
122+
123+
if test.setEnvVarFunc != nil {
124+
test.setEnvVarFunc(test.envVar)
125+
}
126+
127+
result, err := reconcileArgoCD.Reconcile(context.TODO(), newRequest(argocdNS, argocdInstanceName))
128+
if !test.consoleLinkShouldExist {
129+
assertConsoleLinkDeletion(t, fakeClient, reconcileResult{result, err})
130+
} else {
131+
assertConsoleLinkExists(t, fakeClient, reconcileResult{result, err}, consoleLink)
132+
}
133+
if err != nil {
134+
if !test.wantErr {
135+
t.Errorf("Got unexpected error")
136+
} else {
137+
assert.Equal(t, test.Err, err)
138+
}
139+
} else {
140+
if test.wantErr {
141+
t.Errorf("expected error but didn't get one")
142+
}
143+
}
144+
})
145+
}
73146

74-
result, err := reconcileArgoCD.Reconcile(context.TODO(), newRequest(argocdNS, argocdRouteName))
75-
assertConsoleLinkDeletion(t, fakeClient, reconcileResult{result, err})
76147
}
77148

78149
func TestReconcile_update_consolelink(t *testing.T) {

docs/OpenShift GitOps Usage Guide.md

+61-14
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
## Table of Contents
44
1. [Installing OpenShift GitOps](#installing-openshift-gitops)
55
2. [Configure RHSSO for OpenShift GitOps(>= v1.2)](#configure-rhsso-for-openshift-gitops-v12)
6-
3. [Setting up OpenShift Login (=< v1.1.2)](#setting-up-openshift-login--v112)
7-
4. [Configuring the groups claim](#configuring-the-groups-claim-)
8-
5. [Getting started with GitOps Application Manager (kam)](#getting-started-with-gitops-application-manager-kam)
9-
6. [Setting up a new ArgoCD instance](#setting-up-a-new-argo-cd-instance)
10-
7. [Configure resource quota/requests for OpenShift GitOps workloads](#configure-resource-quotarequests-for-openshift-gitops-workloads)
11-
8. [Running default Gitops workloads on Infrastructure Nodes](#running-default-gitops-workloads-on-infrastructure-nodes)
12-
9. [Monitoring](#monitoring)
13-
10. [Logging](#logging)
14-
11. [Prevent auto-reboot during Argo CD sync with machine configs](#prevent-auto-reboot-during-argo-cd-sync-with-machine-configs)
15-
12. [Machine configs and Argo CD: Performance challenges](#machine-configs-and-argo-cd-performance-challenges)
16-
13. [Health status of OpenShift resources](#health-status-of-openshift-resources)
17-
14. [Upgrade GitOps Operator from v1.0.1 to v1.1.0 (GA)](#upgrade-gitops-operator-from-v101-to-v110-ga)
18-
15. [Upgrade GitOps Operator from v1.1.2 to v1.2.0 (GA)](#upgrade-gitops-operator-from-v112-to-v120-ga)
6+
3. [Setting up OpenShift Login (=< v1.1.2)](#setting-up-openshift-login--v112)
7+
4. [Setting environment variables](#setting-environment-variables)
8+
5. [Configuring the groups claim](#configuring-the-groups-claim-)
9+
6. [Getting started with GitOps Application Manager (kam)](#getting-started-with-gitops-application-manager-kam)
10+
7. [Setting up a new ArgoCD instance](#setting-up-a-new-argo-cd-instance)
11+
8. [Configure resource quota/requests for OpenShift GitOps workloads](#configure-resource-quotarequests-for-openshift-gitops-workloads)
12+
9. [Running default Gitops workloads on Infrastructure Nodes](#running-default-gitops-workloads-on-infrastructure-nodes)
13+
10. [Monitoring](#monitoring)
14+
11. [Logging](#logging)
15+
12. [Prevent auto-reboot during Argo CD sync with machine configs](#prevent-auto-reboot-during-argo-cd-sync-with-machine-configs)
16+
13. [Machine configs and Argo CD: Performance challenges](#machine-configs-and-argo-cd-performance-challenges)
17+
14. [Health status of OpenShift resources](#health-status-of-openshift-resources)
18+
15. [Upgrade GitOps Operator from v1.0.1 to v1.1.0 (GA)](#upgrade-gitops-operator-from-v101-to-v110-ga)
19+
16. [Upgrade GitOps Operator from v1.1.2 to v1.2.0 (GA)](#upgrade-gitops-operator-from-v112-to-v120-ga)
1920

2021
## Installing OpenShift GitOps
2122

@@ -99,6 +100,8 @@ You can launch into this Argo CD instance from the Console Application Launcher.
99100

100101
![image alt text](assets/5.console_application_launcher.png)
101102

103+
**Note: To disable the Link to Argo CD in the Console Application Launcher, see the documentation on how to disable consoleLink in the [setting environment variables section](#setting-environment-variables)**
104+
102105
Alternatively, the DNS hostname of the Argo CD Web Console can be retrieved by the command line.
103106

104107
`oc get route openshift-gitops-server -n openshift-gitops -o jsonpath='{.spec.host}'`
@@ -412,6 +415,50 @@ Make sure to click **Save**. You should now have a new tab called **Credentials*
412415

413416
![image alt text](assets/16.credentials_setup.png)
414417

418+
## **Setting environment variables**
419+
420+
Updating the following environment variables in the existing Subscription Object for the GitOps Operator will allow you (as an admin) to change certain properties in your cluster:
421+
422+
<table>
423+
<tr>
424+
<td>Environment variable</td>
425+
<td>Default value</td>
426+
<td>Description</td>
427+
</tr>
428+
<tr>
429+
<td>ARGOCD_CLUSTER_CONFIG_NAMESPACES</td>
430+
<td>none</td>
431+
<td>When provided with a namespace, Argo CD is granted permissions to manage specific cluster-scoped resources which include
432+
platform operators, optional OLM operators, user management, etc. Argo CD is not granted cluster-admin.</td>
433+
</tr>
434+
<tr>
435+
<td>CONTROLLER_CLUSTER_ROLE</td>
436+
<td>none</td>
437+
<td>Administrators can configure a common cluster role for all the managed namespaces in role bindings for the Argo CD application controller with this environment variable. Note: If this environment variable contains custom roles, the Operator doesn't create the default admin role. Instead, it uses the existing custom role for all managed namespaces.</td>
438+
</tr>
439+
<tr>
440+
<td>DISABLE_DEFAULT_ARGOCD_CONSOLELINK</td>
441+
<td>false</td>
442+
<td>When set to `true`, will disable the ConsoleLink for Argo CD, which appears as the link to Argo CD in the Application Launcher. This can be beneficial to users of multi-tenant clusters who have multiple instances of Argo CD.</td>
443+
</tr>
444+
<tr>
445+
<td>DISABLE_DEFAULT_ARGOCD_INSTANCE</td>
446+
<td>false</td>
447+
<td>When set to `true`, will disable the default 'ready-to-use' installation of Argo CD in `openshift-gitops` namespace.</td>
448+
</tr>
449+
<tr>
450+
<td>DISABLE_DEX</td>
451+
<td>false</td>
452+
<td> When set to `true`, will remove the Dex deployment from the openshift-gitops namespace. Note: Disabling Dex will not be supported in v.1.9.0+.
453+
</td>
454+
</tr>
455+
<tr>
456+
<td>SERVER_CLUSTER_ROLE</td>
457+
<td>none</td>
458+
<td>Administrators can configure a common cluster role for all the managed namespaces in role bindings for the Argo CD server with this environment variable. Note: If this environment variable contains custom roles, the Operator doesn’t create the default admin role. Instead, it uses the existing custom role for all managed namespaces.</td>
459+
</tr>
460+
</table>
461+
415462
## **Configuring the groups claim**[](https://argoproj.github.io/argo-cd/operator-manual/user-management/keycloak/#configuring-the-groups-claim)
416463

417464
In order for Argo CD to provide the groups the user is in we need to configure a groups claim that can be included in the authentication token. To do this we'll start by creating a new **Client Scope** called *groups*.
@@ -562,7 +609,7 @@ data:
562609

563610
### Working with Dex
564611

565-
**NOTE:** For a fresh install of v1.3.0, Dex is automatically configured. You can log into the default Argo CD instance in the openshift-gitops namespace using the OpenShift or kubeadmin credentials. As an admin you can disable the Dex installation after the Operator is installed which will remove the Dex deployment from the openshift-gitops namespace.
612+
**NOTE:** As of v1.3.0, Dex is automatically configured. You can log into the default Argo CD instance in the openshift-gitops namespace using the OpenShift or kubeadmin credentials. As an admin you can disable the Dex installation after the Operator is installed which will remove the Dex deployment from the openshift-gitops namespace.
566613

567614
:warning: **DISABLE_DEX is Deprecated in OpenShift GitOps v1.6.0 and support will be removed in v1.9.0. Dex can be enabled/disabled by setting `.spec.sso.provider: dex` as follows:**
568615

0 commit comments

Comments
 (0)