Skip to content

Commit 3b50dd8

Browse files
dspoCopilot
andauthored
feat: Add v2 API support for Apisix resources and update controller logic (#158)
Co-authored-by: Copilot <[email protected]>
1 parent 0a97f82 commit 3b50dd8

File tree

52 files changed

+6169
-258
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+6169
-258
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
293293

294294
## Tool Versions
295295
KUSTOMIZE_VERSION ?= v5.4.2
296-
CONTROLLER_TOOLS_VERSION ?= v0.15.0
296+
CONTROLLER_TOOLS_VERSION ?= v0.17.2
297297
ENVTEST_VERSION ?= release-0.18
298298
GOLANGCI_LINT_VERSION ?= v2.1.5
299299

PROJECT

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,57 @@ resources:
3434
kind: HTTPRoutePolicy
3535
path: github.com/apache/apisix-ingress-controller/api/v1alpha1
3636
version: v1alpha1
37+
- api:
38+
crdVersion: v1
39+
namespaced: true
40+
controller: true
41+
domain: github.com
42+
group: apisix.apache.org
43+
kind: ApisixRoute
44+
path: github.com/apache/apisix-ingress-controller/api/v2
45+
version: v2
46+
- api:
47+
crdVersion: v1
48+
namespaced: true
49+
controller: true
50+
domain: github.com
51+
group: apisix.apache.org
52+
kind: ApisixConsumer
53+
path: github.com/apache/apisix-ingress-controller/api/v2
54+
version: v2
55+
- api:
56+
crdVersion: v1
57+
namespaced: true
58+
controller: true
59+
domain: github.com
60+
group: apisix.apache.org
61+
kind: ApisixGlobalRule
62+
path: github.com/apache/apisix-ingress-controller/api/v2
63+
version: v2
64+
- api:
65+
crdVersion: v1
66+
namespaced: true
67+
controller: true
68+
domain: github.com
69+
group: apisix.apache.org
70+
kind: ApisixTls
71+
path: github.com/apache/apisix-ingress-controller/api/v2
72+
version: v2
73+
- api:
74+
crdVersion: v1
75+
namespaced: true
76+
controller: true
77+
domain: github.com
78+
group: apisix.apache.org
79+
kind: ApisixUpstream
80+
path: github.com/apache/apisix-ingress-controller/api/v2
81+
version: v2
82+
- api:
83+
crdVersion: v1
84+
namespaced: true
85+
domain: github.com
86+
group: apisix.apache.org
87+
kind: ApisixPluginConfig
88+
path: github.com/apache/apisix-ingress-controller/api/v2
89+
version: v2
3790
version: "3"

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/apisixconsumer_types.go

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
package v2
14+
15+
import (
16+
corev1 "k8s.io/api/core/v1"
17+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18+
)
19+
20+
// ApisixConsumerSpec defines the desired state of ApisixConsumer.
21+
type ApisixConsumerSpec struct {
22+
// IngressClassName is the name of an IngressClass cluster resource.
23+
// controller implementations use this field to know whether they should be
24+
// serving this ApisixConsumer resource, by a transitive connection
25+
// (controller -> IngressClass -> ApisixConsumer resource).
26+
IngressClassName string `json:"ingressClassName,omitempty" yaml:"ingressClassName,omitempty"`
27+
28+
AuthParameter ApisixConsumerAuthParameter `json:"authParameter" yaml:"authParameter"`
29+
}
30+
31+
// ApisixConsumerStatus defines the observed state of ApisixConsumer.
32+
type ApisixConsumerStatus = ApisixStatus
33+
34+
// +kubebuilder:object:root=true
35+
// +kubebuilder:subresource:status
36+
37+
// ApisixConsumer is the Schema for the apisixconsumers API.
38+
type ApisixConsumer struct {
39+
metav1.TypeMeta `json:",inline"`
40+
metav1.ObjectMeta `json:"metadata,omitempty"`
41+
42+
Spec ApisixConsumerSpec `json:"spec,omitempty"`
43+
Status ApisixConsumerStatus `json:"status,omitempty"`
44+
}
45+
46+
// +kubebuilder:object:root=true
47+
48+
// ApisixConsumerList contains a list of ApisixConsumer.
49+
type ApisixConsumerList struct {
50+
metav1.TypeMeta `json:",inline"`
51+
metav1.ListMeta `json:"metadata,omitempty"`
52+
Items []ApisixConsumer `json:"items"`
53+
}
54+
55+
type ApisixConsumerAuthParameter struct {
56+
BasicAuth *ApisixConsumerBasicAuth `json:"basicAuth,omitempty" yaml:"basicAuth"`
57+
KeyAuth *ApisixConsumerKeyAuth `json:"keyAuth,omitempty" yaml:"keyAuth"`
58+
WolfRBAC *ApisixConsumerWolfRBAC `json:"wolfRBAC,omitempty" yaml:"wolfRBAC"`
59+
JwtAuth *ApisixConsumerJwtAuth `json:"jwtAuth,omitempty" yaml:"jwtAuth"`
60+
HMACAuth *ApisixConsumerHMACAuth `json:"hmacAuth,omitempty" yaml:"hmacAuth"`
61+
LDAPAuth *ApisixConsumerLDAPAuth `json:"ldapAuth,omitempty" yaml:"ldapAuth"`
62+
}
63+
64+
// ApisixConsumerBasicAuth defines the configuration for basic auth.
65+
type ApisixConsumerBasicAuth struct {
66+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
67+
Value *ApisixConsumerBasicAuthValue `json:"value,omitempty" yaml:"value,omitempty"`
68+
}
69+
70+
// ApisixConsumerBasicAuthValue defines the in-place username and password configuration for basic auth.
71+
type ApisixConsumerBasicAuthValue struct {
72+
Username string `json:"username" yaml:"username"`
73+
Password string `json:"password" yaml:"password"`
74+
}
75+
76+
// ApisixConsumerKeyAuth defines the configuration for the key auth.
77+
type ApisixConsumerKeyAuth struct {
78+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
79+
Value *ApisixConsumerKeyAuthValue `json:"value,omitempty" yaml:"value,omitempty"`
80+
}
81+
82+
// ApisixConsumerKeyAuthValue defines the in-place configuration for basic auth.
83+
type ApisixConsumerKeyAuthValue struct {
84+
Key string `json:"key" yaml:"key"`
85+
}
86+
87+
// ApisixConsumerWolfRBAC defines the configuration for the wolf-rbac auth.
88+
type ApisixConsumerWolfRBAC struct {
89+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
90+
Value *ApisixConsumerWolfRBACValue `json:"value,omitempty" yaml:"value,omitempty"`
91+
}
92+
93+
// ApisixConsumerWolfRBAC defines the in-place server and appid and header_prefix configuration for wolf-rbac auth.
94+
type ApisixConsumerWolfRBACValue struct {
95+
Server string `json:"server,omitempty" yaml:"server,omitempty"`
96+
Appid string `json:"appid,omitempty" yaml:"appid,omitempty"`
97+
HeaderPrefix string `json:"header_prefix,omitempty" yaml:"header_prefix,omitempty"`
98+
}
99+
100+
// ApisixConsumerJwtAuth defines the configuration for the jwt auth.
101+
type ApisixConsumerJwtAuth struct {
102+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
103+
Value *ApisixConsumerJwtAuthValue `json:"value,omitempty" yaml:"value,omitempty"`
104+
}
105+
106+
// ApisixConsumerJwtAuthValue defines the in-place configuration for jwt auth.
107+
type ApisixConsumerJwtAuthValue struct {
108+
Key string `json:"key" yaml:"key"`
109+
Secret string `json:"secret,omitempty" yaml:"secret,omitempty"`
110+
PublicKey string `json:"public_key,omitempty" yaml:"public_key,omitempty"`
111+
PrivateKey string `json:"private_key" yaml:"private_key,omitempty"`
112+
Algorithm string `json:"algorithm,omitempty" yaml:"algorithm,omitempty"`
113+
Exp int64 `json:"exp,omitempty" yaml:"exp,omitempty"`
114+
Base64Secret bool `json:"base64_secret,omitempty" yaml:"base64_secret,omitempty"`
115+
LifetimeGracePeriod int64 `json:"lifetime_grace_period,omitempty" yaml:"lifetime_grace_period,omitempty"`
116+
}
117+
118+
// ApisixConsumerHMACAuth defines the configuration for the hmac auth.
119+
type ApisixConsumerHMACAuth struct {
120+
SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty" yaml:"secretRef,omitempty"`
121+
Value *ApisixConsumerHMACAuthValue `json:"value,omitempty" yaml:"value,omitempty"`
122+
}
123+
124+
// ApisixConsumerHMACAuthValue defines the in-place configuration for hmac auth.
125+
type ApisixConsumerHMACAuthValue struct {
126+
AccessKey string `json:"access_key" yaml:"access_key"`
127+
SecretKey string `json:"secret_key" yaml:"secret_key"`
128+
Algorithm string `json:"algorithm,omitempty" yaml:"algorithm,omitempty"`
129+
ClockSkew int64 `json:"clock_skew,omitempty" yaml:"clock_skew,omitempty"`
130+
SignedHeaders []string `json:"signed_headers,omitempty" yaml:"signed_headers,omitempty"`
131+
KeepHeaders bool `json:"keep_headers,omitempty" yaml:"keep_headers,omitempty"`
132+
EncodeURIParams bool `json:"encode_uri_params,omitempty" yaml:"encode_uri_params,omitempty"`
133+
ValidateRequestBody bool `json:"validate_request_body,omitempty" yaml:"validate_request_body,omitempty"`
134+
MaxReqBody int64 `json:"max_req_body,omitempty" yaml:"max_req_body,omitempty"`
135+
}
136+
137+
// ApisixConsumerLDAPAuth defines the configuration for the ldap auth.
138+
type ApisixConsumerLDAPAuth struct {
139+
SecretRef *corev1.LocalObjectReference `json:"secretRef" yaml:"secret"`
140+
Value *ApisixConsumerLDAPAuthValue `json:"value,omitempty" yaml:"value,omitempty"`
141+
}
142+
143+
// ApisixConsumerLDAPAuthValue defines the in-place configuration for ldap auth.
144+
type ApisixConsumerLDAPAuthValue struct {
145+
UserDN string `json:"user_dn" yaml:"user_dn"`
146+
}
147+
148+
func init() {
149+
SchemeBuilder.Register(&ApisixConsumer{}, &ApisixConsumerList{})
150+
}

api/v2/apisixglobalrule_types.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
package v2
14+
15+
import (
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
)
18+
19+
// ApisixGlobalRuleSpec defines the desired state of ApisixGlobalRule.
20+
type ApisixGlobalRuleSpec struct {
21+
// IngressClassName is the name of an IngressClass cluster resource.
22+
// The controller uses this field to decide whether the resource should be managed or not.
23+
IngressClassName string `json:"ingressClassName,omitempty" yaml:"ingressClassName,omitempty"`
24+
// Plugins contains a list of ApisixRoutePlugin
25+
// +kubebuilder:validation:Required
26+
Plugins []ApisixRoutePlugin `json:"plugins" yaml:"plugins"`
27+
}
28+
29+
// ApisixGlobalRuleStatus defines the observed state of ApisixGlobalRule.
30+
type ApisixGlobalRuleStatus = ApisixStatus
31+
32+
// +kubebuilder:object:root=true
33+
// +kubebuilder:subresource:status
34+
35+
// ApisixGlobalRule is the Schema for the apisixglobalrules API.
36+
type ApisixGlobalRule struct {
37+
metav1.TypeMeta `json:",inline"`
38+
metav1.ObjectMeta `json:"metadata,omitempty"`
39+
40+
Spec ApisixGlobalRuleSpec `json:"spec,omitempty"`
41+
Status ApisixGlobalRuleStatus `json:"status,omitempty"`
42+
}
43+
44+
// +kubebuilder:object:root=true
45+
46+
// ApisixGlobalRuleList contains a list of ApisixGlobalRule.
47+
type ApisixGlobalRuleList struct {
48+
metav1.TypeMeta `json:",inline"`
49+
metav1.ListMeta `json:"metadata,omitempty"`
50+
Items []ApisixGlobalRule `json:"items"`
51+
}
52+
53+
func init() {
54+
SchemeBuilder.Register(&ApisixGlobalRule{}, &ApisixGlobalRuleList{})
55+
}

api/v2/apisixpluginconfig_types.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Licensed under the Apache License, Version 2.0 (the "License");
2+
// you may not use this file except in compliance with the License.
3+
// You may obtain a copy of the License at
4+
//
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
//
7+
// Unless required by applicable law or agreed to in writing, software
8+
// distributed under the License is distributed on an "AS IS" BASIS,
9+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
// See the License for the specific language governing permissions and
11+
// limitations under the License.
12+
13+
package v2
14+
15+
import (
16+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
)
18+
19+
// ApisixPluginConfigSpec defines the desired state of ApisixPluginConfigSpec.
20+
type ApisixPluginConfigSpec struct {
21+
// IngressClassName is the name of an IngressClass cluster resource.
22+
// The controller uses this field to decide whether the resource should be managed or not.
23+
// +kubebuilder:validation:Optional
24+
IngressClassName string `json:"ingressClassName,omitempty" yaml:"ingressClassName,omitempty"`
25+
// Plugins contain a list of ApisixRoutePlugin
26+
// +kubebuilder:validation:Required
27+
Plugins []ApisixRoutePlugin `json:"plugins" yaml:"plugins"`
28+
}
29+
30+
// ApisixPluginConfigStatus defines the observed state of ApisixPluginConfig.
31+
type ApisixPluginConfigStatus ApisixStatus
32+
33+
// +kubebuilder:object:root=true
34+
// +kubebuilder:subresource:status
35+
36+
// ApisixPluginConfig is the Schema for the apisixpluginconfigs API.
37+
type ApisixPluginConfig struct {
38+
metav1.TypeMeta `json:",inline"`
39+
metav1.ObjectMeta `json:"metadata,omitempty"`
40+
41+
Spec ApisixPluginConfigSpec `json:"spec,omitempty"`
42+
Status ApisixPluginConfigStatus `json:"status,omitempty"`
43+
}
44+
45+
// +kubebuilder:object:root=true
46+
47+
// ApisixPluginConfigList contains a list of ApisixPluginConfig.
48+
type ApisixPluginConfigList struct {
49+
metav1.TypeMeta `json:",inline"`
50+
metav1.ListMeta `json:"metadata,omitempty"`
51+
Items []ApisixPluginConfig `json:"items"`
52+
}
53+
54+
func init() {
55+
SchemeBuilder.Register(&ApisixPluginConfig{}, &ApisixPluginConfigList{})
56+
}

0 commit comments

Comments
 (0)