Skip to content

Commit 942cb99

Browse files
committed
Merge branch 'main' into support/migrate-config-manager-to-kbagent
2 parents d9e8c27 + de0398f commit 942cb99

File tree

5 files changed

+46
-23
lines changed

5 files changed

+46
-23
lines changed

cmd/manager/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func init() {
148148
viper.SetDefault("KUBEBLOCKS_SERVICEACCOUNT_NAME", "kubeblocks")
149149
viper.SetDefault(constant.CfgKeyCtrlrMgrNS, "default")
150150
viper.SetDefault(constant.CfgHostPortConfigMapName, "kubeblocks-host-ports")
151-
viper.SetDefault(constant.CfgHostPortIncludeRanges, "1025-65536")
151+
viper.SetDefault(constant.CfgHostPortIncludeRanges, "55000-59999")
152152
viper.SetDefault(constant.CfgHostPortExcludeRanges, "6443,10250,10257,10259,2379-2380,30000-32767")
153153
viper.SetDefault(constant.KubernetesClusterDomainEnv, constant.DefaultDNSDomain)
154154
viper.SetDefault(instanceset.MaxPlainRevisionCount, 1024)

controllers/operations/opsdefinition_controller.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ import (
2323
"context"
2424
"text/template"
2525

26+
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
27+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
28+
"k8s.io/apiextensions-apiserver/pkg/apiserver/validation"
2629
"k8s.io/apimachinery/pkg/runtime"
2730
"k8s.io/client-go/tools/record"
31+
"k8s.io/kube-openapi/pkg/validation/spec"
2832
ctrl "sigs.k8s.io/controller-runtime"
2933
"sigs.k8s.io/controller-runtime/pkg/client"
3034
"sigs.k8s.io/controller-runtime/pkg/log"
@@ -74,13 +78,19 @@ func (r *OpsDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
7478
continue
7579
}
7680
if _, err = template.New("opsDefTemplate").Parse(v.Rule.Expression); err != nil {
77-
if patchErr := r.updateStatusUnavailable(reqCtx, opsDef, err); patchErr != nil {
78-
return intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, "")
79-
}
80-
return intctrlutil.Reconciled()
81+
return r.updateStatusUnavailable(reqCtx, opsDef, err)
82+
}
83+
}
84+
if opsDef.Spec.ParametersSchema != nil {
85+
out := &apiextensions.JSONSchemaProps{}
86+
if err = apiextensionsv1.Convert_v1_JSONSchemaProps_To_apiextensions_JSONSchemaProps(opsDef.Spec.ParametersSchema.OpenAPIV3Schema, out, nil); err != nil {
87+
return r.updateStatusUnavailable(reqCtx, opsDef, err)
88+
}
89+
openapiSchema := &spec.Schema{}
90+
if err = validation.ConvertJSONSchemaPropsWithPostProcess(out, openapiSchema, validation.StripUnsupportedFormatsPostProcess); err != nil {
91+
return r.updateStatusUnavailable(reqCtx, opsDef, err)
8192
}
8293
}
83-
8494
// TODO: check serviceKind, connectionCredentialName and serviceName
8595
statusPatch := client.MergeFrom(opsDef.DeepCopy())
8696
opsDef.Status.ObservedGeneration = opsDef.Generation
@@ -92,12 +102,15 @@ func (r *OpsDefinitionReconciler) Reconcile(ctx context.Context, req ctrl.Reques
92102
return intctrlutil.Reconciled()
93103
}
94104

95-
func (r *OpsDefinitionReconciler) updateStatusUnavailable(reqCtx intctrlutil.RequestCtx, opsDef *opsv1alpha1.OpsDefinition, err error) error {
105+
func (r *OpsDefinitionReconciler) updateStatusUnavailable(reqCtx intctrlutil.RequestCtx, opsDef *opsv1alpha1.OpsDefinition, err error) (ctrl.Result, error) {
96106
statusPatch := client.MergeFrom(opsDef.DeepCopy())
97107
opsDef.Status.Phase = opsv1alpha1.UnavailablePhase
98108
opsDef.Status.ObservedGeneration = opsDef.Generation
99109
opsDef.Status.Message = err.Error()
100-
return r.Client.Status().Patch(reqCtx.Ctx, opsDef, statusPatch)
110+
if err = r.Client.Status().Patch(reqCtx.Ctx, opsDef, statusPatch); err != nil {
111+
return intctrlutil.CheckedRequeueWithError(err, reqCtx.Log, "")
112+
}
113+
return intctrlutil.Reconciled()
101114
}
102115

103116
// SetupWithManager sets up the controller with the Manager.

deploy/helm/values.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,21 @@ hostPorts:
541541
# The TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them.
542542
# This is a security feaure, in that if you connect to a service on one of these ports you can be fairly sure
543543
# that you have the real thing, and not a fake which some hacker has put up for you.
544+
# =================================================================================
545+
# Default ports update in KubeBlocks 1.1
546+
# Ports 49152–65535 is defined by IANA as the private (dynamic) port range,
547+
# but this range may conflict with the node’s ephemeral ports.
548+
# Therefore KubeBlocks reserves 55000–59999 as a dedicated hostPort range
549+
# to reduce port collision risks and improve cluster stability.
550+
# Users are recommended to update include/exclude ranges on demand
551+
# =================================================================================
544552
include:
545-
- "1025-65536"
553+
- "55000-59999"
546554
# https://kubernetes.io/docs/reference/networking/ports-and-protocols/
547555
# exclude ports used by kubernetes
556+
# =================================================================================
557+
# Following ports are not in the 'include' range but are still kept as examples
558+
# =================================================================================
548559
exclude:
549560
- "6443"
550561
- "10250"

pkg/controller/kubebuilderx/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func (c *controller) emitFailureEvent() {
164164
return
165165
}
166166
// TODO(free6om): make error message user-friendly
167-
c.tree.EventRecorder.Eventf(c.tree.GetRoot(), corev1.EventTypeWarning, "FailedReconcile", "reconcile failed: %s", c.err.Error())
167+
c.tree.EventRecorder.Eventf(c.tree.GetRoot(), corev1.EventTypeWarning, "FailedReconcile", "%s", c.err.Error())
168168
}
169169

