Skip to content

Commit 6f7cf96

Browse files
committed
feat: add ingress and ingressClass
1 parent b899f3f commit 6f7cf96

File tree

12 files changed

+989
-67
lines changed

12 files changed

+989
-67
lines changed

modules/network/ingress/ingress.k

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
schema Ingress:
2+
""" Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.
3+
An Ingress can be configured to give services externally-reachable urls, load balance traffic, terminate SSL,
4+
offer name based virtual hosting etc.
5+
6+
Attributes
7+
----------
8+
defaultBackend: IngressBackend, default is Undefined, optional.
9+
DefaultBackend is the backend that should handle requests that don't match any rule. If Rules are not specified,
10+
DefaultBackend must be specified. If DefaultBackend is not set, the handling of requests that do not match any
11+
of the rules will be up to the Ingress controller.
12+
ingressClassName: str, default is Undefined, optional.
13+
IngressClassName is the name of an IngressClass cluster resource. Ingress controller implementations use this
14+
field to know whether they should be serving this Ingress resource, by a transitive connection
15+
(controller -> IngressClass -> Ingress resource). Although the `kubernetes.io/ingress.class` annotation
16+
(simple constant name) was never formally defined, it was widely supported by Ingress controllers to create a
17+
direct binding between Ingress controller and Ingress resources. Newly created Ingress resources should prefer
18+
using the field. However, even though the annotation is officially deprecated, for backwards compatibility
19+
reasons, ingress controllers should still honor that annotation if present.
20+
rules: [IngressRule], default is Undefined, optional.
21+
Rules is a list of host rules used to configure the Ingress. If unspecified, or no rule matches, all traffic is
22+
sent to the default backend.
23+
tls: [IngressTLS], default is Undefined, optional.
24+
TLS represents the TLS configuration. Currently the Ingress only supports a single TLS port, 443. If multiple
25+
members of this list specify different hosts, they will be multiplexed on the same port according to the hostname
26+
specified through the SNI TLS extension, if the ingress controller fulfilling the ingress supports SNI.
27+
labels: {str:str}, default is Undefined, optional.
28+
Labels are key/value pairs that are attached to the workload.
29+
annotations: {str:str}, default is Undefined, optional.
30+
Annotations are key/value pairs that attach arbitrary non-identifying metadata to the workload.
31+
"""
32+
33+
# DefaultBackend is the backend that should handle requests that don't match any rule.
34+
defaultBackend?: IngressBackend
35+
36+
# IngressClassName is the name of an IngressClass cluster resource.
37+
ingressClassName?: str
38+
39+
# Rules is a list of host rules used to configure the Ingress.
40+
rules?: [IngressRule]
41+
42+
# TLS represents the TLS configuration.
43+
tls?: [IngressTLS]
44+
45+
# Labels and annotations can be used to attach arbitrary metadata as key-value pairs to resources.
46+
labels?: {str:str}
47+
annotations?: {str:str}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
schema IngressBackend:
2+
""" IngressBackend describes all endpoints for a given service and port.
3+
4+
Attributes
5+
----------
6+
resource: TypedLocalObjectReference, default is Undefined, optional.
7+
Resource is an ObjectRef to another Kubernetes resource in the namespace of the Ingress object. If resource is
8+
specified, a service.Name and service.Port must not be specified. This is a mutually exclusive setting with
9+
"Service".
10+
service: IngressServiceBackend, default is Undefined, optional.
11+
Service references a service as a backend. This is a mutually exclusive setting with "Resource".
12+
"""
13+
14+
# Resource is an ObjectRef to another Kubernetes resource in the namespace of the Ingress object.
15+
resource?: TypedLocalObjectReference
16+
17+
# Service references a service as a backend.
18+
service?: IngressServiceBackend
19+
20+
check:
21+
not resource or not service, "resource and number are mutually exclusive"
22+
23+
24+
schema IngressServiceBackend:
25+
""" IngressServiceBackend references a Kubernetes Service as a Backend.
26+
27+
Attributes
28+
----------
29+
name: str, default is Undefined, optional.
30+
Name is the referenced service. The service must exist in the same namespace as the Ingress object.
31+
If the name is not set, the generated public service name will be used.
32+
port: ServiceBackendPort, default is Undefined, optional.
33+
Port of the referenced service. A port name or port number is required for a IngressServiceBackend.
34+
"""
35+
36+
# Name is the referenced service. The service must exist in the same namespace as the Ingress object.
37+
# If the name is not set, the generated public service name will be used.
38+
name?: str
39+
40+
# Port of the referenced service. A port name or port number is required for a IngressServiceBackend.
41+
port?: ServiceBackendPort
42+
43+
44+
schema ServiceBackendPort:
45+
""" ServiceBackendPort is the service port being referenced. A port name or port number is required
46+
for a IngressServiceBackend.
47+
48+
Attributes
49+
----------
50+
name: str, default is Undefined, optional.
51+
Name is the name of the port on the Service. This is a mutually exclusive setting with "Number".
52+
number: int, default is Undefined, optional.
53+
Number is the numerical port number (e.g. 80) on the Service. This is a mutually exclusive setting with "Name".
54+
"""
55+
56+
# Name is the name of the port on the Service. This is a mutually exclusive setting with "Number".
57+
name?: str
58+
59+
# Number is the numerical port number (e.g. 80) on the Service. This is a mutually exclusive setting with "Name".
60+
number?: int
61+
62+
check:
63+
not name or not number, "name and number are mutually exclusive"
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
schema IngressClass:
2+
""" IngressClass represents the class of the Ingress, referenced by the Ingress Spec. The
3+
`ingressclass.kubernetes.io/is-default-class` annotation can be used to indicate that an IngressClass should be
4+
considered default. When a single IngressClass resource has this annotation set to true, new Ingress resources
5+
without a class specified will be assigned this default class.
6+
7+
Attributes
8+
----------
9+
controller: str, default is Undefined, optional.
10+
Controller refers to the name of the controller that should handle this class. This allows for different "flavors"
11+
that are controlled by the same controller. For example, you may have different parameters for the same implementing
12+
controller. This should be specified as a domain-prefixed path no more than 250 characters in length,
13+
e.g. "acme.io/ingress-controller". This field is immutable.
14+
parameters: IngressClassParametersReference, default is Undefined, optional.
15+
Parameters is a link to a custom resource containing additional configuration for the controller. This is optional
16+
if the controller does not require extra parameters.
17+
labels: {str:str}, default is Undefined, optional.
18+
Labels are key/value pairs that are attached to the workload.
19+
annotations: {str:str}, default is Undefined, optional.
20+
Annotations are key/value pairs that attach arbitrary non-identifying metadata to the workload.
21+
"""
22+
23+
# Controller refers to the name of the controller that should handle this class.
24+
controller?: str
25+
26+
# Parameters is a link to a custom resource containing additional configuration for the controller.
27+
parameters?: IngressClassParametersReference
28+
29+
# Labels and annotations can be used to attach arbitrary metadata as key-value pairs to resources.
30+
labels?: {str:str}
31+
annotations?: {str:str}
32+
33+
schema IngressClassParametersReference:
34+
""" IngressClassParametersReference identifies an API object. This can be used to specify a cluster or
35+
namespace-scoped resource.
36+
37+
Attributes
38+
----------
39+
kind: str, default is Undefined, required.
40+
Kind is the type of resource being referenced.
41+
name: str, default is Undefined, required.
42+
Name is the name of resource being referenced.
43+
apiGroup: str, default is Undefined, optional.
44+
ApiGroup is the group for the resource being referenced. If APIGroup is not specified, the specified Kind must be
45+
in the core API group. For any other third-party types, APIGroup is required.
46+
namespace: str, default is Undefined, optional.
47+
Namespace is the namespace of the resource being referenced. This field is required when scope is set to "Namespace"
48+
and must be unset when scope is set to "Cluster".
49+
scope: str, default is Undefined, optional.
50+
Scope represents if this refers to a cluster or namespace scoped resource. This may be set to "Cluster" (default)
51+
or "Namespace".
52+
"""
53+
54+
# Kind is the type of resource being referenced.
55+
kind: str
56+
57+
# Name is the name of resource being referenced.
58+
name: str
59+
60+
# ApiGroup is the group for the resource being referenced.
61+
apiGroup?: str
62+
63+
# Namespace is the namespace of the resource being referenced.
64+
namespace?: str
65+
66+
# Scope represents if this refers to a cluster or namespace scoped resource.
67+
scope?: str
68+
69+
check:
70+
scope in ["Namespace", "Cluster"] if scope, "scope value is invalid"
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
schema IngressRule:
2+
""" IngressRule represents the rules mapping the paths under a specified host to the related backend services.
3+
Incoming requests are first evaluated for a host match, then routed to the backend associated with the matching IngressRuleValue.
4+
5+
Attributes
6+
----------
7+
host: str, default is Undefined, optional.
8+
Host is the fully qualified domain name of a network host, as defined by RFC 3986. Note the following deviations
9+
from the "host" part of the URI as defined in RFC 3986: 1. IPs are not allowed. Currently an IngressRuleValue can
10+
only apply to the IP in the Spec of the parent Ingress. 2. The : delimiter is not respected because ports are not
11+
allowed. Currently the port of an Ingress is implicitly :80 for http and :443 for https. Both these may change in
12+
the future. Incoming requests are matched against the host before the IngressRuleValue. If the host is unspecified,
13+
the Ingress routes all traffic based on the specified IngressRuleValue.
14+
Host can be "precise" which is a domain name without the terminating dot of a network host (e.g. "foo.bar.com")
15+
or "wildcard", which is a domain name prefixed with a single wildcard label (e.g. ".foo.com"). The wildcard
16+
character '' must appear by itself as the first DNS label and matches only a single label. You cannot have a
17+
wildcard label by itself (e.g. Host == "*"). Requests will be matched against the Host field in the following
18+
way: 1. If host is precise, the request matches this rule if the http host header is equal to Host. 2. If host is
19+
a wildcard, then the request matches this rule if the http host header is to equal to the suffix (removing the
20+
first label) of the wildcard rule.
21+
http: HTTPIngressRuleValue, default is Undefined, optional.
22+
HTTPIngressRuleValue is a list of http selectors pointing to backends. In the example: http:///? -> backend where
23+
parts of the url correspond to RFC 3986, this resource will be used to match against everything after the last '/'
24+
and before the first '?' or '#'.
25+
"""
26+
27+
# Host is the fully qualified domain name of a network host, as defined by RFC 3986.
28+
host?: str
29+
30+
# HTTPIngressRuleValue is a list of http selectors pointing to backends.
31+
http?: HTTPIngressRuleValue
32+
33+
34+
schema HTTPIngressRuleValue:
35+
""" HTTPIngressRuleValue is a list of http selectors pointing to backends. In the example:
36+
http://<host>/<path>?<searchpart> -> backend where where parts of the url correspond to RFC 3986, this resource will
37+
be used to match against everything after the last '/' and before the first '?' or '#'.
38+
39+
Attributes
40+
----------
41+
paths: [HTTPIngressPath], default is Undefined, required.
42+
Paths is a collection of paths that map requests to backends.
43+
"""
44+
45+
# Paths is a collection of paths that map requests to backends.
46+
paths: [HTTPIngressPath]
47+
48+
49+
schema HTTPIngressPath:
50+
""" HTTPIngressPath associates a path with a backend. Incoming urls matching the path are forwarded to the backend.
51+
52+
Attributes
53+
----------
54+
backend: IngressBackend, default is Undefined, required.
55+
Backend defines the referenced service endpoint to which the traffic will be forwarded to.
56+
pathType: str, default is Undefined, required.
57+
PathType determines the interpretation of the path matching. PathType can be one of the following values:
58+
* Exact: Matches the URL path exactly. * Prefix: Matches based on a URL path prefix split by '/'. Matching is
59+
done on a path element by element basis. A path element refers is the list of labels in the path split by the '/'
60+
separator. A request is a match for path p if every p is an element-wise prefix of p of the request path. Note
61+
that if the last element of the path is a substring of the last element in request path, it is not a match
62+
(e.g. /foo/bar matches /foo/bar/baz, but does not match /foo/barbaz).
63+
ImplementationSpecific: Interpretation of the Path matching is up to the IngressClass. Implementations can treat
64+
this as a separate PathType or treat it identically to Prefix or Exact path types. Implementations are required
65+
to support all path types.
66+
path: str, default is Undefined, optional.
67+
Path is matched against the path of an incoming request. Currently it can contain characters disallowed from the
68+
conventional "path" part of a URL as defined by RFC 3986. Paths must begin with a '/' and must be present when
69+
using PathType with value "Exact" or "Prefix".
70+
"""
71+
72+
# Backend defines the referenced service endpoint to which the traffic will be forwarded to.
73+
backend: IngressBackend
74+
75+
# PathType determines the interpretation of the path matching.
76+
pathType: str
77+
78+
# Path is matched against the path of an incoming request.
79+
path?: str
80+
81+
check:
82+
pathType in ["Exact", "Prefix", "ImplementationSpecific"] if pathType, "pathType value is invalid"
83+
84+
85+
86+
87+
88+
89+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
schema IngressTLS:
2+
""" IngressTLS describes the transport layer security associated with an ingress.
3+
4+
Attributes
5+
----------
6+
hosts: [str], default is Undefined, optional.
7+
Hosts is a list of hosts included in the TLS certificate. The values in this list must match the name/s used in
8+
the tlsSecret. Defaults to the wildcard host setting for the loadbalancer controller fulfilling this Ingress, if
9+
left unspecified.
10+
secretName: str, default is Undefined, optional.
11+
SecretName is the name of the secret used to terminate TLS traffic on port 443. Field is left optional to allow
12+
TLS routing based on SNI hostname alone. If the SNI host in a listener conflicts with the "Host" header field used
13+
by an IngressRule, the SNI host is used for termination and value of the "Host" header is used for routing.
14+
"""
15+
16+
# Hosts is a list of hosts included in the TLS certificate.
17+
hosts?: [str]
18+
19+
# SecretName is the name of the secret used to terminate TLS traffic on port 443.
20+
secretName?: str
21+
22+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
schema TypedLocalObjectReference:
2+
""" TypedLocalObjectReference contains enough information to let you locate the typed referenced object inside the
3+
same namespace.
4+
5+
Attributes
6+
----------
7+
kind: str, default is Undefined, required.
8+
Kind is the type of resource being referenced.
9+
name: str, default is Undefined, required.
10+
Name is the name of resource being referenced.
11+
apiGroup: str, optional.
12+
APIGroup is the group for the resource being referenced. If APIGroup is not specified, the specified Kind must
13+
be in the core API group. For any other third-party types, APIGroup is required.
14+
"""
15+
16+
# Kind is the type of resource being referenced.
17+
kind: str
18+
19+
# Name is the name of resource being referenced.
20+
name: str
21+
22+
# APIGroup is the group for the resource being referenced. If APIGroup is not specified, the specified Kind must
23+
# be in the core API group. For any other third-party types, APIGroup is required.
24+
apiGroup?: str

