Skip to content

Commit 453583e

Browse files
committed
UPSTREAM: <carry>: Add host assignment plugin for CRD-based routes.
1 parent 0a6c1cb commit 453583e

File tree

16 files changed

+819
-0
lines changed

16 files changed

+819
-0
lines changed

openshift-kube-apiserver/admission/admissionenablement/register.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ import (
1818
"k8s.io/kubernetes/openshift-kube-apiserver/admission/network/externalipranger"
1919
"k8s.io/kubernetes/openshift-kube-apiserver/admission/network/restrictedendpoints"
2020
ingressadmission "k8s.io/kubernetes/openshift-kube-apiserver/admission/route"
21+
"k8s.io/kubernetes/openshift-kube-apiserver/admission/route/hostassignment"
2122
projectnodeenv "k8s.io/kubernetes/openshift-kube-apiserver/admission/scheduler/nodeenv"
2223
schedulerpodnodeconstraints "k8s.io/kubernetes/openshift-kube-apiserver/admission/scheduler/podnodeconstraints"
2324
)
2425

2526
func RegisterOpenshiftKubeAdmissionPlugins(plugins *admission.Plugins) {
2627
authorizationrestrictusers.Register(plugins)
28+
hostassignment.Register(plugins)
2729
imagepolicy.Register(plugins)
2830
ingressadmission.Register(plugins)
2931
managementcpusoverride.Register(plugins)
@@ -65,6 +67,7 @@ var (
6567
"security.openshift.io/SecurityContextConstraint",
6668
"security.openshift.io/SCCExecRestrictions",
6769
"route.openshift.io/IngressAdmission",
70+
hostassignment.PluginName, // "route.openshift.io/RouteHostAssignment"
6871
}
6972

7073
// openshiftAdmissionPluginsForKubeAfterResourceQuota are the plugins to add after ResourceQuota plugin
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// +k8s:deepcopy-gen=package,register
2+
3+
// Package hostassignment is the internal version of the API.
4+
package hostassignment
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package hostassignment
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
// SchemeGroupVersion is group version used to register these objects
9+
var GroupVersion = schema.GroupVersion{Group: "route.openshift.io", Version: runtime.APIVersionInternal}
10+
11+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
12+
func Kind(kind string) schema.GroupKind {
13+
return GroupVersion.WithKind(kind).GroupKind()
14+
}
15+
16+
// Resource takes an unqualified resource and returns back a Group qualified GroupResource
17+
func Resource(resource string) schema.GroupResource {
18+
return GroupVersion.WithResource(resource).GroupResource()
19+
}
20+
21+
var (
22+
schemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
23+
Install = schemeBuilder.AddToScheme
24+
)
25+
26+
func addKnownTypes(scheme *runtime.Scheme) error {
27+
scheme.AddKnownTypes(GroupVersion,
28+
&HostAssignmentAdmissionConfig{},
29+
)
30+
return nil
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package hostassignment
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
8+
9+
// HostAssignmentAdmissionConfig is the configuration for the the route host assignment plugin.
10+
type HostAssignmentAdmissionConfig struct {
11+
metav1.TypeMeta
12+
13+
// domain is used to generate a default host name for a route when the
14+
// route's host name is empty. The generated host name will follow this
15+
// pattern: "<route-name>.<route-namespace>.<domain>".
16+
Domain string
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// +k8s:deepcopy-gen=package,register
2+
// +k8s:conversion-gen=k8s.io/kubernetes/openshift-kube-apiserver/admission/route/apis/hostassignment
3+
4+
// Package v1 is the v1 version of the API.
5+
package v1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Copyright The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1
18+
19+
import (
20+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
)
24+
25+
// GroupName specifies the group name used to register the objects.
26+
const GroupName = "route.openshift.io"
27+
28+
// GroupVersion specifies the group and the version used to register the objects.
29+
var GroupVersion = v1.GroupVersion{Group: GroupName, Version: "v1"}
30+
31+
// SchemeGroupVersion is group version used to register these objects
32+
// Deprecated: use GroupVersion instead.
33+
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
34+
35+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
36+
func Resource(resource string) schema.GroupResource {
37+
return SchemeGroupVersion.WithResource(resource).GroupResource()
38+
}
39+
40+
var (
41+
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
42+
SchemeBuilder runtime.SchemeBuilder
43+
localSchemeBuilder = &SchemeBuilder
44+
// Depreciated: use Install instead
45+
AddToScheme = localSchemeBuilder.AddToScheme
46+
Install = localSchemeBuilder.AddToScheme
47+
)
48+
49+
func init() {
50+
// We only register manually written functions here. The registration of the
51+
// generated functions takes place in the generated files. The separation
52+
// makes the code compile even when the generated files are missing.
53+
localSchemeBuilder.Register(addKnownTypes)
54+
}
55+
56+
// Adds the list of known types to Scheme.
57+
func addKnownTypes(scheme *runtime.Scheme) error {
58+
scheme.AddKnownTypes(SchemeGroupVersion,
59+
&HostAssignmentAdmissionConfig{},
60+
)
61+
// AddToGroupVersion allows the serialization of client types like ListOptions.
62+
v1.AddToGroupVersion(scheme, SchemeGroupVersion)
63+
return nil
64+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package v1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
8+
9+
// HostAssignmentAdmissionConfig is the configuration for the the route host assignment plugin.
10+
type HostAssignmentAdmissionConfig struct {
11+
metav1.TypeMeta `json:",inline"`
12+
13+
// domain is used to generate a default host name for a route when the
14+
// route's host name is empty. The generated host name will follow this
15+
// pattern: "<route-name>.<route-namespace>.<domain>".
16+
Domain string `json:"domain"`
17+
}

openshift-kube-apiserver/admission/route/apis/hostassignment/v1/zz_generated.conversion.go

+68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openshift-kube-apiserver/admission/route/apis/hostassignment/v1/zz_generated.deepcopy.go

+51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

openshift-kube-apiserver/admission/route/apis/hostassignment/zz_generated.deepcopy.go

+51
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)