Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not trigger non-existing plan #1616

Merged
merged 1 commit into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pkg/webhook/instance_admission.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ func admitUpdate(old, new *kudov1beta1.Instance, ov, oldOv *kudov1beta1.Operator
isDeleting := new.IsDeleting() // a non-empty meta.deletionTimestamp is a signal to switch to the uninstalling life-cycle phase
isPlanTerminal := new.Spec.PlanExecution.Status.IsTerminal()

// validate plan first
if newPlan != "" && kudov1beta1.SelectPlan([]string{newPlan}, ov) == nil {
return nil, fmt.Errorf("plan %s does not exist", newPlan)
}

changedDefs, removedDefs, err := changedParameters(old.Spec.Parameters, new.Spec.Parameters, ov)
if err != nil {
return nil, fmt.Errorf("failed to update Instance %s/%s: %v", old.Namespace, old.Name, err)
Expand Down
13 changes: 13 additions & 0 deletions pkg/webhook/instance_admission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,19 @@ func TestValidateUpdate(t *testing.T) {
}(),
want: &update,
},
{
name: "plan does not exist",
old: idle,
new: func() *v1beta1.Instance {
i := idle.DeepCopy()
i.Spec.PlanExecution = v1beta1.PlanExecution{PlanName: "nonexistingplan"}
return i
}(),
oldOv: ov,
ov: ov,
want: nil,
wantErr: true,
},
}

for _, tt := range tests {
Expand Down