Skip to content

Commit 48ac31e

Browse files
committed
add ApplicationTargetsBinding API
1 parent 6532b2f commit 48ac31e

12 files changed

+612
-14
lines changed

config/crds/ingress_v1alpha1_applicationtargetgroup.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ spec:
141141
- protocol
142142
type: object
143143
status:
144+
properties:
145+
targetGroupARN:
146+
type: string
144147
type: object
145148
version: v1alpha1
146149
status:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
creationTimestamp: null
5+
labels:
6+
controller-tools.k8s.io: "1.0"
7+
name: applicationtargetsbindings.ingress.k8s.aws
8+
spec:
9+
group: ingress.k8s.aws
10+
names:
11+
kind: ApplicationTargetsBinding
12+
plural: applicationtargetsbindings
13+
scope: Namespaced
14+
validation:
15+
openAPIV3Schema:
16+
properties:
17+
apiVersion:
18+
description: 'APIVersion defines the versioned schema of this representation
19+
of an object. Servers should convert recognized schemas to the latest
20+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources'
21+
type: string
22+
kind:
23+
description: 'Kind is a string value representing the REST resource this
24+
object represents. Servers may infer this from the endpoint the client
25+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds'
26+
type: string
27+
metadata:
28+
type: object
29+
spec:
30+
properties:
31+
networkType:
32+
type: string
33+
serviceName:
34+
type: string
35+
servicePort:
36+
oneOf:
37+
- type: string
38+
- type: integer
39+
targetGroupARN:
40+
type: string
41+
targetGroupRef:
42+
type: object
43+
targetType:
44+
type: string
45+
required:
46+
- targetType
47+
- networkType
48+
- serviceName
49+
- servicePort
50+
type: object
51+
status:
52+
type: object
53+
version: v1alpha1
54+
status:
55+
acceptedNames:
56+
kind: ""
57+
plural: ""
58+
conditions: []
59+
storedVersions: []

config/rbac/rbac_role.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,46 @@ rules:
6464
- get
6565
- update
6666
- patch
67+
- apiGroups:
68+
- ingress.k8s.aws
69+
resources:
70+
- applicationtargetsbindings
71+
verbs:
72+
- get
73+
- list
74+
- watch
75+
- create
76+
- update
77+
- patch
78+
- delete
79+
- apiGroups:
80+
- ingress.k8s.aws
81+
resources:
82+
- applicationtargetsbindings/status
83+
verbs:
84+
- get
85+
- update
86+
- patch
87+
- apiGroups:
88+
- apps
89+
resources:
90+
- deployments
91+
verbs:
92+
- get
93+
- list
94+
- watch
95+
- create
96+
- update
97+
- patch
98+
- delete
99+
- apiGroups:
100+
- apps
101+
resources:
102+
- deployments/status
103+
verbs:
104+
- get
105+
- update
106+
- patch
67107
- apiGroups:
68108
- ingress.k8s.aws
69109
resources:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: ingress.k8s.aws/v1alpha1
2+
kind: ApplicationTargetsBinding
3+
metadata:
4+
labels:
5+
controller-tools.k8s.io: "1.0"
6+
name: applicationtargetsbinding-sample
7+
spec:
8+
# Add fields here
9+
foo: bar

pkg/apis/ingress/v1alpha1/applicationtargetgroup_types.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,6 @@ type HealthCheckConfig struct {
6363
Matcher *HealthCheckMatcher `json:"matcher,omitempty"`
6464
}
6565

