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
24 changes: 21 additions & 3 deletions pkg/infrastructure/cluster.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
// Copyright (c) 2019-2026 Red Hat, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -35,8 +35,9 @@ const (

var (
// current is the infrastructure that we're currently running on.
current Type
initialized = false
current Type
certManagerDetected bool
initialized = false
)

// Initialize attempts to determine the type of cluster its currently running on (OpenShift or Kubernetes). This function
Expand All @@ -57,6 +58,14 @@ func Initialize() error {
// InitializeForTesting is used to mock running on a specific type of cluster (Kubernetes, OpenShift) in testing code.
func InitializeForTesting(currentInfrastructure Type) {
current = currentInfrastructure
certManagerDetected = false
initialized = true
}

// InitializeForTestingWithCertManager is used to mock running on a cluster with cert-manager installed.
func InitializeForTestingWithCertManager(currentInfrastructure Type) {
current = currentInfrastructure
certManagerDetected = true
initialized = true
}

Expand All @@ -72,6 +81,14 @@ func IsOpenShift() bool {
return current == OpenShiftv4
}

// CertManagerDetected returns true if the cert-manager API group was detected on the cluster.
func CertManagerDetected() bool {
if !initialized {
panic("Attempting to determine information about the cluster without initializing first")
}
return certManagerDetected
}

func detect() (Type, error) {
kubeCfg, err := config.GetConfig()
if err != nil {
Expand All @@ -85,6 +102,7 @@ func detect() (Type, error) {
if err != nil {
return Unsupported, fmt.Errorf("could not read API groups: %w", err)
}
certManagerDetected = findAPIGroup(apiList.Groups, "cert-manager.io") != nil
if findAPIGroup(apiList.Groups, "route.openshift.io") == nil {
return Kubernetes, nil
} else {
Expand Down
32 changes: 32 additions & 0 deletions webhook/workspace/annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Copyright (c) 2019-2026 Red Hat, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

package workspace

import (
"fmt"

"github.com/devfile/devworkspace-operator/pkg/infrastructure"
)

func getWebhookAnnotations(namespace string) map[string]string {
annotations := map[string]string{}
if infrastructure.CertManagerDetected() {
annotations["cert-manager.io/inject-ca-from"] = fmt.Sprintf("%s/devworkspace-controller-serving-cert", namespace)
} else if infrastructure.IsOpenShift() {
annotations["service.beta.openshift.io/inject-cabundle"] = "true"
}
return annotations
}
7 changes: 4 additions & 3 deletions webhook/workspace/mutating_cfg.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
// Copyright (c) 2019-2026 Red Hat, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -153,8 +153,9 @@ func BuildMutateWebhookCfg(namespace string) *admregv1.MutatingWebhookConfigurat

return &admregv1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: MutateWebhookCfgName,
Labels: server.WebhookServerAppLabels(),
Name: MutateWebhookCfgName,
Labels: server.WebhookServerAppLabels(),
Annotations: getWebhookAnnotations(namespace),
},
Webhooks: []admregv1.MutatingWebhook{
workspaceMutateWebhook,
Expand Down
7 changes: 4 additions & 3 deletions webhook/workspace/validating_cfg.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2019-2025 Red Hat, Inc.
// Copyright (c) 2019-2026 Red Hat, Inc.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
Expand Down Expand Up @@ -34,8 +34,9 @@ func buildValidatingWebhookCfg(namespace string) *admregv1.ValidatingWebhookConf
sideEffectsNone := admregv1.SideEffectClassNone
return &admregv1.ValidatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: ValidateWebhookCfgName,
Labels: server.WebhookServerAppLabels(),
Name: ValidateWebhookCfgName,
Labels: server.WebhookServerAppLabels(),
Annotations: getWebhookAnnotations(namespace),
},
Webhooks: []admregv1.ValidatingWebhook{
{
Expand Down
Loading