modules/network/network.k

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
schema Network:
1+
import ingress as ing
2+
3+
schema Network:
24
""" Network describes the network accessories of Workload, which typically contains the exposed ports, load balancer
35
and other related resource configs.
46
57
Attributes
68
----------
79
ports: [n.Port], default is Undefined, optional.
810
The list of ports which the Workload should get exposed.
11+
ingress: ing.Ingress, default is Undefined, optional.
12+
Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.
13+
ingressClass: ing.IngressClass, default is Undefined, optional.
14+
IngressClass represents the class of the Ingress, referenced by the Ingress Spec.
915
1016
Examples
1117
--------
@@ -29,6 +35,13 @@ schema Network:
2935
# The list of ports getting exposed.
3036
ports?: [Port]
3137

38+
# Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.
39+
ingress?: ing.Ingress
40+
41+
# Ingress is a collection of rules that allow inbound connections to reach the endpoints defined by a backend.
42+
ingressClass?: ing.IngressClass
43+
44+
3245
schema Port:
3346
""" Port defines the exposed port of Workload, which can be used to describe how the Workload
3447
get accessed.

modules/network/src/go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ go 1.23.1
55
toolchain go1.23.2
66

77
require (
8+
github.com/hashicorp/go-hclog v1.6.3
89
github.com/stretchr/testify v1.10.0
910
gopkg.in/yaml.v3 v3.0.1
1011
k8s.io/api v0.31.3
1112
k8s.io/apimachinery v0.31.3
13+
k8s.io/kubernetes v1.32.0
1214
kusionstack.io/kusion-api-go v0.13.0
1315
kusionstack.io/kusion-module-framework v0.2.3-beta.6
1416
)
@@ -21,7 +23,6 @@ require (
2123
github.com/gogo/protobuf v1.3.2 // indirect
2224
github.com/golang/protobuf v1.5.4 // indirect
2325
github.com/google/gofuzz v1.2.0 // indirect
24-
github.com/hashicorp/go-hclog v1.6.3 // indirect
2526
github.com/hashicorp/go-plugin v1.6.2 // indirect
2627
github.com/hashicorp/yamux v0.1.2 // indirect
2728
github.com/json-iterator/go v1.1.12 // indirect

modules/network/src/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ k8s.io/apimachinery v0.31.3 h1:6l0WhcYgasZ/wk9ktLq5vLaoXJJr5ts6lkaQzgeYPq4=
150150
k8s.io/apimachinery v0.31.3/go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo=
151151
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
152152
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
153+
k8s.io/kubernetes v1.32.0 h1:4BDBWSolqPrv8GC3YfZw0CJvh5kA1TPnoX0FxDVd+qc=
154+
k8s.io/kubernetes v1.32.0/go.mod h1:tiIKO63GcdPRBHW2WiUFm3C0eoLczl3f7qi56Dm1W8I=
153155
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078 h1:jGnCPejIetjiy2gqaJ5V0NLwTpF4wbQ6cZIItJCSHno=
154156
k8s.io/utils v0.0.0-20241104163129-6fe5fd82f078/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
155157
kusionstack.io/kusion-api-go v0.13.0 h1:fDrLkgpkBnG7DTSHmCEfO/aL+iv6FZCTZ4ucxaQSuwg=

0 commit comments

Comments
 (0)