WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 87e8688

Browse files
committed
update API
1 parent 23c8d20 commit 87e8688

19 files changed

+356
-262
lines changed

apis/apps/v1/deprecated.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ func (r *Cluster) GetComponentByName(componentName string) *ClusterComponentSpec
5050
}
5151

5252
func (r *ClusterSpec) GetComponentByName(componentName string) *ClusterComponentSpec {
53-
for _, v := range r.ComponentSpecs {
53+
for i, v := range r.ComponentSpecs {
5454
if v.Name == componentName {
55-
return &v
55+
return &r.ComponentSpecs[i]
5656
}
5757
}
5858
return nil

apis/apps/v1/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,11 @@ type ClusterComponentConfig struct {
502502
// +optional
503503
ExternalManaged *bool `json:"externalManaged,omitempty"`
504504

505+
// The versioned hash of the config content.
506+
//
507+
// +optional
508+
VersionHash string `json:"versionHash,omitempty"`
509+
505510
// The custom reconfigure action to reload the configuration whenever changes to this config are detected.
506511
//
507512
// The container executing this action has access to following variables:

apis/workloads/v1/instanceset_types.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,15 @@ type ConfigTemplate struct {
514514
// The name of the config.
515515
Name string `json:"name"`
516516

517-
// The generation of the config.
518-
Generation int64 `json:"generation"`
517+
// The generation of the config content.
518+
//
519+
// +optional
520+
Generation int64 `json:"generation,omitempty"`
521+
522+
// The versioned hash of the config content.
523+
//
524+
// +optional
525+
VersionHash string `json:"versionHash,omitempty"`
519526

520527
// The custom reconfigure action.
521528
//
@@ -566,8 +573,13 @@ type InstanceConfigStatus struct {
566573

567574
// The generation of the config.
568575
//
569-
// +kubebuilder:validation:Required
570-
Generation int64 `json:"generation"`
576+
// +optional
577+
Generation int64 `json:"generation,omitempty"`
578+
579+
// The hash of the config content.
580+
//
581+
// +optional
582+
VersionHash string `json:"versionHash,omitempty"`
571583
}
572584

573585
// InstanceTemplateStatus aggregates the status of replicas for each InstanceTemplate

config/crd/bases/apps.kubeblocks.io_clusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ spec:
739739
description: Variables are key-value pairs for dynamic
740740
configuration values that can be provided by the user.
741741
type: object
742+
versionHash:
743+
description: The versioned hash of the config content.
744+
type: string
742745
type: object
743746
type: array
744747
disableExporter:
@@ -11963,6 +11966,9 @@ spec:
1196311966
configuration values that can be provided by the
1196411967
user.
1196511968
type: object
11969+
versionHash:
11970+
description: The versioned hash of the config content.
11971+
type: string
1196611972
type: object
1196711973
type: array
1196811974
disableExporter:

config/crd/bases/apps.kubeblocks.io_components.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,9 @@ spec:
610610
description: Variables are key-value pairs for dynamic configuration
611611
values that can be provided by the user.
612612
type: object
613+
versionHash:
614+
description: The versioned hash of the config content.
615+
type: string
613616
type: object
614617
type: array
615618
disableExporter:

config/crd/bases/workloads.kubeblocks.io_instancesets.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ spec:
7070
items:
7171
properties:
7272
generation:
73-
description: The generation of the config.
73+
description: The generation of the config content.
7474
format: int64
7575
type: integer
7676
name:
@@ -519,8 +519,10 @@ spec:
519519

520520
An empty name indicates that the reconfigure action is the default one defined by lifecycle actions.
521521
type: string
522+
versionHash:
523+
description: The versioned hash of the config content.
524+
type: string
522525
required:
523-
- generation
524526
- name
525527
type: object
526528
type: array
@@ -11716,8 +11718,10 @@ spec:
1171611718
name:
1171711719
description: The name of the config.
1171811720
type: string
11721+
versionHash:
11722+
description: The hash of the config content.
11723+
type: string
1171911724
required:
11720-
- generation
1172111725
- name
1172211726
type: object
1172311727
type: array

controllers/parameters/config_reconcile_wrapper.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525

2626
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
2727
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
28+
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
29+
"github.com/apecloud/kubeblocks/pkg/constant"
2830
"github.com/apecloud/kubeblocks/pkg/controller/component"
2931
"github.com/apecloud/kubeblocks/pkg/controller/render"
3032
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
@@ -39,6 +41,8 @@ type ReconcileContext struct {
3941
ConfigMap *corev1.ConfigMap
4042
BuiltinComponent *component.SynthesizedComponent
4143

44+
ITS *workloads.InstanceSet
45+
4246
ConfigRender *parametersv1alpha1.ParamConfigRenderer
4347
ParametersDefs map[string]*parametersv1alpha1.ParametersDefinition
4448
}
@@ -63,11 +67,23 @@ func (c *ReconcileContext) GetRelatedObjects() error {
6367
return c.Cluster().
6468
ComponentAndComponentDef().
6569
ComponentSpec().
70+
Workload().
6671
SynthesizedComponent().
6772
ParametersDefinitions().
6873
Complete()
6974
}
7075

76+
func (c *ReconcileContext) Workload() *ReconcileContext {
77+
return c.Wrap(func() error {
78+
itsKey := client.ObjectKey{
79+
Namespace: c.Namespace,
80+
Name: constant.GenerateWorkloadNamePattern(c.ClusterName, c.ComponentName),
81+
}
82+
c.ITS = &workloads.InstanceSet{}
83+
return c.Client.Get(c.Context, itsKey, c.ITS)
84+
})
85+
}
86+
7187
func (c *ReconcileContext) SynthesizedComponent() *ReconcileContext {
7288
return c.Wrap(func() (err error) {
7389
// build synthesized component for the component

controllers/parameters/policy_util.go

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
package parameters
2121

2222
import (
23-
"context"
2423
"fmt"
2524

2625
corev1 "k8s.io/api/core/v1"
@@ -74,11 +73,6 @@ func getPodsForOnlineUpdate(params reconfigureContext) ([]corev1.Pod, error) {
7473
return podList.Items, nil
7574
}
7675

77-
func commonOnlineUpdateWithPod(pod *corev1.Pod, ctx context.Context, configSpec string, configFile string, updatedParams map[string]string) error {
78-
// TODO: update cluster spec to call the reconfigure action
79-
return fmt.Errorf("not yet implemented")
80-
}
81-
8276
func getComponentSpecPtrByName(cli client.Client, ctx intctrlutil.RequestCtx, cluster *appsv1.Cluster, compName string) (*appsv1.ClusterComponentSpec, error) {
8377
for i := range cluster.Spec.ComponentSpecs {
8478
componentSpec := &cluster.Spec.ComponentSpecs[i]
@@ -147,7 +141,6 @@ func (r reconfigureTask) ExecReload() (returnedStatus, error) {
147141
if executor, ok := upgradePolicyMap[r.ReloadPolicy]; ok {
148142
return executor.Upgrade(r.taskCtx)
149143
}
150-
151144
return returnedStatus{}, fmt.Errorf("not support reload action[%s]", r.ReloadPolicy)
152145
}
153146

@@ -227,12 +220,13 @@ func buildReloadActionTask(reloadPolicy parametersv1alpha1.ReloadPolicy, templat
227220
RequestCtx: rctx.RequestCtx,
228221
Client: rctx.Client,
229222
ConfigTemplate: *templateSpec,
230-
ConfigMap: rctx.ConfigMap,
223+
VersionHash: computeTargetVersionHash(rctx.RequestCtx, rctx.ConfigMap.Data),
231224
ParametersDef: &pd.Spec,
232225
ConfigDescription: configDescription,
233226
Cluster: rctx.ClusterObj,
234227
ClusterComponent: rctx.ClusterComObj,
235228
SynthesizedComponent: rctx.BuiltinComponent,
229+
ITS: rctx.ITS,
236230
Patch: patch,
237231
},
238232
}
@@ -245,32 +239,11 @@ func buildRestartTask(configTemplate *appsv1.ComponentFileTemplate, rctx *Reconc
245239
RequestCtx: rctx.RequestCtx,
246240
Client: rctx.Client,
247241
ConfigTemplate: *configTemplate,
242+
VersionHash: computeTargetVersionHash(rctx.RequestCtx, rctx.ConfigMap.Data),
248243
ClusterComponent: rctx.ClusterComObj,
249244
Cluster: rctx.ClusterObj,
250245
SynthesizedComponent: rctx.BuiltinComponent,
251-
ConfigMap: rctx.ConfigMap,
246+
ITS: rctx.ITS,
252247
},
253248
}
254249
}
255-
256-
func generateOnlineUpdateParams(configPatch *core.ConfigPatchInfo, paramDef *parametersv1alpha1.ParametersDefinitionSpec, description parametersv1alpha1.ComponentConfigDescription) map[string]string {
257-
params := make(map[string]string)
258-
dynamicAction := parameters.NeedDynamicReloadAction(paramDef)
259-
needReloadStaticParams := parameters.ReloadStaticParameters(paramDef)
260-
visualizedParams := core.GenerateVisualizedParamsList(configPatch, []parametersv1alpha1.ComponentConfigDescription{description})
261-
262-
for _, key := range visualizedParams {
263-
if key.UpdateType != core.UpdatedType {
264-
continue
265-
}
266-
for _, p := range key.Parameters {
267-
if dynamicAction && !needReloadStaticParams && !core.IsDynamicParameter(p.Key, paramDef) {
268-
continue
269-
}
270-
if p.Value != nil {
271-
params[p.Key] = *p.Value
272-
}
273-
}
274-
}
275-
return params
276-
}

controllers/parameters/policy_util_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
appsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
3636
parametersv1alpha1 "github.com/apecloud/kubeblocks/apis/parameters/v1alpha1"
37+
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
3738
"github.com/apecloud/kubeblocks/pkg/controller/component"
3839
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
3940
"github.com/apecloud/kubeblocks/pkg/parameters/core"
@@ -63,12 +64,26 @@ func withClusterComponent(replicas int) paramsOps {
6364
}
6465
}
6566

66-
func withConfigSpec(configSpecName string, data map[string]string) paramsOps {
67+
func withClusterComponentNConfigs(replicas int, configs []appsv1.ClusterComponentConfig) paramsOps {
6768
return func(params *reconfigureContext) {
68-
params.ConfigMap = &corev1.ConfigMap{
69-
Data: data,
69+
params.ClusterComponent = &appsv1.ClusterComponentSpec{
70+
Name: "test",
71+
Replicas: func() int32 { rep := int32(replicas); return rep }(),
72+
Configs: configs,
7073
}
74+
}
75+
}
76+
77+
func withWorkload() paramsOps {
78+
return func(params *reconfigureContext) {
79+
params.ITS = &workloads.InstanceSet{}
80+
}
81+
}
82+
83+
func withConfigSpec(configSpecName string, data map[string]string) paramsOps {
84+
return func(params *reconfigureContext) {
7185
params.ConfigTemplate.Name = configSpecName
86+
params.VersionHash = computeTargetVersionHash(params.RequestCtx, data)
7287
}
7388
}
7489

controllers/parameters/reconfigure_controller.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"context"
2424
"encoding/json"
2525
"fmt"
26+
"reflect"
2627
"time"
2728

2829
"github.com/pkg/errors"
@@ -234,46 +235,64 @@ func (r *ReconfigureReconciler) updateConfigCMStatus(reqCtx intctrlutil.RequestC
234235
}
235236

236237
func (r *ReconfigureReconciler) performUpgrade(rctx *ReconcileContext, reloadTasks []ReloadAction) (ctrl.Result, error) {
237-
var err error
238-
var returnedStatus returnedStatus
239-
var reloadType string
240-
238+
var (
239+
err error
240+
status returnedStatus
241+
reloadType string
242+
)
241243
for _, task := range reloadTasks {
242244
reloadType = task.ReloadType()
243-
returnedStatus, err = task.ExecReload()
244-
if err != nil || returnedStatus.Status != ESNone {
245-
return r.status(rctx, returnedStatus, reloadType, err)
245+
status, err = task.ExecReload()
246+
if err != nil || status.Status != ESNone {
247+
break
246248
}
247249
}
248-
return r.succeed(rctx, reloadType, returnedStatus)
250+
// submit changes to the cluster
251+
if err1 := r.submit(rctx); err1 != nil {
252+
return intctrlutil.RequeueAfter(configReconcileInterval, rctx.Log, "failed to submit changes to the cluster", "error", err1)
253+
}
254+
if err != nil || status.Status != ESNone {
255+
return r.status(rctx, reloadType, status, err)
256+
}
257+
return r.succeed(rctx, reloadType, status)
258+
}
259+
260+
func (r *ReconfigureReconciler) submit(rctx *ReconcileContext) error {
261+
if rctx.ClusterObj == nil || rctx.ClusterObjCopy == nil {
262+
return fmt.Errorf("the cluster object is nil")
263+
}
264+
if reflect.DeepEqual(rctx.ClusterObj.Spec, rctx.ClusterObjCopy.Spec) {
265+
return nil
266+
}
267+
return rctx.Client.Update(rctx.RequestCtx.Ctx, rctx.ClusterObj)
249268
}
250269

251-
func (r *ReconfigureReconciler) status(rctx *ReconcileContext, returnedStatus returnedStatus, policy string, err error) (ctrl.Result, error) {
270+
func (r *ReconfigureReconciler) status(rctx *ReconcileContext, reloadType string, status returnedStatus, err error) (ctrl.Result, error) {
252271
updatePhase := func(phase parametersv1alpha1.ParameterPhase, options ...options) (ctrl.Result, error) {
253-
return updateConfigPhaseWithResult(rctx.Client, rctx.RequestCtx, rctx.ConfigMap, reconciled(returnedStatus, policy, phase, options...))
272+
return updateConfigPhaseWithResult(rctx.Client, rctx.RequestCtx, rctx.ConfigMap, reconciled(status, reloadType, phase, options...))
254273
}
255274

256-
switch returnedStatus.Status {
275+
switch status.Status {
257276
case ESFailedAndRetry:
258277
return updatePhase(parametersv1alpha1.CFailedPhase, withFailed(err, true))
259278
case ESRetry:
260279
return updatePhase(parametersv1alpha1.CUpgradingPhase)
261280
case ESFailed:
262281
return updatePhase(parametersv1alpha1.CFailedAndPausePhase, withFailed(err, false))
263282
case ESNone:
264-
return r.succeed(rctx, policy, returnedStatus)
283+
return r.succeed(rctx, reloadType, status)
265284
default:
266285
return updatePhase(parametersv1alpha1.CFailedAndPausePhase, withFailed(cfgcore.MakeError("unknown status"), false))
267286
}
268287
}
269288

270-
func (r *ReconfigureReconciler) succeed(rctx *ReconcileContext, reloadType string, returnedStatus returnedStatus) (ctrl.Result, error) {
289+
func (r *ReconfigureReconciler) succeed(rctx *ReconcileContext, reloadType string, status returnedStatus) (ctrl.Result, error) {
271290
rctx.Recorder.Eventf(rctx.ConfigMap,
272291
corev1.EventTypeNormal,
273292
appsv1alpha1.ReasonReconfigureSucceed,
274293
"the reconfigure[%s] has been processed successfully",
275294
reloadType)
276295

277-
result := reconciled(returnedStatus, reloadType, parametersv1alpha1.CFinishedPhase)
296+
result := reconciled(status, reloadType, parametersv1alpha1.CFinishedPhase)
278297
return r.updateConfigCMStatus(rctx.RequestCtx, rctx.ConfigMap, reloadType, &result)
279298
}

0 commit comments

Comments
 (0)