170170
func NewController(ctx context.Context, cli client.Client, req ctrl.Request, recorder record.EventRecorder, logger logr.Logger) Controller {

pkg/controller/kubebuilderx/plan_builder.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import (
3030
corev1 "k8s.io/api/core/v1"
3131
rbacv1 "k8s.io/api/rbac/v1"
3232
"k8s.io/apimachinery/pkg/api/equality"
33-
apierrors "k8s.io/apimachinery/pkg/api/errors"
3433
"k8s.io/apimachinery/pkg/util/sets"
3534
"k8s.io/client-go/tools/record"
35+
"k8s.io/klog/v2"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3838

@@ -265,8 +265,8 @@ func (b *PlanBuilder) defaultWalkFunc(v graph.Vertex) error {
265265

266266
func (b *PlanBuilder) createObject(ctx context.Context, vertex *model.ObjectVertex) error {
267267
err := b.cli.Create(ctx, vertex.Obj, clientOption(vertex))
268-
if err != nil && !apierrors.IsAlreadyExists(err) {
269-
return err
268+
if err != nil {
269+
return fmt.Errorf("create %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
270270
}
271271
b.emitEvent(vertex.Obj, "SuccessfulCreate", model.CREATE)
272272
return nil
@@ -282,8 +282,8 @@ func (b *PlanBuilder) updateObject(ctx context.Context, vertex *model.ObjectVert
282282
err = b.cli.Update(ctx, vertex.Obj, clientOption(vertex))
283283
reason = "SuccessfulUpdate"
284284
}
285-
if err != nil && !apierrors.IsNotFound(err) {
286-
return err
285+
if err != nil {
286+
return fmt.Errorf("update %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
287287
}
288288
b.emitEvent(vertex.Obj, reason, model.UPDATE)
289289
return nil
@@ -300,8 +300,8 @@ func (b *PlanBuilder) patchObject(ctx context.Context, vertex *model.ObjectVerte
300300
err = b.cli.Patch(ctx, vertex.Obj, patch, clientOption(vertex))
301301
reason = "SuccessfulPatch"
302302
}
303-
if err != nil && !apierrors.IsNotFound(err) {
304-
return err
303+
if err != nil {
304+
return fmt.Errorf("patch %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
305305
}
306306
b.emitEvent(vertex.Obj, reason, model.PATCH)
307307
return nil
@@ -314,15 +314,14 @@ func (b *PlanBuilder) deleteObject(ctx context.Context, vertex *model.ObjectVert
314314
}
315315
if len(finalizer) > 0 && controllerutil.RemoveFinalizer(vertex.Obj, finalizer) {
316316
err := b.cli.Update(ctx, vertex.Obj, clientOption(vertex))
317-
if err != nil && !apierrors.IsNotFound(err) {
318-
b.transCtx.logger.Error(err, fmt.Sprintf("delete %T error: %s", vertex.Obj, vertex.Obj.GetName()))
319-
return err
317+
if err != nil {
318+
return fmt.Errorf("delete %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
320319
}
321320
}
322321
if !model.IsObjectDeleting(vertex.Obj) {
323322
err := b.cli.Delete(ctx, vertex.Obj, clientOption(vertex))
324-
if err != nil && !apierrors.IsNotFound(err) {
325-
return err
323+
if err != nil {
324+
return fmt.Errorf("delete %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
326325
}
327326
b.emitEvent(vertex.Obj, "SuccessfulDelete", model.DELETE)
328327
}
@@ -331,7 +330,7 @@ func (b *PlanBuilder) deleteObject(ctx context.Context, vertex *model.ObjectVert
331330

332331
func (b *PlanBuilder) statusObject(ctx context.Context, vertex *model.ObjectVertex) error {
333332
if err := b.cli.Status().Update(ctx, vertex.Obj, clientOption(vertex)); err != nil {
334-
return err
333+
return fmt.Errorf("status %T %s failed: %w", vertex.Obj, klog.KObj(vertex.Obj), err)
335334
}
336335
return nil
337336
}

0 commit comments

Comments
 (0)