Skip to content

Commit

Permalink
Reject VS/VSR resources with enabled plus features for OSS
Browse files Browse the repository at this point in the history
  • Loading branch information
Vighneswar Rao Bojja authored and bvighnesha committed Sep 13, 2019
1 parent a560a15 commit 58c869c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/apis/configuration/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func validateUpstreams(upstreams []v1alpha1.Upstream, fieldPath *field.Path, isP
allErrs = append(allErrs, validateTime(u.SlowStart, idxPath.Child("slow-start"))...)
allErrs = append(allErrs, validateBuffer(u.ProxyBuffers, idxPath.Child("buffers"))...)
allErrs = append(allErrs, validateSize(u.ProxyBufferSize, idxPath.Child("buffer-size"))...)
allErrs = append(allErrs, rejectPlusResourcesInOSS(u, idxPath, isPlus)...)

for _, msg := range validation.IsValidPortNum(int(u.Port)) {
allErrs = append(allErrs, field.Invalid(idxPath.Child("port"), u.Port, msg))
Expand Down Expand Up @@ -796,3 +797,21 @@ func validateVirtualServerRouteSubroutes(routes []v1alpha1.Route, fieldPath *fie

return allErrs
}

func rejectPlusResourcesInOSS(upstream v1alpha1.Upstream, idxPath *field.Path, isPlus bool) field.ErrorList {
allErrs := field.ErrorList{}

if isPlus {
return allErrs
}

if upstream.HealthCheck != nil {
allErrs = append(allErrs, field.Forbidden(idxPath.Child("healthCheck"), "active health checks are only supported in NGINX Plus"))
}

if upstream.SlowStart != "" {
allErrs = append(allErrs, field.Forbidden(idxPath.Child("slow-start"), "slow start is only supported in NGINX Plus"))
}

return allErrs
}
19 changes: 19 additions & 0 deletions pkg/apis/configuration/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1992,3 +1992,22 @@ func TestValidateIntFromStringFails(t *testing.T) {
t.Errorf("validateIntFromString() returned no errors for invalid input %v", input)
}
}

func TestRejectPlusResourcesInOSS(t *testing.T) {
upstream := v1alpha1.Upstream{
SlowStart: "10s",
HealthCheck: &v1alpha1.HealthCheck{},
}

allErrsPlus := rejectPlusResourcesInOSS(upstream, field.NewPath("upstreams").Index(0), true)
allErrsOSS := rejectPlusResourcesInOSS(upstream, field.NewPath("upstreams").Index(0), false)

if len(allErrsPlus) != 0 {
t.Errorf("rejectPlusResourcesInOSS() returned errors %v for NGINX Plus for upstream %v", allErrsPlus, upstream)
}

if len(allErrsOSS) == 0 {
t.Errorf("rejectPlusResourcesInOSS() returned no errors for NGINX OSS for upstream %v", upstream)
}

}

0 comments on commit 58c869c

Please sign in to comment.