@@ -17,6 +17,10 @@ import (
1717 "os"
1818 "time"
1919
20+ dwInfra "github.com/devfile/devworkspace-operator/pkg/infrastructure"
21+ "github.com/eclipse-che/che-operator/pkg/common/infrastructure"
22+ oauthv1 "github.com/openshift/api/oauth/v1"
23+ userv1 "github.com/openshift/api/user/v1"
2024 "sigs.k8s.io/controller-runtime/pkg/webhook"
2125
2226 "github.com/eclipse-che/che-operator/controllers/namespacecache"
@@ -33,8 +37,6 @@ import (
3337 securityv1 "github.com/openshift/api/security/v1"
3438
3539 dwoApi "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
36- "github.com/devfile/devworkspace-operator/pkg/infrastructure"
37- devworkspaceinfra "github.com/devfile/devworkspace-operator/pkg/infrastructure"
3840 "go.uber.org/zap/zapcore"
3941
4042 "github.com/eclipse-che/che-operator/pkg/common/constants"
@@ -62,11 +64,9 @@ import (
6264 "github.com/go-logr/logr"
6365 configv1 "github.com/openshift/api/config/v1"
6466 consolev1 "github.com/openshift/api/console/v1"
65- oauthv1 "github.com/openshift/api/oauth/v1"
6667 templatev1 "github.com/openshift/api/template/v1"
6768
6869 checontroller "github.com/eclipse-che/che-operator/controllers/che"
69- "github.com/eclipse-che/che-operator/pkg/common/utils"
7070
7171 admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
7272 utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -79,7 +79,6 @@ import (
7979 imagepullerapi "github.com/che-incubator/kubernetes-image-puller-operator/api/v1alpha1"
8080 projectv1 "github.com/openshift/api/project/v1"
8181 routev1 "github.com/openshift/api/route/v1"
82- userv1 "github.com/openshift/api/user/v1"
8382 appsv1 "k8s.io/api/apps/v1"
8483 batchv1 "k8s.io/api/batch/v1"
8584 corev1 "k8s.io/api/core/v1"
@@ -101,10 +100,6 @@ var (
101100 renewDeadline = 30 * time .Second
102101)
103102
104- const (
105- leasesApiResourceName = "leases"
106- )
107-
108103func init () {
109104 flag .StringVar (& metricsAddr , "metrics-bind-address" , ":60000" , "The address the metric endpoint binds to." )
110105 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":6789" , "The address the probe endpoint binds to." )
@@ -122,11 +117,6 @@ func init() {
122117 logger := zap .New (zap .UseFlagOptions (& opts ))
123118 ctrl .SetLogger (logger )
124119
125- if err := infrastructure .Initialize (); err != nil {
126- logger .Error (err , "Unable determine installation platform" )
127- os .Exit (1 )
128- }
129-
130120 defaults .Initialize ()
131121
132122 printVersion (logger )
@@ -145,15 +135,20 @@ func init() {
145135 utilruntime .Must (corev1 .AddToScheme (scheme ))
146136
147137 if infrastructure .IsOpenShift () {
148- utilruntime .Must (routev1 .AddToScheme (scheme ))
149- utilruntime .Must (oauthv1 .AddToScheme (scheme ))
150- utilruntime .Must (userv1 .AddToScheme (scheme ))
151- utilruntime .Must (configv1 .AddToScheme (scheme ))
152- utilruntime .Must (consolev1 .AddToScheme (scheme ))
153- utilruntime .Must (projectv1 .AddToScheme (scheme ))
138+ utilruntime .Must (routev1 .Install (scheme ))
139+ utilruntime .Must (configv1 .Install (scheme ))
140+ utilruntime .Must (consolev1 .Install (scheme ))
141+ utilruntime .Must (projectv1 .Install (scheme ))
154142 utilruntime .Must (securityv1 .Install (scheme ))
155143 utilruntime .Must (templatev1 .Install (scheme ))
156144 }
145+
146+ // User and OAuthClient API are disabled in case of external IDP
147+ // Check API before adding to the scheme
148+ if infrastructure .IsOpenShiftOAuthEnabled () {
149+ utilruntime .Must (userv1 .Install (scheme ))
150+ utilruntime .Must (oauthv1 .Install (scheme ))
151+ }
157152}
158153
159154func getLogLevel () zapcore.Level {
@@ -181,7 +176,7 @@ func printVersion(logger logr.Logger) {
181176
182177 infra := "Kubernetes"
183178 if infrastructure .IsOpenShift () {
184- infra = "OpenShift v4.x "
179+ infra = "OpenShift"
185180 }
186181 logger .Info ("Operator is running on " , "Infrastructure" , infra )
187182}
@@ -202,6 +197,11 @@ func getWatchNamespace() (string, error) {
202197}
203198
204199func main () {
200+ if err := dwInfra .Initialize (); err != nil {
201+ setupLog .Error (err , "Failed to initialize infrastructure" )
202+ os .Exit (1 )
203+ }
204+
205205 watchNamespace , err := getWatchNamespace ()
206206 if err != nil {
207207 setupLog .Error (err , "unable to get WatchNamespace, " +
@@ -216,8 +216,8 @@ func main() {
216216 os .Exit (1 )
217217 }
218218
219- if ! utils . IsK8SResourceServed ( discoveryClient , leasesApiResourceName ) {
220- setupLog .Info ("Leader election was disabled" , "Cause:" , leasesApiResourceName + "k8s api resource is an absent. " )
219+ if ! infrastructure . IsLeaderElectionEnabled ( ) {
220+ setupLog .Info ("Leader election disabled" )
221221 enableLeaderElection = false
222222 }
223223
@@ -227,13 +227,6 @@ func main() {
227227 os .Exit (1 )
228228 }
229229
230- // DWO use the infrastructure package for openshift detection. It needs to be initialized
231- // but only supports OpenShift v4 or Kubernetes.
232- if err := devworkspaceinfra .Initialize (); err != nil {
233- setupLog .Error (err , "failed to evaluate infrastructure which is needed for DevWorkspace support" )
234- os .Exit (1 )
235- }
236-
237230 cacheFunction , err := getCacheFunc ()
238231 if err != nil {
239232 setupLog .Error (err , "failed to create cache function" )
@@ -394,11 +387,14 @@ func getCacheFunc() (cache.NewCacheFunc, error) {
394387 }
395388
396389 if infrastructure .IsOpenShift () {
397- selectors [& oauthv1.OAuthClient {}] = cache.ByObject {Label : partOfCheObjectSelector }
398390 selectors [& routev1.Route {}] = cache.ByObject {Label : partOfCheObjectSelector }
399391 selectors [& templatev1.Template {}] = cache.ByObject {Label : partOfCheObjectSelector }
400392 }
401393
394+ if infrastructure .IsOpenShiftOAuthEnabled () {
395+ selectors [& oauthv1.OAuthClient {}] = cache.ByObject {Label : partOfCheObjectSelector }
396+ }
397+
402398 return func (config * rest.Config , opts cache.Options ) (cache.Cache , error ) {
403399 opts .ByObject = selectors
404400 return cache .New (config , opts )
0 commit comments