-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ApisixRoute v2alpha1 #262
Merged
Merged
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d458871
feat: ApisixRoute v2alpha1
tokers c9265cd
fix
tokers 4716b73
Merge remote-tracking branch 'upstream/master' into feat/apisixroute-…
tokers dd36ae8
fix: broken unit test cases
tokers 9466c17
feat: ApisixRoute v2alph1
tokers f7f57bb
Merge remote-tracking branch 'upstream/master' into feat/apisixroute-…
tokers 9de8588
feat: apisixroute v2alpha1 translator and controller
tokers 5bb0de5
chore: deepcopy gen
tokers 7ff3505
feat: add kube.ApisixRoute
tokers be463ca
chore: unified kube.ApisixRoute interface
tokers f0af922
fix
tokers ff300fa
fix: e2e
tokers a647f47
fix
tokers 6335d0c
Merge remote-tracking branch 'upstream/master' into feat/apisixroute-…
tokers a367acc
fix
tokers fc5ee88
fix
tokers c074d33
fix
tokers 1691eaa
fix
tokers 557a88b
fix
tokers 3d90130
fix
tokers de03db9
fix
tokers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// +k8s:deepcopy-gen=package | ||
|
||
// +groupName=apisix.apache.org | ||
package v2alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package v2alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
const ( | ||
_groupName = "apisix.apache.org" | ||
_version = "v2alpha1" | ||
) | ||
|
||
var ( | ||
SchemeGroupVersion = schema.GroupVersion{ | ||
Group: _groupName, | ||
Version: _version, | ||
} | ||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} | ||
|
||
func addKnownTypes(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes(SchemeGroupVersion, | ||
&ApisixRoute{}, | ||
&ApisixRouteList{}, | ||
) | ||
|
||
// register the type in the scheme | ||
metav1.AddToGroupVersion(scheme, SchemeGroupVersion) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one or more | ||
// contributor license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright ownership. | ||
// The ASF licenses this file to You under the Apache License, Version 2.0 | ||
// (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package v2alpha1 | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
) | ||
|
||
// +genclient | ||
// +genclient:noStatus | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
// ApisixRoute is used to define the route rules and upstreams for Apache APISIX. | ||
type ApisixRoute struct { | ||
metav1.TypeMeta `json:",inline" yaml:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"` | ||
Spec *ApisixRouteSpec `json:"spec,omitempty" yaml:"spec,omitempty"` | ||
} | ||
|
||
// ApisixRouteSpec is the spec definition for ApisixRouteSpec. | ||
type ApisixRouteSpec struct { | ||
HTTP []*ApisixRouteHTTP `json:"http,omitempty"` | ||
} | ||
|
||
// ApisixRouteHTTP represents a single route in for HTTP traffic. | ||
type ApisixRouteHTTP struct { | ||
// Route priority, when multiple routes contains | ||
// same URI path (for path matching), route with | ||
// higher priority will take effect. | ||
Priority int `json:"priority,omitempty"` | ||
Match *ApisixRouteHTTPMatch `json:"match,omitempty"` | ||
Backend *ApisixRouteHTTPBackend `json:"backend"` | ||
Plugins []*ApisixRouteHTTPPlugin `json:"plugins,omitempty"` | ||
} | ||
|
||
// ApisixRouteHTTPMatch represents the match condition for hitting this route. | ||
type ApisixRouteHTTPMatch struct { | ||
// URI path predicates, at least one path should be | ||
// configured, path could be exact or prefix, for prefix path, | ||
// append "*" after it, for instance, "/foo*". | ||
Paths []string `json:"paths"` | ||
// HTTP request method predicates. | ||
Methods []string `json:"methods,omitempty"` | ||
// HTTP Host predicates, host can be a wildcard domain or | ||
// an exact domain. For wildcard domain, only one generic | ||
// level is allowed, for instance, "*.foo.com" is valid but | ||
// "*.*.foo.com" is not. | ||
Hosts []string `json:"hosts,omitempty"` | ||
// Remote address predicates, items can be valid IPv4 address | ||
// or IPv6 address or CIDR. | ||
RemoteAddrs []string `json:"remoteAddrs,omitempty"` | ||
// NginxVars represents generic match predicates, | ||
// it uses Nginx variable systems, so any predicate | ||
// like headers, querystring and etc can be leveraged | ||
// here to match the route. | ||
// For instance, it can be: | ||
// nginxVars: | ||
// - subject: "$remote_addr" | ||
// op: in | ||
// value: | ||
// - "127.0.0.1" | ||
// - "10.0.5.11" | ||
NginxVars []ApisixRouteHTTPMatchNginxVar `json:"nginxVars,omitempty"` | ||
} | ||
|
||
// ApisixRouteHTTPMatchNginxVar represents a binary expression for the Nginx vars. | ||
type ApisixRouteHTTPMatchNginxVar struct { | ||
// Subject is the expression subject, it can | ||
// be any string composed by literals and nginx | ||
// vars. | ||
Subject string `json:"subject"` | ||
// Op is the operator, can be: | ||
// - "==": equal | ||
// - "~=": not equal | ||
// - ">": greater than | ||
// - ">=": greater than or equal to | ||
// - "<": less then | ||
// - "<=": less then or equal to | ||
// - "~~": regex match | ||
// - "!~~": regex not match | ||
// - "~*": case insensitive regex match | ||
// - "!~*": case insensitive regex not match | ||
// - "in": set match, Value should be a string array. | ||
// - "not_in": set match, Value should be a string array. | ||
// - "contain": subject contains the Value (inclusion relation). | ||
// - "not_contain": subject doesn't contain the Value (inclusion relation). | ||
Op string `json:"op"` | ||
// Array is an array type object of the expression. | ||
// It should be used when the Op is "in" or "not_in"; | ||
Array []string `json:"array"` | ||
// Value is the normal type object for the expression, | ||
// it should be used when the Op is not "in" and "not_in". | ||
// Array and Value are exclusive so only of them can be set | ||
// in the same time. | ||
Value *string `json:"value"` | ||
} | ||
|
||
// ApisixRouteHTTPBackend represents a HTTP backend (a Kuberentes Service). | ||
type ApisixRouteHTTPBackend struct { | ||
// The name (short) of the service, note cross namespace is forbidden, | ||
// so be sure the ApisixRoute and Service are in the same namespace. | ||
ServiceName string `json:"serviceName"` | ||
// The service port, could be the name or the port number. | ||
ServicePort intstr.IntOrString `json:"servicePort"` | ||
// The resolve granularity, can be "endpoints" or "service", | ||
// when set to "endpoints", the pod ips will be used; other | ||
// wise, the service ClusterIP or ExternalIP will be used, | ||
// default is endpoints. | ||
ResolveGranularity string `json:"resolveGranularity"` | ||
} | ||
|
||
// ApisixRouteHTTPPlugin represents an APISIX plugin. | ||
type ApisixRouteHTTPPlugin struct { | ||
// The plugin name. | ||
Name string `json:"name"` | ||
// Whether this plugin is in use, default is true. | ||
Enable bool `json:"enable"` | ||
// Plugin configuration. | ||
// TODO we may use protobuf to define it. | ||
Config ApisixRouteHTTPPluginConfig | ||
} | ||
|
||
// ApisixRouteHTTPPluginConfig is the configuration for | ||
// any plugins. | ||
type ApisixRouteHTTPPluginConfig map[string]interface{} | ||
|
||
func (p ApisixRouteHTTPPluginConfig) DeepCopyInto(out *ApisixRouteHTTPPluginConfig) { | ||
b, _ := json.Marshal(&p) | ||
_ = json.Unmarshal(b, out) | ||
} | ||
|
||
func (p *ApisixRouteHTTPPluginConfig) DeepCopy() *ApisixRouteHTTPPluginConfig { | ||
if p == nil { | ||
return nil | ||
} | ||
out := new(ApisixRouteHTTPPluginConfig) | ||
p.DeepCopyInto(out) | ||
return out | ||
} | ||
|
||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
type ApisixRouteList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata"` | ||
Items []ApisixRoute `json:"items,omitempty"` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed earlier that we should keep the v1 version for a while, declare in the document "deprecated", and delete the logic of v1 in version 1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I forgot to set this PR to draft, the v1 ApisixRoute will be kept of course.