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

feat(operator): adapt TaskDefinition validation webhook to consider python and deno runtime #1534

23 changes: 18 additions & 5 deletions operator/apis/lifecycle/v1alpha3/keptntaskdefinition_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,33 @@ func (r *KeptnTaskDefinition) validateKeptnTaskDefinition() error {
allErrs)
}
func (r *KeptnTaskDefinition) validateFields() *field.Error {

if r.Spec.Function == nil && r.Spec.Container == nil {
if r.Spec.Function == nil && r.Spec.Container == nil && r.Spec.Python == nil && r.Spec.Deno == nil {
return field.Invalid(
field.NewPath("spec"),
r.Spec,
errors.New("Forbidden! Either Function or Container field must be defined").Error(),
errors.New("Forbidden! Either Function, Container, Python, or Deno field must be defined").Error(),
)
}

if r.Spec.Function != nil && r.Spec.Container != nil {
count := 0
geoffrey1330 marked this conversation as resolved.
Show resolved Hide resolved
if r.Spec.Function != nil {
geoffrey1330 marked this conversation as resolved.
Show resolved Hide resolved
count++
}
if r.Spec.Container != nil {
count++
}
if r.Spec.Python != nil {
count++
}
if r.Spec.Deno != nil {
count++
}

if count > 1 {
return field.Invalid(
field.NewPath("spec"),
r.Spec,
errors.New("Forbidden! Both Function and Container fields cannot be defined simultaneously").Error(),
errors.New("Forbidden! Only one of Function, Container, Python, or Deno field can be defined").Error(),
)
}

Expand Down