Skip to content

Commit 436c3d2

Browse files
authored
IngressClassParams support (#1849)
* bootstrap IngressClassParams CRD * add validation webhook for disable annotation usage for ingressClass & ingressGroupName * update go mod
1 parent 04c9bf5 commit 436c3d2

27 files changed

+1234
-251
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ifeq (, $(shell which controller-gen))
7171
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
7272
cd $$CONTROLLER_GEN_TMP_DIR ;\
7373
go mod init tmp ;\
74-
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
74+
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
7575
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
7676
}
7777
CONTROLLER_GEN=$(GOBIN)/controller-gen

PROJECT

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@ repo: sigs.k8s.io/aws-load-balancer-controller
44
resources:
55
- group: elbv2
66
kind: TargetGroupBinding
7-
version: v1alpha1
7+
version: v1beta1
8+
- group: elbv2
9+
kind: IngressClassParams
10+
version: v1beta1
811
version: "2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
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 v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// +kubebuilder:validation:Enum=ipv4;dualstack
24+
// IPAddressType is the ip address type of load balancer.
25+
type IPAddressType string
26+
27+
const (
28+
IPAddressTypeIPV4 IPAddressType = "ipv4"
29+
IPAddressTypeDualStack IPAddressType = "dualstack"
30+
)
31+
32+
// +kubebuilder:validation:Enum=internal;internet-facing
33+
// Scheme is the scheme of load balancer.
34+
//
35+
// * the nodes of an internet-facing load balancer have public IP addresses.
36+
// * the nodes of an internal load balancer have only private IP addresses.
37+
type LoadBalancerScheme string
38+
39+
const (
40+
LoadBalancerSchemeInternal LoadBalancerScheme = "internal"
41+
LoadBalancerSchemeInternetFacing LoadBalancerScheme = "internet-facing"
42+
)
43+
44+
// IngressGroup defines IngressGroup configuration.
45+
type IngressGroup struct {
46+
// Name is the name of IngressGroup.
47+
Name string `json:"name"`
48+
}
49+
50+
// IngressClassParamsSpec defines the desired state of IngressClassParams
51+
type IngressClassParamsSpec struct {
52+
// NamespaceSelector restrict the namespaces of Ingresses that are allowed to specify the IngressClass with this IngressClassParams.
53+
// * if absent or present but empty, it selects all namespaces.
54+
// +optional
55+
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
56+
57+
// Group defines the IngressGroup for all Ingresses that belong to IngressClass with this IngressClassParams.
58+
// +optional
59+
Group *IngressGroup `json:"group,omitempty"`
60+
61+
// Scheme defines the scheme for all Ingresses that belong to IngressClass with this IngressClassParams.
62+
// +optional
63+
Scheme *LoadBalancerScheme `json:"scheme,omitempty"`
64+
65+
// IPAddressType defines the ip address type for all Ingresses that belong to IngressClass with this IngressClassParams.
66+
// +optional
67+
IPAddressType *IPAddressType `json:"ipAddressType,omitempty"`
68+
}
69+
70+
// +kubebuilder:object:root=true
71+
// +kubebuilder:resource:scope=Cluster
72+
// +kubebuilder:storageversion
73+
// IngressClassParams is the Schema for the IngressClassParams API
74+
type IngressClassParams struct {
75+
metav1.TypeMeta `json:",inline"`
76+
metav1.ObjectMeta `json:"metadata,omitempty"`
77+
78+
Spec IngressClassParamsSpec `json:"spec,omitempty"`
79+
}
80+
81+
// +kubebuilder:object:root=true
82+
83+
// IngressClassParamsList contains a list of IngressClassParams
84+
type IngressClassParamsList struct {
85+
metav1.TypeMeta `json:",inline"`
86+
metav1.ListMeta `json:"metadata,omitempty"`
87+
Items []IngressClassParams `json:"items"`
88+
}
89+
90+
func init() {
91+
SchemeBuilder.Register(&IngressClassParams{}, &IngressClassParamsList{})
92+
}

apis/elbv2/v1beta1/zz_generated.deepcopy.go

