Skip to content

Commit

Permalink
fix: reconfigure painc when updating file (#5675) (#5679)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophon-zt authored Oct 30, 2023
1 parent d9d230f commit ba6766d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions controllers/apps/operations/reconfigure_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (p *pipeline) doMergeImpl(parameters appsv1alpha1.ConfigurationItem) error
}
filter := validate.WithKeySelector(configSpec.Keys)
for _, key := range parameters.Keys {
// patch parameters
if configSpec.ConfigConstraintRef != "" && filter(key.Key) {
if key.FileContent != "" {
return cfgcore.MakeError("not allowed to update file content: %s", key.Key)
Expand All @@ -145,10 +146,12 @@ func (p *pipeline) doMergeImpl(parameters appsv1alpha1.ConfigurationItem) error
})
continue
}
// update file content
if len(key.Parameters) != 0 {
return cfgcore.MakeError("not allowed to patch parameters: %s", key.Key)
}
updateFileContent(item, key.Key, key.FileContent)
p.isFileUpdated = true
}
p.updatedObject = newConfigObj
return p.createUpdatePatch(item, configSpec)
Expand Down
4 changes: 4 additions & 0 deletions controllers/apps/operations/reconfigure_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ mysqld.innodb_autoinc_lock_mode: conflicting values 2 and 100:
// r := updateConfigConfigmapResource(updatedCfg, tpl, client.ObjectKeyFromObject(cmObj), ctx, k8sMockClient.Client(), "test", mockUpdate)
r := testUpdateConfigConfigmapResource(reqCtx, k8sMockClient.Client(), opsRes, updatedCfg, clusterName, componentName)
Expect(r.err).Should(Succeed())
Expect(r.noFormatFilesUpdated).Should(BeFalse())
Expect(r.configPatch).ShouldNot(BeNil())
diff := r.configPatch
Expect(diff.IsModify).Should(BeTrue())
Expect(diff.UpdateConfig["my.cnf"]).Should(BeEquivalentTo(diffCfg))
Expand Down Expand Up @@ -265,6 +267,8 @@ z2=y2
// r := updateConfigConfigmapResource(updatedFiles, tpl, client.ObjectKeyFromObject(cmObj), ctx, k8sMockClient.Client(), "test", mockUpdate)
r := testUpdateConfigConfigmapResource(reqCtx, k8sMockClient.Client(), opsRes, updatedFiles, clusterName, componentName)
Expect(r.err).Should(Succeed())
Expect(r.configPatch).Should(BeNil())
Expect(r.noFormatFilesUpdated).Should(BeTrue())
}

By("normal file update without configSpec keys")
Expand Down
2 changes: 1 addition & 1 deletion controllers/apps/operations/reconfigure_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func makeReconfiguringResult(err error, ops ...func(*reconfiguringResult)) recon
}

func constructReconfiguringConditions(result reconfiguringResult, resource *OpsResource, configSpec *appsv1alpha1.ComponentConfigSpec) *metav1.Condition {
if result.noFormatFilesUpdated || result.configPatch.IsModify {
if result.noFormatFilesUpdated || (result.configPatch != nil && result.configPatch.IsModify) {
return appsv1alpha1.NewReconfigureRunningCondition(
resource.OpsRequest,
appsv1alpha1.ReasonReconfigurePersisted,
Expand Down
1 change: 1 addition & 0 deletions pkg/controllerutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func GetUncachedObjects() []client.Object {
&corev1.ConfigMap{},
&corev1.Secret{},
&appsv1alpha1.Cluster{},
&appsv1alpha1.Configuration{},
}
}

Expand Down

0 comments on commit ba6766d

Please sign in to comment.