Skip to content
Open
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
21 changes: 14 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ func main() {
registerComponentOrExit(mgr, argov1beta1api.AddToScheme)

// Setup Scheme for OpenShift Config if available
// Disables default Argo CD instance if the cluster doesn't contain OpenShift config API

if util.IsConfigAPIFound() {
registerComponentOrExit(mgr, configv1.AddToScheme)
}
Expand Down Expand Up @@ -254,13 +256,18 @@ func main() {
}
}

if err = (&controllers.ReconcileGitopsService{
Client: client,
Scheme: mgr.GetScheme(),
DisableDefaultInstall: strings.ToLower(os.Getenv(common.DisableDefaultInstallEnvVar)) == "true",
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GitopsService")
os.Exit(1)
if util.IsOpenShiftCluster() {
if err = (&controllers.ReconcileGitopsService{
Client: client,
Scheme: mgr.GetScheme(),
DisableDefaultInstall: strings.ToLower(os.Getenv(common.DisableDefaultInstallEnvVar)) == "true",
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "GitopsService")
os.Exit(1)
}
} else {
setupLog.Info("skipping GitopsService controller setup", "reason", "OpenShift Config API not available")

}

if util.IsRouteAPIFound() {
Expand Down
11 changes: 10 additions & 1 deletion controllers/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ import (

argoapp "github.com/argoproj-labs/argocd-operator/api/v1beta1"
argoappController "github.com/argoproj-labs/argocd-operator/controllers/argocd"
"github.com/redhat-developer/gitops-operator/controllers/util"
v1 "k8s.io/api/core/v1"
resourcev1 "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/yaml"
)

var log = logf.Log.WithName("controller_argocd")

var (
defaultAdminPolicy = "g, system:cluster-admins, role:admin\ng, cluster-admins, role:admin\n"
defaultScope = "[groups]"
Expand Down Expand Up @@ -90,7 +94,12 @@ func getArgoDexSpec() *argoapp.ArgoCDDexSpec {
}

func getArgoSSOSpec(client client.Client) *argoapp.ArgoCDSSOSpec {
if argoappController.IsOpenShiftCluster() && argoappController.IsExternalAuthenticationEnabledOnCluster(context.TODO(), client) {
if !util.IsOpenShiftCluster() {
log.Info("non-OpenShift cluster detected, skipping SSO/Dex configuration")
return nil
}
if argoappController.IsExternalAuthenticationEnabledOnCluster(context.TODO(), client) {
log.Info("external authentication enabled on cluster, skipping SSO/Dex configuration")
return nil
}
return &argoapp.ArgoCDSSOSpec{
Expand Down
24 changes: 24 additions & 0 deletions controllers/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

argoapp "github.com/argoproj-labs/argocd-operator/api/v1beta1"
configv1 "github.com/openshift/api/config/v1"
"github.com/redhat-developer/gitops-operator/controllers/util"
"gotest.tools/assert"
v1 "k8s.io/api/core/v1"
resourcev1 "k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -30,6 +31,9 @@ import (
)

func TestArgoCD(t *testing.T) {
util.SetConfigAPIFound(true)
defer util.SetConfigAPIFound(false)

scheme := runtime.NewScheme()
_ = argoapp.AddToScheme(scheme)
_ = configv1.AddToScheme(scheme)
Expand Down Expand Up @@ -199,6 +203,9 @@ func TestArgoCD(t *testing.T) {
}

func TestDexConfiguration(t *testing.T) {
util.SetConfigAPIFound(true)
defer util.SetConfigAPIFound(false)

scheme := runtime.NewScheme()
_ = argoapp.AddToScheme(scheme)
_ = configv1.AddToScheme(scheme)
Expand All @@ -223,3 +230,20 @@ func TestDexConfiguration(t *testing.T) {
}
assert.DeepEqual(t, testArgoCD.Spec.RBAC, testRBAC)
}

// kubernetes environment test, no defer required as the Config API is false by default
func TestSSOSkippedOnNonOpenShift(t *testing.T) {
util.SetConfigAPIFound(false)

scheme := runtime.NewScheme()
_ = argoapp.AddToScheme(scheme)
_ = configv1.AddToScheme(scheme)

fakeClient := fake.NewClientBuilder().
WithScheme(scheme).
Build()

testArgoCD, _ := NewCR("openshift-gitops", "openshift-gitops", fakeClient)

assert.Assert(t, testArgoCD.Spec.SSO == nil, "SSO should be nil on non-OpenShift clusters")
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
7 changes: 6 additions & 1 deletion controllers/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ func InspectCluster() error {
return stderrors.Join(errs...)
}

// used as a shortcut to check if the cluster is an OpenShift cluster
// used as a shortcut to check if the Config.Openshift.io API is found
func IsConfigAPIFound() bool {
return configAPIFound
}

// used as a shortcut to check if the cluster is an OpenShift cluster
func IsOpenShiftCluster() bool {
return IsConfigAPIFound()
}

// verify if the Config.Openshift.io API is found
func verifyConfigAPI() error {
found, err := argoutil.VerifyAPI(configv1.GroupName, configv1.GroupVersion.Version)
Expand Down
Loading