Skip to content

Commit cad6645

Browse files
authored
feat: add ingress and ingressClass (#102)
## What type of PR is this? /kind feature: add ingress and ingressClass for network module ## Which issue(s) this PR fixes: Fixes KusionStack/kusion#1306
1 parent b899f3f commit cad6645

17 files changed

Lines changed: 1018 additions & 75 deletions

modules/network/example/dev/example_workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
modules:
22
network:
33
path: oci://ghcr.io/kusionstack/network
4-
version: 0.2.0
4+
version: 0.3.0
55
configs:
66
default:
77
port:

modules/network/example/dev/kcl.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = "example"
33

44
[dependencies]
55
kam = { git = "https://github.com/KusionStack/kam.git", tag = "0.2.0" }
6-
service = {oci = "oci://ghcr.io/kusionstack/service", tag = "0.1.0" }
7-
network = { oci = "oci://ghcr.io/kusionstack/network", tag = "0.2.0" }
6+
service = { oci = "oci://ghcr.io/kusionstack/service", tag = "0.2.0" }
7+
network = { oci = "oci://ghcr.io/kusionstack/network", tag = "0.3.0" }
88

99
[profile]
1010
entries = ["main.k"]

modules/network/example/dev/main.k

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import kam.v1.app_configuration as ac
33
import service
44
import service.container as c
55
import network as n
6+
import network.ingress as ni
67

78
nginx: ac.AppConfiguration {
89
workload: service.Service {
@@ -16,10 +17,39 @@ nginx: ac.AppConfiguration {
1617
"network": n.Network {
1718
ports: [
1819
n.Port {
19-
port: 80
20-
public: True
20+
port: 8080
21+
targetPort: 80
22+
public: False
2123
}
2224
]
25+
ingress: {
26+
defaultBackend: {
27+
service: {
28+
port: {
29+
number: 8080
30+
}
31+
}
32+
}
33+
rules: [
34+
{
35+
http: {
36+
paths: [
37+
{
38+
path: "/"
39+
pathType: "Prefix"
40+
backend: {
41+
service: {
42+
port: {
43+
number: 8080
44+
}
45+
}
46+
}
47+
}
48+
]
49+
}
50+
}
51+
]
52+
}
2353
}
2454
}
2555
}

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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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
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/kcl.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[package]
22
name = "network"
3-
version = "0.2.1-rc.1"
3+
version = "0.3.0"

0 commit comments

Comments
 (0)