forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPSTREAM: <carry>: Add RouteExternalCertificate validation in Route O…
…bjectValidator Co-authored-by: Thejas N <thn@redhat.com> Signed-off-by: Swarup Ghosh <swghosh@redhat.com>
- Loading branch information
1 parent
47d3e19
commit 2a676ab
Showing
4 changed files
with
149 additions
and
16 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
35 changes: 35 additions & 0 deletions
35
openshift-kube-apiserver/admission/customresourcevalidation/route/validation_opts.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,35 @@ | ||
package route | ||
|
||
import ( | ||
"k8s.io/apiserver/pkg/util/feature" | ||
"k8s.io/component-base/featuregate" | ||
|
||
configv1 "github.com/openshift/api/config/v1" | ||
routecommon "github.com/openshift/library-go/pkg/route" | ||
) | ||
|
||
type RouteValidationOptionGetter interface { | ||
GetValidationOptions() routecommon.RouteValidationOptions | ||
} | ||
|
||
type RouteValidationOpts struct { | ||
opts routecommon.RouteValidationOptions | ||
} | ||
|
||
var _ RouteValidationOptionGetter = &RouteValidationOpts{} | ||
|
||
func NewRouteValidationOpts() *RouteValidationOpts { | ||
return &RouteValidationOpts{} | ||
} | ||
|
||
func (o *RouteValidationOpts) GetValidationOptions() routecommon.RouteValidationOptions { | ||
return o.opts | ||
} | ||
|
||
func (o *RouteValidationOpts) Initialize() *RouteValidationOpts { | ||
o.opts = routecommon.RouteValidationOptions{ | ||
AllowExternalCertificates: feature.DefaultMutableFeatureGate.Enabled(featuregate.Feature(configv1.FeatureGateRouteExternalCertificate)), | ||
} | ||
|
||
return o | ||
} |
97 changes: 97 additions & 0 deletions
97
openshift-kube-apiserver/admission/customresourcevalidation/route/validation_wrapper.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,97 @@ | ||
package route | ||
|
||
import ( | ||
"fmt" | ||
|
||
routev1 "github.com/openshift/api/route/v1" | ||
"github.com/openshift/library-go/pkg/apiserver/admission/admissionrestconfig" | ||
authorizationv1client "k8s.io/client-go/kubernetes/typed/authorization/v1" | ||
corev1client "k8s.io/client-go/kubernetes/typed/core/v1" | ||
|
||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/apiserver/pkg/admission" | ||
"k8s.io/client-go/rest" | ||
"k8s.io/kubernetes/openshift-kube-apiserver/admission/customresourcevalidation" | ||
) | ||
|
||
type validateCustomResourceWithClient struct { | ||
admission.ValidationInterface | ||
|
||
secretsGetter corev1client.SecretsGetter | ||
sarGetter authorizationv1client.SubjectAccessReviewsGetter | ||
routeValidationOptsGetter RouteValidationOptionGetter | ||
} | ||
|
||
func NewValidateRoute() (admission.Interface, error) { | ||
ret := &validateCustomResourceWithClient{} | ||
|
||
delegate, err := customresourcevalidation.NewValidator( | ||
map[schema.GroupResource]bool{ | ||
routev1.GroupVersion.WithResource("routes").GroupResource(): true, | ||
}, | ||
map[schema.GroupVersionKind]customresourcevalidation.ObjectValidator{ | ||
routev1.GroupVersion.WithKind("Route"): routeV1{ | ||
secretsGetter: ret.getSecretsGetter(), | ||
sarGetter: ret.getSubjectAccessReviewsGetter(), | ||
routeValidationOptsGetter: ret.getRouteValidationOptions(), | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ret.ValidationInterface = delegate | ||
|
||
return ret, nil | ||
} | ||
|
||
var _ admissionrestconfig.WantsRESTClientConfig = &validateCustomResourceWithClient{} | ||
|
||
func (a *validateCustomResourceWithClient) getSecretsGetter() corev1client.SecretsGetter { | ||
return a.secretsGetter | ||
} | ||
|
||
func (a *validateCustomResourceWithClient) getSubjectAccessReviewsGetter() authorizationv1client.SubjectAccessReviewsGetter { | ||
return a.sarGetter | ||
} | ||
|
||
func (a *validateCustomResourceWithClient) getRouteValidationOptions() RouteValidationOptionGetter { | ||
return a.routeValidationOptsGetter | ||
} | ||
|
||
func (a *validateCustomResourceWithClient) SetRESTClientConfig(restClientConfig rest.Config) { | ||
var err error | ||
|
||
a.secretsGetter, err = corev1client.NewForConfig(&restClientConfig) | ||
if err != nil { | ||
utilruntime.HandleError(err) | ||
return | ||
} | ||
|
||
a.sarGetter, err = authorizationv1client.NewForConfig(&restClientConfig) | ||
if err != nil { | ||
utilruntime.HandleError(err) | ||
return | ||
} | ||
|
||
a.routeValidationOptsGetter = NewRouteValidationOpts().Initialize() | ||
} | ||
|
||
func (a *validateCustomResourceWithClient) ValidateInitialization() error { | ||
if a.secretsGetter == nil { | ||
return fmt.Errorf("%s needs a secretsGetter", PluginName) | ||
} | ||
if a.sarGetter == nil { | ||
return fmt.Errorf("%s needs a subjectAccessReviewsGetter", PluginName) | ||
} | ||
if a.routeValidationOptsGetter == nil { | ||
return fmt.Errorf("%s needs a routeValidationOptsGetter", PluginName) | ||
} | ||
|
||
initializationValidator, ok := a.ValidationInterface.(admission.InitializationValidator) | ||
if !ok { | ||
return fmt.Errorf("%s InitializationValidator type check for ValidationInterface failed", PluginName) | ||
} | ||
|
||
return initializationValidator.ValidateInitialization() | ||
} |
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