-
Notifications
You must be signed in to change notification settings - Fork 2
chore: Add CRD HTTPRoutePolicy #89
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
Merged
Merged
Changes from 3 commits
Commits
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
This file contains hidden or 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 hidden or 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 hidden or 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,64 @@ | ||
| // +kubebuilder:object:generate=true | ||
|
|
||
| package common | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| ) | ||
|
|
||
| // Vars represents the route match expressions of APISIX. | ||
| type Vars [][]StringOrSlice | ||
|
|
||
| // UnmarshalJSON implements json.Unmarshaler interface. | ||
| // lua-cjson doesn't distinguish empty array and table, | ||
| // and by default empty array will be encoded as '{}'. | ||
| // We have to maintain the compatibility. | ||
| func (vars *Vars) UnmarshalJSON(p []byte) error { | ||
| if p[0] == '{' { | ||
| if len(p) != 2 { | ||
| return errors.New("unexpected non-empty object") | ||
| } | ||
| return nil | ||
| } | ||
| var data [][]StringOrSlice | ||
| if err := json.Unmarshal(p, &data); err != nil { | ||
| return err | ||
| } | ||
| *vars = data | ||
| return nil | ||
| } | ||
|
|
||
| // StringOrSlice represents a string or a string slice. | ||
| // TODO Do not use interface{} to avoid the reflection overheads. | ||
| type StringOrSlice struct { | ||
| StrVal string `json:"-"` | ||
| SliceVal []string `json:"-"` | ||
| } | ||
|
|
||
| func (s *StringOrSlice) MarshalJSON() ([]byte, error) { | ||
| var ( | ||
| p []byte | ||
| err error | ||
| ) | ||
| if s.SliceVal != nil { | ||
| p, err = json.Marshal(s.SliceVal) | ||
| } else { | ||
| p, err = json.Marshal(s.StrVal) | ||
| } | ||
| return p, err | ||
| } | ||
|
|
||
| func (s *StringOrSlice) UnmarshalJSON(p []byte) error { | ||
| var err error | ||
|
|
||
| if len(p) == 0 { | ||
| return errors.New("empty object") | ||
| } | ||
| if p[0] == '[' { | ||
| err = json.Unmarshal(p, &s.SliceVal) | ||
| } else { | ||
| err = json.Unmarshal(p, &s.StrVal) | ||
| } | ||
| return err | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,73 @@ | ||
| /* | ||
| Copyright 2024. | ||
|
|
||
| Licensed 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 v1alpha1 | ||
|
|
||
| import ( | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
|
|
||
| "github.com/api7/api7-ingress-controller/api/common" | ||
| ) | ||
|
|
||
| // HTTPRoutePolicySpec defines the desired state of HTTPRoutePolicy. | ||
| type HTTPRoutePolicySpec struct { | ||
| // TargetRef identifies an API object (enum: HTTPRoute, Ingress) to apply HTTPRoutePolicy to. | ||
| // | ||
| // target references. | ||
| // +listType=map | ||
| // +listMapKey=group | ||
| // +listMapKey=kind | ||
| // +listMapKey=name | ||
| // +kubebuilder:validation:MinItems=1 | ||
| // +kubebuilder:validation:MaxItems=16 | ||
| TargetRefs []gatewayv1alpha2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"` | ||
|
|
||
| Policy HTTPRoutePolicySpecPolicy `json:"policy"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
AlinsRan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // HTTPRoutePolicy is the Schema for the httproutepolicies API. | ||
| type HTTPRoutePolicy struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
|
||
| Spec HTTPRoutePolicySpec `json:"spec,omitempty"` | ||
| Status gatewayv1alpha2.PolicyStatus `json:"status,omitempty"` | ||
| } | ||
|
|
||
| // +kubebuilder:object:root=true | ||
|
|
||
| // HTTPRoutePolicyList contains a list of HTTPRoutePolicy. | ||
| type HTTPRoutePolicyList struct { | ||
| metav1.TypeMeta `json:",inline"` | ||
| metav1.ListMeta `json:"metadata,omitempty"` | ||
| Items []HTTPRoutePolicy `json:"items"` | ||
| } | ||
|
|
||
| type HTTPRoutePolicySpecPolicy struct { | ||
| Priority *int64 `json:"priority,omitempty" yaml:"priority,omitempty"` | ||
| Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"` | ||
| } | ||
|
|
||
| // Vars represents the route match expressions of APISIX. | ||
| // +kubebuilder:object:generate=false | ||
| type Vars = common.Vars | ||
|
|
||
| func init() { | ||
| SchemeBuilder.Register(&HTTPRoutePolicy{}, &HTTPRoutePolicyList{}) | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.