+108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
2+
---
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
controller-gen.kubebuilder.io/version: v0.4.0
8+
creationTimestamp: null
9+
name: ingressclassparams.elbv2.k8s.aws
10+
spec:
11+
group: elbv2.k8s.aws
12+
names:
13+
kind: IngressClassParams
14+
listKind: IngressClassParamsList
15+
plural: ingressclassparams
16+
singular: ingressclassparams
17+
scope: Cluster
18+
validation:
19+
openAPIV3Schema:
20+
description: IngressClassParams is the Schema for the IngressClassParams API
21+
properties:
22+
apiVersion:
23+
description: 'APIVersion defines the versioned schema of this representation
24+
of an object. Servers should convert recognized schemas to the latest
25+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
26+
type: string
27+
kind:
28+
description: 'Kind is a string value representing the REST resource this
29+
object represents. Servers may infer this from the endpoint the client
30+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
31+
type: string
32+
metadata:
33+
type: object
34+
spec:
35+
description: IngressClassParamsSpec defines the desired state of IngressClassParams
36+
properties:
37+
group:
38+
description: Group defines the IngressGroup for all Ingresses that belong
39+
to IngressClass with this IngressClassParams.
40+
properties:
41+
name:
42+
description: Name is the name of IngressGroup.
43+
type: string
44+
required:
45+
- name
46+
type: object
47+
ipAddressType:
48+
description: IPAddressType defines the ip address type for all Ingresses
49+
that belong to IngressClass with this IngressClassParams.
50+
enum:
51+
- ipv4
52+
- dualstack
53+
type: string
54+
namespaceSelector:
55+
description: NamespaceSelector restrict the namespaces of Ingresses
56+
that are allowed to specify the IngressClass with this IngressClassParams.
57+
* if absent or present but empty, it selects all namespaces.
58+
properties:
59+
matchExpressions:
60+
description: matchExpressions is a list of label selector requirements.
61+
The requirements are ANDed.
62+
items:
63+
description: A label selector requirement is a selector that contains
64+
values, a key, and an operator that relates the key and values.
65+
properties:
66+
key:
67+
description: key is the label key that the selector applies
68+
to.
69+
type: string
70+
operator:
71+
description: operator represents a key's relationship to a
72+
set of values. Valid operators are In, NotIn, Exists and
73+
DoesNotExist.
74+
type: string
75+
values:
76+
description: values is an array of string values. If the operator
77+
is In or NotIn, the values array must be non-empty. If the
78+
operator is Exists or DoesNotExist, the values array must
79+
be empty. This array is replaced during a strategic merge
80+
patch.
81+
items:
82+
type: string
83+
type: array
84+
required:
85+
- key
86+
- operator
87+
type: object
88+
type: array
89+
matchLabels:
90+
additionalProperties:
91+
type: string
92+
description: matchLabels is a map of {key,value} pairs. A single
93+
{key,value} in the matchLabels map is equivalent to an element
94+
of matchExpressions, whose key field is "key", the operator is
95+
"In", and the values array contains only "value". The requirements
96+
are ANDed.
97+
type: object
98+
type: object
99+
scheme:
100+
description: Scheme defines the scheme for all Ingresses that belong
101+
to IngressClass with this IngressClassParams.
102+
enum:
103+
- internal
104+
- internet-facing
105+
type: string
106+
type: object
107+
type: object
108+
version: v1beta1
109+
versions:
110+
- name: v1beta1
111+
served: true
112+
storage: true
113+
status:
114+
acceptedNames:
115+
kind: ""
116+
plural: ""
117+
conditions: []
118+
storedVersions: []

config/crd/kustomization.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
# It should be run by config/default
44
resources:
55
- bases/elbv2.k8s.aws_targetgroupbindings.yaml
6+
- bases/elbv2.k8s.aws_ingressclassparams.yaml
67
# +kubebuilder:scaffold:crdkustomizeresource
78

89
patchesStrategicMerge:
910
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
1011
# patches here are for enabling the conversion webhook for each CRD
1112
#- patches/webhook_in_targetgroupbindings.yaml
13+
#- patches/webhook_in_ingressclassparams.yaml
1214
# +kubebuilder:scaffold:crdkustomizewebhookpatch
1315

1416
# [CERTMANAGER] To enable webhook, uncomment all the sections with [CERTMANAGER] prefix.
1517
# patches here are for enabling the CA injection for each CRD
1618
#- patches/cainjection_in_targetgroupbindings.yaml
19+
#- patches/cainjection_in_ingressclassparams.yaml
1720
# +kubebuilder:scaffold:crdkustomizecainjectionpatch
1821

1922
# the following config is for teaching kustomize how to do kustomization for CRDs.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following patch adds a directive for certmanager to inject CA into the CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
annotations:
7+
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
8+
name: ingressclassparams.elbv2.k8s.aws
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# The following patch enables conversion webhook for CRD
2+
# CRD conversion requires k8s 1.13 or later.
3+
apiVersion: apiextensions.k8s.io/v1beta1
4+
kind: CustomResourceDefinition
5+
metadata:
6+
name: ingressclassparams.elbv2.k8s.aws
7+
spec:
8+
conversion:
9+
strategy: Webhook
10+
webhookClientConfig:
11+
# this is "\n" used as a placeholder, otherwise it will be rejected by the apiserver for being blank,
12+
# but we're going to set it later using the cert-manager (or potentially a patch if not using cert-manager)
13+
caBundle: Cg==
14+
service:
15+
name: webhook-service
16+
path: /convert

0 commit comments

Comments
 (0)