Skip to content

Commit

Permalink
chore: forbidden vars value and valueFrom are specified (apecloud#8635)
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Rookie authored Dec 18, 2024
1 parent ed1d303 commit 96249df
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/apps/componentdefinition_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func (r *ComponentDefinitionReconciler) validateVars(cli client.Client, rctx int
// validate the reference to component definition name pattern
var compDef string
for _, cVar := range cmpd.Spec.Vars {
if len(cVar.Value) > 0 && cVar.ValueFrom != nil {
return fmt.Errorf("both value and valueFrom are specified for component var: %s", cVar.Name)
}
if cVar.ValueFrom == nil {
continue
}
Expand Down
20 changes: 20 additions & 0 deletions controllers/apps/componentdefinition_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,26 @@ var _ = Describe("ComponentDefinition Controller", func() {
checkObjectStatus(componentDefObj, kbappsv1.AvailablePhase)
})

It("both value and valueFrom are specified", func() {
By("create a ComponentDefinition obj")
componentDefObj := testapps.NewComponentDefinitionFactory(componentDefName).
SetRuntime(nil).
AddVar(kbappsv1.EnvVar{
Name: "VAR1",
Value: "value1",
ValueFrom: &kbappsv1.VarSource{
SecretKeyRef: &corev1.SecretKeySelector{
LocalObjectReference: corev1.LocalObjectReference{
Name: "secret",
},
Key: "secret-key",
},
},
}).
Create(&testCtx).GetObject()
checkObjectStatus(componentDefObj, kbappsv1.UnavailablePhase)
})

It("duplicate vars name", func() {
By("create a ComponentDefinition obj")
componentDefObj := testapps.NewComponentDefinitionFactory(componentDefName).
Expand Down

0 comments on commit 96249df

Please sign in to comment.