Skip to content

Commit c281ede

Browse files
committed
fixes
Signed-off-by: Anatolii Bazko <[email protected]>
1 parent ef7ae8d commit c281ede

File tree

5 files changed

+44
-167
lines changed

5 files changed

+44
-167
lines changed

pkg/common/infrastructure/cluster.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ package infrastructure
1414

1515
import (
1616
"os"
17+
"slices"
1718
"strings"
1819

1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -28,7 +29,6 @@ const (
2829
Unknown Type = iota
2930
Kubernetes
3031
OpenShiftV4
31-
OpenShiftV5
3232

3333
LeasesResources = "leases"
3434
OAuthClientsResources = "oauthclients"
@@ -57,7 +57,7 @@ func GetOperatorNamespace() (string, error) {
5757

5858
func IsOpenShift() bool {
5959
initializeIfNeeded()
60-
return infrastructure == OpenShiftV4 || infrastructure == OpenShiftV5
60+
return infrastructure == OpenShiftV4
6161
}
6262

6363
func IsOpenShiftOAuthEnabled() bool {
@@ -111,7 +111,7 @@ func initializeIfNeeded() {
111111
os.Exit(1)
112112
}
113113

114-
if hasAPIGroup(apiGroups, "route.openshift.io") {
114+
if hasAPIGroup(apiGroups, "config.openshift.io") {
115115
infrastructure = OpenShiftV4
116116
isOpenShiftOAuthEnabled = hasAPIResource(apiResources, OAuthClientsResources)
117117
} else {
@@ -124,13 +124,9 @@ func initializeIfNeeded() {
124124
}
125125

126126
func hasAPIGroup(source []*metav1.APIGroup, apiName string) bool {
127-
for i := 0; i < len(source); i++ {
128-
if source[i].Name == apiName {
129-
return true
130-
}
131-
}
132-
133-
return false
127+
return slices.ContainsFunc(source, func(g *metav1.APIGroup) bool {
128+
return g.Name == apiName
129+
})
134130
}
135131

136132
func hasAPIResource(resources []*metav1.APIResourceList, resourceName string) bool {

pkg/common/operator-defaults/defaults.go

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"github.com/eclipse-che/che-operator/pkg/common/infrastructure"
2121
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2222
"k8s.io/apimachinery/pkg/runtime"
23+
ctrl "sigs.k8s.io/controller-runtime"
2324

2425
util "github.com/eclipse-che/che-operator/pkg/common/utils"
25-
"github.com/sirupsen/logrus"
2626
appsv1 "k8s.io/api/apps/v1"
2727
)
2828

@@ -52,17 +52,23 @@ var (
5252
defaultDevfileRegistryExternalDevfileRegistries string
5353

5454
initialized = false
55+
56+
log = ctrl.Log.WithName("defaults")
5557
)
5658

5759
func InitializeForTesting(operatorDeploymentFilePath string) {
5860
operatorDeployment := &appsv1.Deployment{}
5961
if err := util.ReadObjectInto(operatorDeploymentFilePath, operatorDeployment); err != nil {
60-
logrus.Fatalf("Failed to read operator deployment from '%s', cause: %v", operatorDeploymentFilePath, err)
62+
log.Error(err, "Error reading operator deployment")
63+
os.Exit(1)
6164
}
6265

6366
for _, container := range operatorDeployment.Spec.Template.Spec.Containers {
6467
for _, env := range container.Env {
65-
os.Setenv(env.Name, env.Value)
68+
err := os.Setenv(env.Name, env.Value)
69+
if err != nil {
70+
log.Error(err, "Error setting env variable", "name", env.Name)
71+
}
6672
}
6773
}
6874

@@ -109,191 +115,192 @@ func Initialize() {
109115
func ensureEnv(name string) string {
110116
value := os.Getenv(name)
111117
if value == "" {
112-
logrus.Fatalf("Failed to initialize default value: '%s'. Environment variable not found.", name)
118+
log.Error(fmt.Errorf("environment variable %s not set", name), "unable to determine required environment variable")
119+
os.Exit(1)
113120
}
114121

115122
return value
116123
}
117124

118125
func GetCheServerImage(checluster interface{}) string {
119126
if !initialized {
120-
logrus.Fatalf("Operator defaults are not initialized.")
127+
Initialize()
121128
}
122129

123130
return PatchDefaultImageName(checluster, defaultCheServerImage)
124131
}
125132

126133
func GetCheTLSSecretsCreationJobImage() string {
127134
if !initialized {
128-
logrus.Fatalf("Operator defaults are not initialized.")
135+
Initialize()
129136
}
130137

131138
return defaultCheTLSSecretsCreationJobImage
132139
}
133140

134141
func GetCheVersion() string {
135142
if !initialized {
136-
logrus.Fatalf("Operator defaults are not initialized.")
143+
Initialize()
137144
}
138145

139146
return defaultCheVersion
140147
}
141148

142149
func GetDashboardImage(checluster interface{}) string {
143150
if !initialized {
144-
logrus.Fatalf("Operator defaults are not initialized.")
151+
Initialize()
145152
}
146153

147154
return PatchDefaultImageName(checluster, defaultDashboardImage)
148155
}
149156

150157
func GetPluginRegistryImage(checluster interface{}) string {
151158
if !initialized {
152-
logrus.Fatalf("Operator defaults are not initialized.")
159+
Initialize()
153160
}
154161

155162
return PatchDefaultImageName(checluster, defaultPluginRegistryImage)
156163
}
157164

158165
func GetGatewayImage(checluster interface{}) string {
159166
if !initialized {
160-
logrus.Fatalf("Operator defaults are not initialized.")
167+
Initialize()
161168
}
162169

163170
return PatchDefaultImageName(checluster, defaultSingleHostGatewayImage)
164171
}
165172

166173
func GetGatewayConfigSidecarImage(checluster interface{}) string {
167174
if !initialized {
168-
logrus.Fatalf("Operator defaults are not initialized.")
175+
Initialize()
169176
}
170177

171178
return PatchDefaultImageName(checluster, defaultSingleHostGatewayConfigSidecarImage)
172179
}
173180

174181
func GetGatewayKubernetesAuthenticationSidecarImage(checluster interface{}) string {
175182
if !initialized {
176-
logrus.Fatalf("Operator defaults are not initialized.")
183+
Initialize()
177184
}
178185

179186
return PatchDefaultImageName(checluster, defaultGatewayKubernetesAuthenticationSidecarImage)
180187
}
181188

182189
func GetGatewayKubernetesAuthorizationSidecarImage(checluster interface{}) string {
183190
if !initialized {
184-
logrus.Fatalf("Operator defaults are not initialized.")
191+
Initialize()
185192
}
186193

187194
return PatchDefaultImageName(checluster, defaultGatewayKubernetesAuthorizationSidecarImage)
188195
}
189196

190197
func GetGatewayOpenShiftAuthenticationSidecarImage(checluster interface{}) string {
191198
if !initialized {
192-
logrus.Fatalf("Operator defaults are not initialized.")
199+
Initialize()
193200
}
194201

195202
return PatchDefaultImageName(checluster, defaultGatewayOpenShiftAuthenticationSidecarImage)
196203
}
197204

198205
func GetGatewayOpenShiftAuthorizationSidecarImage(checluster interface{}) string {
199206
if !initialized {
200-
logrus.Fatalf("Operator defaults are not initialized.")
207+
Initialize()
201208
}
202209

203210
return PatchDefaultImageName(checluster, defaultGatewayOpenShiftAuthorizationSidecarImage)
204211
}
205212

206213
func GetCheFlavor() string {
207214
if !initialized {
208-
logrus.Fatalf("Operator defaults are not initialized.")
215+
Initialize()
209216
}
210217

211218
return defaultCheFlavor
212219
}
213220

214221
func GetConsoleLinkName() string {
215222
if !initialized {
216-
logrus.Fatalf("Operator defaults are not initialized.")
223+
Initialize()
217224
}
218225

219226
return defaultConsoleLinkName
220227
}
221228

222229
func GetConsoleLinkDisplayName() string {
223230
if !initialized {
224-
logrus.Fatalf("Operator defaults are not initialized.")
231+
Initialize()
225232
}
226233

227234
return defaultConsoleLinkDisplayName
228235
}
229236

230237
func GetConsoleLinkSection() string {
231238
if !initialized {
232-
logrus.Fatalf("Operator defaults are not initialized.")
239+
Initialize()
233240
}
234241

235242
return defaultConsoleLinkSection
236243
}
237244

238245
func GetConsoleLinkImage() string {
239246
if !initialized {
240-
logrus.Fatalf("Operator defaults are not initialized.")
247+
Initialize()
241248
}
242249

243250
return defaultsConsoleLinkImage
244251
}
245252

246253
func GetDevfileRegistryExternalDevfileRegistries() string {
247254
if !initialized {
248-
logrus.Fatalf("Operator defaults are not initialized.")
255+
Initialize()
249256
}
250257

251258
return defaultDevfileRegistryExternalDevfileRegistries
252259
}
253260

254261
func GetPluginRegistryOpenVSXURL() string {
255262
if !initialized {
256-
logrus.Fatalf("Operator defaults are not initialized.")
263+
Initialize()
257264
}
258265

259266
return defaultPluginRegistryOpenVSXURL
260267
}
261268

262269
func GetDashboardHeaderMessageText() string {
263270
if !initialized {
264-
logrus.Fatalf("Operator defaults are not initialized.")
271+
Initialize()
265272
}
266273

267274
return defaultDashboardHeaderMessageText
268275
}
269276

270277
func GetDevEnvironmentsDefaultEditor() string {
271278
if !initialized {
272-
logrus.Fatalf("Operator defaults are not initialized.")
279+
Initialize()
273280
}
274281

275282
return defaultDevEnvironmentsDefaultEditor
276283
}
277284

278285
func GetDevEnvironmentsDefaultComponents() string {
279286
if !initialized {
280-
logrus.Fatalf("Operator defaults are not initialized.")
287+
Initialize()
281288
}
282289

283290
return defaultDevEnvironmentsDefaultComponents
284291
}
285292

286293
func GetDevEnvironmentsContainerSecurityContext() string {
287294
if !initialized {
288-
logrus.Fatalf("Operator defaults are not initialized.")
295+
Initialize()
289296
}
290297

291298
return defaultDevEnvironmentsContainerSecurityContext
292299
}
293300

294301
func GetDevEnvironmentsDisableContainerBuildCapabilities() string {
295302
if !initialized {
296-
logrus.Fatalf("Operator defaults are not initialized.")
303+
Initialize()
297304
}
298305

299306
return defaultDevEnvironmentsDisableContainerBuildCapabilities

pkg/deploy/gateway/oauth_proxy.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,14 @@ func getOauthProxyContainerSpec(ctx *chetypes.DeployContext) corev1.Container {
199199
configMapRevision := map[bool]string{true: cm.GetResourceVersion(), false: ""}[exists]
200200

201201
var image, probePath string
202-
var args []string
202+
var args = []string{"--config=/etc/oauth-proxy/oauth-proxy.cfg"}
203203
if infrastructure.IsOpenShiftOAuthEnabled() {
204204
image = defaults.GetGatewayOpenShiftAuthenticationSidecarImage(ctx.CheCluster)
205205
probePath = "/oauth/healthz"
206-
args = []string{
207-
"--config=/etc/oauth-proxy/oauth-proxy.cfg",
208-
}
209206
} else {
210207
image = defaults.GetGatewayKubernetesAuthenticationSidecarImage(ctx.CheCluster)
211208
probePath = "/ping"
212-
args = []string{
213-
"--config=/etc/oauth-proxy/oauth-proxy.cfg",
214-
"--ping-path=/ping",
215-
"--exclude-logging-path=/ping",
216-
}
209+
args = append(args, "--ping-path=/ping", "--exclude-logging-path=/ping")
217210
}
218211

219212
return corev1.Container{

0 commit comments

Comments
 (0)