Skip to content

Commit f80a9d0

Browse files
committed
restart through the config API
1 parent c3c3c55 commit f80a9d0

File tree

9 files changed

+59
-30
lines changed

9 files changed

+59
-30
lines changed

apis/apps/v1/types.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ type ClusterComponentConfig struct {
539539
// +optional
540540
VersionHash string `json:"versionHash,omitempty"`
541541

542-
// The custom reconfigure action to reload the configuration whenever changes to this config are detected.
542+
// The custom reconfigure action to reload the updated configuration.
543543
//
544544
// The container executing this action has access to following variables:
545545
//
@@ -550,21 +550,10 @@ type ClusterComponentConfig struct {
550550
// +optional
551551
Reconfigure *Action `json:"reconfigure,omitempty"`
552552

553-
// The custom reconfigure actions to reload the configuration whenever changes to this config are detected.
554-
// It is applicable to the scenario where there are more than one files in the configuration,
555-
// and they have different reload actions.
556-
//
557-
// Each key in the map represents a file name, and the corresponding value is the action to reload the
558-
// configuration for that file. It takes precedence over the default @reconfigure action if set.
559-
//
560-
// The container executing each action has access to following variables:
561-
//
562-
// - KB_CONFIG_FILES_CREATED: file
563-
// - KB_CONFIG_FILES_REMOVED: file
564-
// - KB_CONFIG_FILES_UPDATED: checksum
553+
// Specifies whether to restart the component to reload the updated configuration.
565554
//
566555
// +optional
567-
// Reconfigures *map[string]Action `json:"reconfigures,omitempty"`
556+
RestartOnChange *bool `json:"restartOnChange,omitempty"`
568557
}
569558

570559
// ClusterComponentConfigSource represents the source of a configuration for a component.

apis/apps/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ spec:
291291
type: string
292292
reconfigure:
293293
description: |-
294-
The custom reconfigure action to reload the configuration whenever changes to this config are detected.
294+
The custom reconfigure action to reload the updated configuration.
295295

296296

297297
The container executing this action has access to following variables:
@@ -733,6 +733,10 @@ spec:
733733
format: int32
734734
type: integer
735735
type: object
736+
restartOnChange:
737+
description: Specifies whether to restart the component
738+
to reload the updated configuration.
739+
type: boolean
736740
variables:
737741
additionalProperties:
738742
type: string
@@ -11547,7 +11551,7 @@ spec:
1154711551
type: string
1154811552
reconfigure:
1154911553
description: |-
11550-
The custom reconfigure action to reload the configuration whenever changes to this config are detected.
11554+
The custom reconfigure action to reload the updated configuration.
1155111555

1155211556

1155311557
The container executing this action has access to following variables:
@@ -11993,6 +11997,10 @@ spec:
1199311997
format: int32
1199411998
type: integer
1199511999
type: object
12000+
restartOnChange:
12001+
description: Specifies whether to restart the component
12002+
to reload the updated configuration.
12003+
type: boolean
1199612004
variables:
1199712005
additionalProperties:
1199812006
type: string

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ spec:
166166
type: string
167167
reconfigure:
168168
description: |-
169-
The custom reconfigure action to reload the configuration whenever changes to this config are detected.
169+
The custom reconfigure action to reload the updated configuration.
170170

171171

172172
The container executing this action has access to following variables:
@@ -604,6 +604,10 @@ spec:
604604
format: int32
605605
type: integer
606606
type: object
607+
restartOnChange:
608+
description: Specifies whether to restart the component to reload
609+
the updated configuration.
610+
type: boolean
607611
variables:
608612
additionalProperties:
609613
type: string

controllers/parameters/restart_policy.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ var restartPolicyInstance = &restartPolicy{}
3434
type restartPolicy struct{}
3535

3636
func (s *restartPolicy) Upgrade(rctx reconfigureContext) (returnedStatus, error) {
37-
rctx.Log.V(1).Info("simple policy begin....")
38-
39-
s.restart(rctx)
40-
41-
return syncLatestConfigStatus(rctx), nil
37+
return syncUpdatedConfig(rctx, nil, true)
4238
}
4339

4440
func (s *restartPolicy) restart(rctx reconfigureContext) {

controllers/parameters/sync_policy.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (o *syncPolicy) Upgrade(rctx reconfigureContext) (returnedStatus, error) {
4545
if len(updateParams) == 0 {
4646
return makeReturnedStatus(ESNone), nil
4747
}
48-
return o.sync(rctx, updateParams)
48+
return syncUpdatedConfig(rctx, updateParams, false)
4949
}
5050

5151
func (o *syncPolicy) updateParameters(rctx reconfigureContext) map[string]string {
@@ -73,7 +73,7 @@ func (o *syncPolicy) updateParameters(rctx reconfigureContext) map[string]string
7373
return params
7474
}
7575

76-
func (o *syncPolicy) sync(rctx reconfigureContext, parameters map[string]string) (returnedStatus, error) {
76+
func syncUpdatedConfig(rctx reconfigureContext, parameters map[string]string, restart bool) (returnedStatus, error) {
7777
var config *apisappsv1.ClusterComponentConfig
7878
for i, cfg := range rctx.ClusterComponent.Configs {
7979
if ptr.Deref(cfg.Name, "") == rctx.ConfigTemplate.Name {
@@ -85,12 +85,12 @@ func (o *syncPolicy) sync(rctx reconfigureContext, parameters map[string]string)
8585
return makeReturnedStatus(ESFailedAndRetry), fmt.Errorf("config %s not found", rctx.ConfigTemplate.Name)
8686
}
8787
if config.VersionHash != rctx.getTargetVersionHash() {
88-
return o.update(rctx, config, parameters), nil
88+
return submitUpdatedConfig(rctx, config, parameters, restart), nil
8989
}
9090
return syncLatestConfigStatus(rctx), nil
9191
}
9292

93-
func (o *syncPolicy) update(rctx reconfigureContext, config *apisappsv1.ClusterComponentConfig, parameters map[string]string) returnedStatus {
93+
func submitUpdatedConfig(rctx reconfigureContext, config *apisappsv1.ClusterComponentConfig, parameters map[string]string, restart bool) returnedStatus {
9494
var (
9595
replicas = rctx.getTargetReplicas()
9696
// fileName string
@@ -102,6 +102,9 @@ func (o *syncPolicy) update(rctx reconfigureContext, config *apisappsv1.ClusterC
102102
// TODO: config file?
103103
config.Variables = parameters // TODO: variables vs parameters?
104104
config.VersionHash = rctx.getTargetVersionHash()
105+
if restart {
106+
config.RestartOnChange = ptr.To(true)
107+
}
105108

106109
return makeReturnedStatus(ESRetry, withExpected(replicas), withSucceed(0))
107110
}

deploy/helm/crds/apps.kubeblocks.io_clusters.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ spec:
291291
type: string
292292
reconfigure:
293293
description: |-
294-
The custom reconfigure action to reload the configuration whenever changes to this config are detected.
294+
The custom reconfigure action to reload the updated configuration.
295295

296296

297297
The container executing this action has access to following variables:
@@ -733,6 +733,10 @@ spec:
733733
format: int32
734734
type: integer
735735
type: object
736+
restartOnChange:
737+
description: Specifies whether to restart the component
738+
to reload the updated configuration.
739+
type: boolean
736740
variables:
737741
additionalProperties:
738742
type: string
@@ -11547,7 +11551,7 @@ spec:
1154711551
type: string
1154811552
reconfigure:
1154911553
description: |-
11550-
The custom reconfigure action to reload the configuration whenever changes to this config are detected.
11554+
The custom reconfigure action to reload the updated configuration.
1155111555

1155211556

1155311557
The container executing this action has access to following variables:
@@ -11993,6 +11997,10 @@ spec:
1199311997
format: int32
1199411998
type: integer
1199511999
type: object
12000+
restartOnChange:
12001+
description: Specifies whether to restart the component
12002+
to reload the updated configuration.
12003+
type: boolean
1199612004
variables:
1199712005
additionalProperties:
1199812006
type: string

deploy/helm/crds/apps.kubeblocks.io_components.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ spec:
166166
type: string
167167
reconfigure:
168168
description: |-
169-
The custom reconfigure action to reload the configuration whenever changes to this config are detected.
169+
The custom reconfigure action to reload the updated configuration.
170170

171171

172172
The container executing this action has access to following variables:
@@ -604,6 +604,10 @@ spec:
604604
format: int32
605605
type: integer
606606
type: object
607+
restartOnChange:
608+
description: Specifies whether to restart the component to reload
609+
the updated configuration.
610+
type: boolean
607611
variables:
608612
additionalProperties:
609613
type: string

docs/developer_docs/api-reference/cluster.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2844,7 +2844,7 @@ Action
28442844
</td>
28452845
<td>
28462846
<em>(Optional)</em>
2847-
<p>The custom reconfigure action to reload the configuration whenever changes to this config are detected.</p>
2847+
<p>The custom reconfigure action to reload the updated configuration.</p>
28482848
<p>The container executing this action has access to following variables:</p>
28492849
<ul>
28502850
<li>KB_CONFIG_FILES_CREATED: file1,file2&hellip;</li>
@@ -2853,6 +2853,18 @@ Action
28532853
</ul>
28542854
</td>
28552855
</tr>
2856+
<tr>
2857+
<td>
2858+
<code>restartOnChange</code><br/>
2859+
<em>
2860+
bool
2861+
</em>
2862+
</td>
2863+
<td>
2864+
<em>(Optional)</em>
2865+
<p>Specifies whether to restart the component to reload the updated configuration.</p>
2866+
</td>
2867+
</tr>
28562868
</tbody>
28572869
</table>
28582870
<h3 id="apps.kubeblocks.io/v1.ClusterComponentConfigSource">ClusterComponentConfigSource

0 commit comments

Comments
 (0)