forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#1416 from benluddy/routev1-admission
OCPBUGS-3499: UPSTREAM: <carry>: Add validation plugin for CRD-based route parity.
- Loading branch information
Showing
5 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
openshift-kube-apiserver/admission/customresourcevalidation/route/validate_route.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package route | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apimachinery/pkg/util/validation/field" | ||
"k8s.io/apiserver/pkg/admission" | ||
|
||
routev1 "github.com/openshift/api/route/v1" | ||
routevalidation "github.com/openshift/library-go/pkg/route/validation" | ||
"k8s.io/kubernetes/openshift-kube-apiserver/admission/customresourcevalidation" | ||
) | ||
|
||
const PluginName = "route.openshift.io/ValidateRoute" | ||
|
||
func Register(plugins *admission.Plugins) { | ||
plugins.Register(PluginName, func(config io.Reader) (admission.Interface, error) { | ||
return customresourcevalidation.NewValidator( | ||
map[schema.GroupResource]bool{ | ||
{Group: routev1.GroupName, Resource: "routes"}: true, | ||
}, | ||
map[schema.GroupVersionKind]customresourcevalidation.ObjectValidator{ | ||
routev1.GroupVersion.WithKind("Route"): routeV1{}, | ||
}) | ||
}) | ||
} | ||
|
||
func toRoute(uncastObj runtime.Object) (*routev1.Route, field.ErrorList) { | ||
if uncastObj == nil { | ||
return nil, nil | ||
} | ||
|
||
obj, ok := uncastObj.(*routev1.Route) | ||
if !ok { | ||
return nil, field.ErrorList{ | ||
field.NotSupported(field.NewPath("kind"), fmt.Sprintf("%T", uncastObj), []string{"Route"}), | ||
field.NotSupported(field.NewPath("apiVersion"), fmt.Sprintf("%T", uncastObj), []string{routev1.GroupVersion.String()}), | ||
} | ||
} | ||
|
||
return obj, nil | ||
} | ||
|
||
type routeV1 struct { | ||
} | ||
|
||
func (routeV1) ValidateCreate(obj runtime.Object) field.ErrorList { | ||
routeObj, errs := toRoute(obj) | ||
if len(errs) > 0 { | ||
return errs | ||
} | ||
|
||
return routevalidation.ValidateRoute(routeObj) | ||
} | ||
|
||
func (routeV1) ValidateUpdate(obj runtime.Object, oldObj runtime.Object) field.ErrorList { | ||
routeObj, errs := toRoute(obj) | ||
if len(errs) > 0 { | ||
return errs | ||
} | ||
|
||
routeOldObj, errs := toRoute(oldObj) | ||
if len(errs) > 0 { | ||
return errs | ||
} | ||
|
||
return routevalidation.ValidateRouteUpdate(routeObj, routeOldObj) | ||
} | ||
|
||
func (c routeV1) ValidateStatusUpdate(obj runtime.Object, oldObj runtime.Object) field.ErrorList { | ||
routeObj, errs := toRoute(obj) | ||
if len(errs) > 0 { | ||
return errs | ||
} | ||
|
||
routeOldObj, errs := toRoute(oldObj) | ||
if len(errs) > 0 { | ||
return errs | ||
} | ||
|
||
return routevalidation.ValidateRouteStatusUpdate(routeObj, routeOldObj) | ||
} |
Oops, something went wrong.