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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
50 changes: 14 additions & 36 deletions api/v2/checluster_webhook.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.
// This program and the accompanying materials are made
// available under the terms of the Eclipse Public License 2.0
// which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -18,8 +18,6 @@ import (
"strconv"
"strings"

"sigs.k8s.io/controller-runtime/pkg/webhook"

"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/devfile/devworkspace-operator/pkg/infrastructure"
Expand All @@ -34,7 +32,6 @@ import (
k8shelper "github.com/eclipse-che/che-operator/pkg/common/k8s-helper"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
)

Expand All @@ -43,8 +40,7 @@ var (
)

func SetupWebhookWithManager(mgr ctrl.Manager) error {
return ctrl.NewWebhookManagedBy(mgr).
For(&CheCluster{}).
return ctrl.NewWebhookManagedBy(mgr, &CheCluster{}).
WithDefaulter(&CheClusterDefaulter{}).
WithValidator(&CheClusterValidator{}).
Complete()
Expand All @@ -55,16 +51,10 @@ func SetupWebhookWithManager(mgr ctrl.Manager) error {

type CheClusterDefaulter struct{}

var _ webhook.CustomDefaulter = &CheClusterDefaulter{}

// Default implements webhook.Defaulter so a webhook will be registered for the type
func (r *CheClusterDefaulter) Default(_ context.Context, obj runtime.Object) error {
cheCluster, ok := obj.(*CheCluster)

if !ok {
return fmt.Errorf("expected an CheCluster object but got %T", obj)
}
var _ admission.Defaulter[*CheCluster] = &CheClusterDefaulter{}

// Default implements admission.Defaulter so a webhook will be registered for the type
func (r *CheClusterDefaulter) Default(_ context.Context, cheCluster *CheCluster) error {
webhookLogger.Info("Defaulting for CheCluster", "name", cheCluster.GetName())

r.setDisableContainerRunCapabilities(cheCluster)
Expand Down Expand Up @@ -109,16 +99,10 @@ func (r *CheClusterDefaulter) setContainerBuildConfiguration(cheCluster *CheClus

type CheClusterValidator struct{}

var _ admission.CustomValidator = &CheClusterValidator{}

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
func (r *CheClusterValidator) ValidateCreate(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
cheCluster, ok := obj.(*CheCluster)

if !ok {
return nil, fmt.Errorf("expected an CheCluster object but got %T", obj)
}
var _ admission.Validator[*CheCluster] = &CheClusterValidator{}

// ValidateCreate implements admission.Validator so a webhook will be registered for the type
func (r *CheClusterValidator) ValidateCreate(_ context.Context, cheCluster *CheCluster) (admission.Warnings, error) {
webhookLogger.Info("Validation for CheCluster upon creation", "name", cheCluster.GetName())

if err := r.ensureSingletonCheCluster(); err != nil {
Expand All @@ -127,21 +111,15 @@ func (r *CheClusterValidator) ValidateCreate(_ context.Context, obj runtime.Obje
return []string{}, r.validate(cheCluster)
}

// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type CheCluster.
func (r *CheClusterValidator) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (admission.Warnings, error) {
cheCluster, ok := newObj.(*CheCluster)

if !ok {
return nil, fmt.Errorf("expected an CheCluster object but got %T", newObj)
}

webhookLogger.Info("Validation for CheCluster upon update", "name", cheCluster.GetName())
// ValidateUpdate implements admission.Validator so a webhook will be registered for the type CheCluster.
func (r *CheClusterValidator) ValidateUpdate(_ context.Context, _, newObj *CheCluster) (admission.Warnings, error) {
webhookLogger.Info("Validation for CheCluster upon update", "name", newObj.GetName())

return nil, r.validate(cheCluster)
return nil, r.validate(newObj)
}

// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type CheCluster.
func (r *CheClusterValidator) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
// ValidateDelete implements admission.Validator so a webhook will be registered for the type CheCluster.
func (r *CheClusterValidator) ValidateDelete(_ context.Context, _ *CheCluster) (admission.Warnings, error) {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion api/v2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ metadata:
categories: Developer Tools
certified: "false"
containerImage: quay.io/eclipse/che-operator:next
createdAt: "2026-03-19T13:07:33Z"
createdAt: "2026-03-25T12:21:22Z"
description: A Kube-native development solution that delivers portable and collaborative
developer workspaces.
features.operators.openshift.io/cnf: "false"
Expand All @@ -108,7 +108,7 @@ metadata:
operatorframework.io/arch.amd64: supported
operatorframework.io/arch.arm64: supported
operatorframework.io/os.linux: supported
name: eclipse-che.v7.116.0-956.next
name: eclipse-che.v7.116.0-957.next
namespace: placeholder
spec:
apiservicedefinitions: {}
Expand Down Expand Up @@ -1144,7 +1144,7 @@ spec:
name: gateway-authorization-sidecar-k8s
- image: quay.io/che-incubator/header-rewrite-proxy:latest
name: gateway-header-sidecar
version: 7.116.0-956.next
version: 7.116.0-957.next
webhookdefinitions:
- admissionReviewVersions:
- v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4170,9 +4170,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -4698,9 +4699,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -5077,9 +5079,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -5422,9 +5425,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -5807,9 +5811,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -8919,7 +8924,9 @@ spec:
type: integer
type: object
resizePolicy:
description: Resources resize policy for the container.
description: |-
Resources resize policy for the container.
This field cannot be set on ephemeral containers.
items:
description: ContainerResizePolicy represents resource
resize policy for the container.
Expand Down Expand Up @@ -10496,9 +10503,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -11024,9 +11032,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down
25 changes: 17 additions & 8 deletions config/crd/bases/org.eclipse.che_checlusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4139,9 +4139,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -4662,9 +4663,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -5039,9 +5041,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -5382,9 +5385,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -5765,9 +5769,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -8871,7 +8876,9 @@ spec:
type: integer
type: object
resizePolicy:
description: Resources resize policy for the container.
description: |-
Resources resize policy for the container.
This field cannot be set on ephemeral containers.
items:
description: ContainerResizePolicy represents resource
resize policy for the container.
Expand Down Expand Up @@ -10446,9 +10453,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down Expand Up @@ -10969,9 +10977,10 @@ spec:
operator:
description: |-
Operator represents a key's relationship to the value.
Valid operators are Exists and Equal. Defaults to Equal.
Valid operators are Exists, Equal, Lt, and Gt. Defaults to Equal.
Exists is equivalent to wildcard for value, so that a pod can
tolerate all taints of a particular category.
Lt and Gt perform numeric comparisons (requires feature gate TaintTolerationComparisonOperators).
type: string
tolerationSeconds:
description: |-
Expand Down
Loading
Loading