@@ -27,6 +27,7 @@ import (
27
27
"k8s.io/apimachinery/pkg/util/validation/field"
28
28
"k8s.io/apiserver/pkg/util/webhook"
29
29
"k8s.io/klog/v2"
30
+ "k8s.io/utils/ptr"
30
31
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
31
32
32
33
configv1alpha1 "github.com/karmada-io/karmada/pkg/apis/config/v1alpha1"
@@ -103,7 +104,19 @@ func validateWebhook(hook *configv1alpha1.ResourceInterpreterWebhook, fldPath *f
103
104
case cc .URL != nil :
104
105
allErrors = append (allErrors , webhook .ValidateWebhookURL (fldPath .Child ("clientConfig" ).Child ("url" ), * cc .URL , true )... )
105
106
case cc .Service != nil :
106
- allErrors = append (allErrors , webhook .ValidateWebhookService (fldPath .Child ("clientConfig" ).Child ("service" ), cc .Service .Name , cc .Service .Namespace , cc .Service .Path , * cc .Service .Port )... )
107
+ // Temporary fix: If the service port is not specified, set a default value of 443.
108
+ // This is a workaround to prevent a panic when validating ResourceInterpreterWebhookConfiguration
109
+ // with an unspecified service port. Ideally, this logic should be handled by a MutatingWebhook,
110
+ // but introducing a MutatingWebhook at this stage would require significant changes and is not
111
+ // convenient for cherry-picking to release branches. Therefore, we are temporarily setting the
112
+ // default port here. Once a MutatingWebhook is implemented, this logic can be moved there.
113
+ //
114
+ // Note: The Interpreter framework also sets the same default value (443) when processing Service,
115
+ // so the backend will not encounter issues due to missing port information.
116
+ if cc .Service .Port == nil {
117
+ cc .Service .Port = ptr.To [int32 ](443 )
118
+ }
119
+ allErrors = append (allErrors , webhook .ValidateWebhookService (fldPath .Child ("clientConfig" ).Child ("service" ), cc .Service .Namespace , cc .Service .Name , cc .Service .Path , * cc .Service .Port )... )
107
120
}
108
121
109
122
allErrors = append (allErrors , validateInterpreterContextVersions (hook .InterpreterContextVersions , fldPath .Child ("interpreterContextVersions" ))... )
0 commit comments