Skip to content

Commit 0322bc3

Browse files
amisevsksleshchenko
authored andcommitted
Move IsOpenShift check to a global variable that must be initialized
Signed-off-by: Angel Misevski <[email protected]>
1 parent a6e179e commit 0322bc3

File tree

21 files changed

+285
-377
lines changed

21 files changed

+285
-377
lines changed

controllers/controller/workspacerouting/solvers/basic_solver.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package solvers
1515
import (
1616
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
1717
"github.com/devfile/devworkspace-operator/pkg/constants"
18+
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
1819
)
1920

2021
var routeAnnotations = func(endpointName string) map[string]string {
@@ -37,9 +38,7 @@ var nginxIngressAnnotations = func(endpointName string) map[string]string {
3738
// According to the current cluster there is different behavior:
3839
// Kubernetes: use Ingresses without TLS
3940
// OpenShift: use Routes with TLS enabled
40-
type BasicSolver struct {
41-
isOpenShift bool
42-
}
41+
type BasicSolver struct{}
4342

4443
var _ RoutingSolver = (*BasicSolver)(nil)
4544

@@ -58,7 +57,7 @@ func (s *BasicSolver) GetSpecObjects(routing *controllerv1alpha1.WorkspaceRoutin
5857
services := getServicesForEndpoints(spec.Endpoints, workspaceMeta)
5958
services = append(services, GetDiscoverableServicesForEndpoints(spec.Endpoints, workspaceMeta)...)
6059
routingObjects.Services = services
61-
if s.isOpenShift {
60+
if infrastructure.IsOpenShift() {
6261
routingObjects.Routes = getRoutesForSpec(spec.Endpoints, workspaceMeta)
6362
} else {
6463
routingObjects.Ingresses = getIngressesForSpec(spec.Endpoints, workspaceMeta)

controllers/controller/workspacerouting/solvers/openshift_oauth_solver.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ package solvers
1515
import (
1616
"fmt"
1717

18+
devworkspace "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
19+
20+
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
1821
maputils "github.com/devfile/devworkspace-operator/internal/map"
22+
"github.com/devfile/devworkspace-operator/pkg/common"
1923
"github.com/devfile/devworkspace-operator/pkg/constants"
2024

21-
"sigs.k8s.io/controller-runtime/pkg/client"
22-
23-
devworkspace "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
2425
oauthv1 "github.com/openshift/api/oauth/v1"
2526
routeV1 "github.com/openshift/api/route/v1"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
28-
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
29-
"github.com/devfile/devworkspace-operator/pkg/common"
28+
"sigs.k8s.io/controller-runtime/pkg/client"
3029
)
3130

3231
type OpenShiftOAuthSolver struct {

controllers/controller/workspacerouting/solvers/solver.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"sigs.k8s.io/controller-runtime/pkg/client"
2323

2424
controllerv1alpha1 "github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
25+
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
2526
)
2627

2728
type RoutingObjects struct {
@@ -73,7 +74,7 @@ type RoutingSolverGetter interface {
7374
// the routingClass is not recognized, and any other error if the routingClass is invalid (e.g. an OpenShift-only
7475
// routingClass on a vanilla Kubernetes platform). Note that an empty routingClass is handled by the DevWorkspace controller itself,
7576
// and should not be handled by external controllers.
76-
GetSolver(client client.Client, routingClass controllerv1alpha1.WorkspaceRoutingClass, isOpenShift bool) (solver RoutingSolver, err error)
77+
GetSolver(client client.Client, routingClass controllerv1alpha1.WorkspaceRoutingClass) (solver RoutingSolver, err error)
7778
}
7879

7980
type SolverGetter struct{}
@@ -97,10 +98,11 @@ func (_ *SolverGetter) HasSolver(routingClass controllerv1alpha1.WorkspaceRoutin
9798
}
9899
}
99100

100-
func (_ *SolverGetter) GetSolver(client client.Client, routingClass controllerv1alpha1.WorkspaceRoutingClass, isOpenShift bool) (RoutingSolver, error) {
101+
func (_ *SolverGetter) GetSolver(client client.Client, routingClass controllerv1alpha1.WorkspaceRoutingClass) (RoutingSolver, error) {
102+
isOpenShift := infrastructure.IsOpenShift()
101103
switch routingClass {
102104
case controllerv1alpha1.WorkspaceRoutingBasic:
103-
return &BasicSolver{isOpenShift: isOpenShift}, nil
105+
return &BasicSolver{}, nil
104106
case controllerv1alpha1.WorkspaceRoutingOpenShiftOauth:
105107
if !isOpenShift {
106108
return nil, fmt.Errorf("routing class %s only supported on OpenShift", routingClass)

controllers/controller/workspacerouting/workspacerouting_controller.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ import (
1818
"time"
1919

2020
"github.com/devfile/devworkspace-operator/controllers/controller/workspacerouting/solvers"
21-
"github.com/devfile/devworkspace-operator/internal/cluster"
2221
maputils "github.com/devfile/devworkspace-operator/internal/map"
2322
"github.com/devfile/devworkspace-operator/pkg/constants"
24-
25-
"github.com/google/go-cmp/cmp"
23+
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
2624

2725
"github.com/go-logr/logr"
26+
"github.com/google/go-cmp/cmp"
2827
routeV1 "github.com/openshift/api/route/v1"
2928
corev1 "k8s.io/api/core/v1"
3029
"k8s.io/api/extensions/v1beta1"
@@ -47,9 +46,8 @@ const workspaceRoutingFinalizer = "workspacerouting.controller.devfile.io"
4746
// WorkspaceRoutingReconciler reconciles a WorkspaceRouting object
4847
type WorkspaceRoutingReconciler struct {
4948
client.Client
50-
Log logr.Logger
51-
Scheme *runtime.Scheme
52-
IsOpenShift bool
49+
Log logr.Logger
50+
Scheme *runtime.Scheme
5351
// SolverGetter will be used to get solvers for a particular workspaceRouting
5452
SolverGetter solvers.RoutingSolverGetter
5553
}
@@ -88,7 +86,7 @@ func (r *WorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
8886
return reconcile.Result{}, r.markRoutingFailed(instance)
8987
}
9088

91-
solver, err := r.SolverGetter.GetSolver(r.Client, instance.Spec.RoutingClass, r.IsOpenShift)
89+
solver, err := r.SolverGetter.GetSolver(r.Client, instance.Spec.RoutingClass)
9290
if err != nil {
9391
if errors.Is(err, solvers.RoutingNotSupported) {
9492
return reconcile.Result{}, nil
@@ -184,7 +182,7 @@ func (r *WorkspaceRoutingReconciler) Reconcile(req ctrl.Request) (ctrl.Result, e
184182
Services: clusterServices,
185183
}
186184

187-
if r.IsOpenShift {
185+
if infrastructure.IsOpenShift() {
188186
routesInSync, clusterRoutes, err := r.syncRoutes(instance, routes)
189187
if err != nil || !routesInSync {
190188
reqLogger.Info("Routes not in sync")
@@ -295,13 +293,8 @@ func (r *WorkspaceRoutingReconciler) SetupWithManager(mgr ctrl.Manager) error {
295293
For(&controllerv1alpha1.WorkspaceRouting{}).
296294
Owns(&corev1.Service{}).
297295
Owns(&v1beta1.Ingress{})
298-
if isOS, err := cluster.IsOpenShift(); err != nil {
299-
return err
300-
} else if isOS {
296+
if infrastructure.IsOpenShift() {
301297
bld.Owns(&routeV1.Route{})
302-
r.IsOpenShift = true
303-
} else {
304-
r.IsOpenShift = false
305298
}
306299
if r.SolverGetter == nil {
307300
return NoSolversEnabled

controllers/workspace/provision/deployment.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
maputils "github.com/devfile/devworkspace-operator/internal/map"
2222
"github.com/devfile/devworkspace-operator/pkg/constants"
23+
"github.com/devfile/devworkspace-operator/pkg/infrastructure"
2324

2425
"github.com/devfile/devworkspace-operator/pkg/common"
2526

@@ -140,7 +141,7 @@ func DeleteWorkspaceDeployment(ctx context.Context, workspace *devworkspace.DevW
140141
}
141142

142143
func GetDevWorkspaceSecurityContext() *corev1.PodSecurityContext {
143-
if !config.ControllerCfg.IsOpenShift() {
144+
if !infrastructure.IsOpenShift() {
144145
uID := int64(1234)
145146
rootGID := int64(0)
146147
nonRoot := true

controllers/workspace/provision/pull_secret.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"github.com/devfile/devworkspace-operator/apis/controller/v1alpha1"
2020
"github.com/devfile/devworkspace-operator/pkg/constants"
21+
2122
corev1 "k8s.io/api/core/v1"
2223
"k8s.io/apimachinery/pkg/labels"
2324
"sigs.k8s.io/controller-runtime/pkg/client"

internal/cluster/info.go

Lines changed: 0 additions & 126 deletions
This file was deleted.

0 commit comments

Comments
 (0)