Skip to content

Commit c859585

Browse files
committed
init
1 parent 0fa7766 commit c859585

7 files changed

Lines changed: 63 additions & 39 deletions

File tree

apis/apps/v1/types.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,10 @@ type ProvisionSecretRef struct {
500500

501501
// The namespace where the secret is located.
502502
//
503-
// +kubebuilder:validation:Required
504-
Namespace string `json:"namespace"`
503+
// If not specified, the secret is assumed to be in the same namespace as the cluster.
504+
//
505+
// +optional
506+
Namespace string `json:"namespace,omitempty"`
505507

506508
// The key in the secret data that contains the password.
507509
//

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,7 +4451,11 @@ spec:
44514451
description: The unique identifier of the secret.
44524452
type: string
44534453
namespace:
4454-
description: The namespace where the secret is located.
4454+
description: |-
4455+
The namespace where the secret is located.
4456+
4457+
4458+
If not specified, the secret is assumed to be in the same namespace as the cluster.
44554459
type: string
44564460
password:
44574461
default: password
@@ -4460,7 +4464,6 @@ spec:
44604464
type: string
44614465
required:
44624466
- name
4463-
- namespace
44644467
type: object
44654468
required:
44664469
- name
@@ -15807,8 +15810,11 @@ spec:
1580715810
description: The unique identifier of the secret.
1580815811
type: string
1580915812
namespace:
15810-
description: The namespace where the secret is
15811-
located.
15813+
description: |-
15814+
The namespace where the secret is located.
15815+
15816+
15817+
If not specified, the secret is assumed to be in the same namespace as the cluster.
1581215818
type: string
1581315819
password:
1581415820
default: password
@@ -15817,7 +15823,6 @@ spec:
1581715823
type: string
1581815824
required:
1581915825
- name
15820-
- namespace
1582115826
type: object
1582215827
required:
1582315828
- name

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,7 +4649,11 @@ spec:
46494649
description: The unique identifier of the secret.
46504650
type: string
46514651
namespace:
4652-
description: The namespace where the secret is located.
4652+
description: |-
4653+
The namespace where the secret is located.
4654+
4655+
4656+
If not specified, the secret is assumed to be in the same namespace as the cluster.
46534657
type: string
46544658
password:
46554659
default: password
@@ -4658,7 +4662,6 @@ spec:
46584662
type: string
46594663
required:
46604664
- name
4661-
- namespace
46624665
type: object
46634666
required:
46644667
- name

controllers/apps/component/transformer_component_account.go

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (t *componentAccountTransformer) Transform(ctx graph.TransformContext, dag
119119

120120
func (t *componentAccountTransformer) createAccount(transCtx *componentTransformContext,
121121
dag *graph.DAG, graphCli model.GraphClient, account synthesizedSystemAccount) error {
122-
secret, err := t.buildAccountSecret(transCtx, transCtx.SynthesizeComponent, account)
122+
secret, err := t.buildAccountSecret(transCtx, account)
123123
if err != nil {
124124
return err
125125
}
@@ -137,7 +137,7 @@ func (t *componentAccountTransformer) deleteAccount(transCtx *componentTransform
137137

138138
func (t *componentAccountTransformer) updateAccount(transCtx *componentTransformContext,
139139
dag *graph.DAG, graphCli model.GraphClient, account synthesizedSystemAccount, running *corev1.Secret) error {
140-
secret, err := t.buildAccountSecret(transCtx, transCtx.SynthesizeComponent, account)
140+
secret, err := t.buildAccountSecret(transCtx, account)
141141
if err != nil {
142142
return err
143143
}
@@ -175,34 +175,36 @@ func (t *componentAccountTransformer) buildAccountHash(account synthesizedSystem
175175
return signatureSystemAccountPassword(secret)
176176
}
177177

178-
func (t *componentAccountTransformer) buildAccountSecret(ctx *componentTransformContext,
179-
synthesizeComp *component.SynthesizedComponent, account synthesizedSystemAccount) (*corev1.Secret, error) {
178+
func (t *componentAccountTransformer) buildAccountSecret(transCtx *componentTransformContext, account synthesizedSystemAccount) (*corev1.Secret, error) {
180179
var password []byte
181180
var err error
182181
switch {
183182
case account.SecretRef != nil:
184-
if password, err = t.getPasswordFromSecret(ctx, account); err != nil {
183+
if password, err = t.getPasswordFromSecret(transCtx, account); err != nil {
185184
return nil, err
186185
}
187186
default:
188-
password, err = t.buildPassword(ctx, account)
187+
password, err = t.buildPassword(transCtx, account)
189188
if err != nil {
190189
return nil, err
191190
}
192191
}
193192
if len(password) > maximumPasswordLength {
194193
return nil, errPasswordTooLong
195194
}
196-
return t.buildAccountSecretWithPassword(ctx, synthesizeComp, account, password)
195+
return t.buildAccountSecretWithPassword(transCtx, account, password)
197196
}
198197

199-
func (t *componentAccountTransformer) getPasswordFromSecret(ctx graph.TransformContext, account synthesizedSystemAccount) ([]byte, error) {
198+
func (t *componentAccountTransformer) getPasswordFromSecret(transCtx *componentTransformContext, account synthesizedSystemAccount) ([]byte, error) {
200199
secretKey := types.NamespacedName{
201200
Namespace: account.SecretRef.Namespace,
202201
Name: account.SecretRef.Name,
203202
}
203+
if len(secretKey.Namespace) == 0 {
204+
secretKey.Namespace = transCtx.SynthesizeComponent.Namespace
205+
}
204206
secret := &corev1.Secret{}
205-
if err := ctx.GetClient().Get(ctx.GetContext(), secretKey, secret); err != nil {
207+
if err := transCtx.GetClient().Get(transCtx.GetContext(), secretKey, secret); err != nil {
206208
return nil, err
207209
}
208210

@@ -216,17 +218,18 @@ func (t *componentAccountTransformer) getPasswordFromSecret(ctx graph.TransformC
216218
return secret.Data[passwordKey], nil
217219
}
218220

219-
func (t *componentAccountTransformer) buildPassword(ctx *componentTransformContext, account synthesizedSystemAccount) ([]byte, error) {
221+
func (t *componentAccountTransformer) buildPassword(transCtx *componentTransformContext, account synthesizedSystemAccount) ([]byte, error) {
222+
synthesizedComp := transCtx.SynthesizeComponent
220223
// get restore password if exists during recovery.
221-
password, err := appsutil.GetRestoreSystemAccountPassword(ctx.Context, ctx.Client,
222-
ctx.SynthesizeComponent.Annotations, ctx.SynthesizeComponent.Name, account.Name)
224+
password, err := appsutil.GetRestoreSystemAccountPassword(transCtx.Context, transCtx.Client,
225+
synthesizedComp.Annotations, synthesizedComp.Name, account.Name)
223226
if err != nil {
224-
return nil, fmt.Errorf("failed to restore password for system account %s of component %s from annotation, err: %w", account.Name, ctx.SynthesizeComponent.Name, err)
227+
return nil, fmt.Errorf("failed to restore password for system account %s of component %s from annotation, err: %w", account.Name, synthesizedComp.Name, err)
225228
}
226229
if account.InitAccount && len(password) == 0 {
227-
// initAccount can also restore from factory.GetRestoreSystemAccountPassword(ctx.SynthesizeComponent, account).
230+
// initAccount can also restore from factory.GetRestoreSystemAccountPassword(synthesizedComp, account).
228231
// This is compatibility processing.
229-
password = []byte(factory.GetRestorePassword(ctx.SynthesizeComponent))
232+
password = []byte(factory.GetRestorePassword(synthesizedComp))
230233
}
231234
if len(password) == 0 {
232235
password, err := common.GeneratePasswordByConfig(account.PasswordGenerationPolicy)
@@ -236,16 +239,17 @@ func (t *componentAccountTransformer) buildPassword(ctx *componentTransformConte
236239
}
237240

238241
func (t *componentAccountTransformer) buildAccountSecretWithPassword(ctx *componentTransformContext,
239-
synthesizeComp *component.SynthesizedComponent, account synthesizedSystemAccount, password []byte) (*corev1.Secret, error) {
240-
secretName := constant.GenerateAccountSecretName(synthesizeComp.ClusterName, synthesizeComp.Name, account.Name)
241-
secret := builder.NewSecretBuilder(synthesizeComp.Namespace, secretName).
242+
account synthesizedSystemAccount, password []byte) (*corev1.Secret, error) {
243+
synthesizedComp := ctx.SynthesizeComponent
244+
secretName := constant.GenerateAccountSecretName(synthesizedComp.ClusterName, synthesizedComp.Name, account.Name)
245+
secret := builder.NewSecretBuilder(synthesizedComp.Namespace, secretName).
242246
// Priority: static < dynamic < built-in
243-
AddLabelsInMap(synthesizeComp.StaticLabels).
244-
AddLabelsInMap(synthesizeComp.DynamicLabels).
245-
AddLabelsInMap(constant.GetCompLabels(synthesizeComp.ClusterName, synthesizeComp.Name)).
247+
AddLabelsInMap(synthesizedComp.StaticLabels).
248+
AddLabelsInMap(synthesizedComp.DynamicLabels).
249+
AddLabelsInMap(constant.GetCompLabels(synthesizedComp.ClusterName, synthesizedComp.Name)).
246250
AddLabels(systemAccountLabel, account.Name).
247-
AddAnnotationsInMap(synthesizeComp.StaticAnnotations).
248-
AddAnnotationsInMap(synthesizeComp.DynamicAnnotations).
251+
AddAnnotationsInMap(synthesizedComp.StaticAnnotations).
252+
AddAnnotationsInMap(synthesizedComp.DynamicAnnotations).
249253
PutData(constant.AccountNameForSecret, []byte(account.Name)).
250254
PutData(constant.AccountPasswdForSecret, password).
251255
// SetImmutable(true).

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4451,7 +4451,11 @@ spec:
44514451
description: The unique identifier of the secret.
44524452
type: string
44534453
namespace:
4454-
description: The namespace where the secret is located.
4454+
description: |-
4455+
The namespace where the secret is located.
4456+
4457+
4458+
If not specified, the secret is assumed to be in the same namespace as the cluster.
44554459
type: string
44564460
password:
44574461
default: password
@@ -4460,7 +4464,6 @@ spec:
44604464
type: string
44614465
required:
44624466
- name
4463-
- namespace
44644467
type: object
44654468
required:
44664469
- name
@@ -15807,8 +15810,11 @@ spec:
1580715810
description: The unique identifier of the secret.
1580815811
type: string
1580915812
namespace:
15810-
description: The namespace where the secret is
15811-
located.
15813+
description: |-
15814+
The namespace where the secret is located.
15815+
15816+
15817+
If not specified, the secret is assumed to be in the same namespace as the cluster.
1581215818
type: string
1581315819
password:
1581415820
default: password
@@ -15817,7 +15823,6 @@ spec:
1581715823
type: string
1581815824
required:
1581915825
- name
15820-
- namespace
1582115826
type: object
1582215827
required:
1582315828
- name

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,7 +4649,11 @@ spec:
46494649
description: The unique identifier of the secret.
46504650
type: string
46514651
namespace:
4652-
description: The namespace where the secret is located.
4652+
description: |-
4653+
The namespace where the secret is located.
4654+
4655+
4656+
If not specified, the secret is assumed to be in the same namespace as the cluster.
46534657
type: string
46544658
password:
46554659
default: password
@@ -4658,7 +4662,6 @@ spec:
46584662
type: string
46594663
required:
46604664
- name
4661-
- namespace
46624665
type: object
46634666
required:
46644667
- name

docs/developer_docs/api-reference/cluster.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9892,7 +9892,9 @@ string
98929892
</em>
98939893
</td>
98949894
<td>
9895+
<em>(Optional)</em>
98959896
<p>The namespace where the secret is located.</p>
9897+
<p>If not specified, the secret is assumed to be in the same namespace as the cluster.</p>
98969898
</td>
98979899
</tr>
98989900
<tr>

0 commit comments

Comments
 (0)