66-
type TargetType string
67-
68-
const (
69-
TargetTypeInstance = "instance"
70-
TargetTypeIP = "ip"
71-
)
72-
7366
type TargetGroupDeregistrationDelayAttributes struct {
7467
// +kubebuilder:validation:Minimum=0
7568
// +kubebuilder:validation:Maximum=3600
@@ -139,8 +132,8 @@ type ApplicationTargetGroupSpec struct {
139132

140133
// ApplicationTargetGroupStatus defines the observed state of ApplicationTargetGroup
141134
type ApplicationTargetGroupStatus struct {
142-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
143-
// Important: Run "make" to regenerate code after modifying this file
135+
// +optional
136+
TargetGroupARN string `json:"targetGroupARN,omitempty"`
144137
}
145138

146139
// +genclient
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
Copyright 2019 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 v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/util/intstr"
22+
)
23+
24+
// ApplicationTargetsBindingSpec defines the desired state of ApplicationTargetsBinding
25+
type ApplicationTargetsBindingSpec struct {
26+
TargetGroupReference `json:",inline"`
27+
28+
TargetType TargetType `json:"targetType"`
29+
NetworkType NetworkType `json:"networkType"`
30+
ServiceName string `json:"serviceName"`
31+
ServicePort intstr.IntOrString `json:"servicePort"`
32+
}
33+
34+
// ApplicationTargetsBindingStatus defines the observed state of ApplicationTargetsBinding
35+
type ApplicationTargetsBindingStatus struct {
36+
}
37+
38+
// +genclient
39+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
40+
41+
// ApplicationTargetsBinding is the Schema for the applicationtargetsbindings API
42+
// +k8s:openapi-gen=true
43+
type ApplicationTargetsBinding struct {
44+
metav1.TypeMeta `json:",inline"`
45+
metav1.ObjectMeta `json:"metadata,omitempty"`
46+
47+
Spec ApplicationTargetsBindingSpec `json:"spec,omitempty"`
48+
Status ApplicationTargetsBindingStatus `json:"status,omitempty"`
49+
}
50+
51+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
52+
53+
// ApplicationTargetsBindingList contains a list of ApplicationTargetsBinding
54+
type ApplicationTargetsBindingList struct {
55+
metav1.TypeMeta `json:",inline"`
56+
metav1.ListMeta `json:"metadata,omitempty"`
57+
Items []ApplicationTargetsBinding `json:"items"`
58+
}
59+
60+
func init() {
61+
SchemeBuilder.Register(&ApplicationTargetsBinding{}, &ApplicationTargetsBindingList{})
62+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2019 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 v1alpha1
18+
19+
import (
20+
"testing"
21+
22+
"github.com/onsi/gomega"
23+
"golang.org/x/net/context"
24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25+
"k8s.io/apimachinery/pkg/types"
26+
)
27+
28+
func TestStorageApplicationTargetsBinding(t *testing.T) {
29+
key := types.NamespacedName{
30+
Name: "foo",
31+
Namespace: "default",
32+
}
33+
created := &ApplicationTargetsBinding{
34+
ObjectMeta: metav1.ObjectMeta{
35+
Name: "foo",
36+
Namespace: "default",
37+
}}
38+
g := gomega.NewGomegaWithT(t)
39+
40+
// Test Create
41+
fetched := &ApplicationTargetsBinding{}
42+
g.Expect(c.Create(context.TODO(), created)).To(gomega.Succeed())
43+
44+
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed())
45+
g.Expect(fetched).To(gomega.Equal(created))
46+
47+
// Test Updating the Labels
48+
updated := fetched.DeepCopy()
49+
updated.Labels = map[string]string{"hello": "world"}
50+
g.Expect(c.Update(context.TODO(), updated)).To(gomega.Succeed())
51+
52+
g.Expect(c.Get(context.TODO(), key, fetched)).To(gomega.Succeed())
53+
g.Expect(fetched).To(gomega.Equal(updated))
54+
55+
// Test Delete
56+
g.Expect(c.Delete(context.TODO(), fetched)).To(gomega.Succeed())
57+
g.Expect(c.Get(context.TODO(), key, fetched)).ToNot(gomega.Succeed())
58+
}

pkg/apis/ingress/v1alpha1/types.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@ const (
1313
ProtocolTLS = "TLS"
1414
)
1515

16+
type TargetType string
17+
18+
const (
19+
TargetTypeInstance = "instance"
20+
TargetTypeIP = "ip"
21+
)
22+
23+
type NetworkType string
24+
25+
const (
26+
NetworkTypeAmazonVPCRoutedENI = "amazon-vpc-routed-eni"
27+
NetworkTypeKubenet = "kubenet"
28+
)
29+
30+
type TargetGroupReference struct {
31+
// +optional
32+
TargetGroupRef corev1.ObjectReference `json:"targetGroupRef,omitempty"`
33+
34+
// +optional
35+
TargetGroupARN string `json:"targetGroupARN,omitempty"`
36+
}
37+
1638
type ApplicationListenerActionType string
1739

1840
const (
@@ -121,11 +143,7 @@ type RedirectConfig struct {
121143
}
122144

123145
type ForwardConfig struct {
124-
// +optional
125-
TargetGroupRef corev1.ObjectReference `json:"targetGroupRef,omitempty"`
126-
127-
// +optional
128-
TargetGroupARN string `json:"targetGroupARN,omitempty"`
146+
TargetGroupReference `json:",inline"`
129147
}
130148

131149
type ApplicationListenerAction struct {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2019 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 controller
18+
19+
import (
20+
"sigs.k8s.io/aws-alb-ingress-controller/pkg/controller/applicationtargetsbinding"
21+
)
22+
23+
func init() {
24+
// AddToManagerFuncs is a list of functions to create controllers and add them to a manager.
25+
AddToManagerFuncs = append(AddToManagerFuncs, applicationtargetsbinding.Add)
26+
}

0 commit comments

Comments
 (0)