Skip to content

Commit b1ca121

Browse files
committed
add e2e case for ApisixRoute
1 parent bb679d0 commit b1ca121

25 files changed

Lines changed: 188 additions & 192 deletions

api/v2/apisixpluginconfig_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type ApisixPluginConfigSpec struct {
2828
}
2929

3030
// ApisixPluginConfigStatus defines the observed state of ApisixPluginConfig.
31-
type ApisixPluginConfigStatus ApisixStatus
31+
type ApisixPluginConfigStatus = ApisixStatus
3232

3333
// +kubebuilder:object:root=true
3434
// +kubebuilder:subresource:status

api/v2/apisixroute_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type ApisixRouteHTTP struct {
7272
// Upstreams refer to ApisixUpstream CRD
7373
Upstreams []ApisixRouteUpstreamReference `json:"upstreams,omitempty" yaml:"upstreams,omitempty"`
7474

75+
// +kubebuilder:validation:Optional
7576
Websocket bool `json:"websocket" yaml:"websocket"`
7677
PluginConfigName string `json:"plugin_config_name,omitempty" yaml:"plugin_config_name,omitempty"`
7778
// By default, PluginConfigNamespace will be the same as the namespace of ApisixRoute
@@ -159,6 +160,7 @@ type ApisixRouteHTTPBackend struct {
159160
// default is endpoints.
160161
ResolveGranularity string `json:"resolveGranularity,omitempty" yaml:"resolveGranularity,omitempty"`
161162
// Weight of this backend.
163+
// +kubebuilder:validation:Optional
162164
Weight *int `json:"weight" yaml:"weight"`
163165
// Subset specifies a subset for the target Service. The subset should be pre-defined
164166
// in ApisixUpstream about this service.

api/v2/groupversion_info.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package v2
1717

1818
import (
1919
"k8s.io/apimachinery/pkg/runtime/schema"
20+
"sigs.k8s.io/controller-runtime/pkg/client"
2021
"sigs.k8s.io/controller-runtime/pkg/scheme"
2122
)
2223

@@ -30,3 +31,12 @@ var (
3031
// AddToScheme adds the types in this group-version to the given scheme.
3132
AddToScheme = SchemeBuilder.AddToScheme
3233
)
34+
35+
func Is(obj client.Object) bool {
36+
switch obj.(type) {
37+
case *ApisixConsumer, *ApisixGlobalRule, *ApisixPluginConfig, *ApisixRoute, *ApisixTls, *ApisixUpstream:
38+
return obj.GetObjectKind().GroupVersionKind().GroupVersion() == GroupVersion
39+
default:
40+
return false
41+
}
42+
}

api/v2/reason.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

api/v2/shared_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ type (
2626
)
2727

2828
const (
29-
ApisixRouteConditionTypeAccepted ApisixRouteConditionType = gatewayv1.RouteConditionAccepted
30-
ApisixRouteConditionReasonAccepted ApisixRouteConditionReason = gatewayv1.RouteReasonAccepted
31-
ApisixRouteConditionReasonInvalidHTTP ApisixRouteConditionReason = "InvalidHTTP"
29+
ConditionTypeAccepted ApisixRouteConditionType = gatewayv1.RouteConditionAccepted
30+
ConditionReasonAccepted ApisixRouteConditionReason = gatewayv1.RouteReasonAccepted
31+
ConditionReasonInvalidSpec ApisixRouteConditionReason = "InvalidSpec"
32+
ConditionReasonSyncFailed ApisixRouteConditionReason = "SyncFailed"
3233
)
3334

3435
const (

api/v2/status.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,29 @@ package v2
1414

1515
import (
1616
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"sigs.k8s.io/controller-runtime/pkg/client"
1718
)
1819

1920
// ApisixStatus is the status report for Apisix ingress Resources
2021
type ApisixStatus struct {
2122
Conditions []metav1.Condition `json:"conditions,omitempty" yaml:"conditions,omitempty"`
2223
}
24+
25+
func GetStatus(object client.Object) ApisixStatus {
26+
switch t := object.(type) {
27+
case *ApisixConsumer:
28+
return t.Status
29+
case *ApisixGlobalRule:
30+
return t.Status
31+
case *ApisixPluginConfig:
32+
return t.Status
33+
case *ApisixRoute:
34+
return t.Status
35+
case *ApisixTls:
36+
return t.Status
37+
case *ApisixUpstream:
38+
return t.Status
39+
default:
40+
return ApisixStatus{}
41+
}
42+
}

api/v2/zz_generated.deepcopy.go

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

config/crd/bases/apisix.apache.org_apisixpluginconfigs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ spec:
7474
- plugins
7575
type: object
7676
status:
77-
description: ApisixPluginConfigStatus defines the observed state of ApisixPluginConfig.
77+
description: ApisixStatus is the status report for Apisix ingress Resources
7878
properties:
7979
conditions:
8080
items:

config/crd/bases/apisix.apache.org_apisixroutes.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ spec:
130130
required:
131131
- serviceName
132132
- servicePort
133-
- weight
134133
type: object
135134
type: array
136135
match:
@@ -303,7 +302,6 @@ spec:
303302
type: boolean
304303
required:
305304
- name
306-
- websocket
307305
type: object
308306
type: array
309307
ingressClassName:

internal/controller/apisixglobalrule_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ func (r *ApisixGlobalRuleReconciler) Reconcile(ctx context.Context, req ctrl.Req
9696
log.Error(err, "failed to sync global rule to provider")
9797
// Update status with failure condition
9898
r.updateStatus(&globalRule, metav1.Condition{
99-
Type: string(gatewayv1.RouteConditionAccepted),
99+
Type: string(apiv2.ConditionTypeAccepted),
100100
Status: metav1.ConditionFalse,
101101
ObservedGeneration: globalRule.Generation,
102102
LastTransitionTime: metav1.Now(),
103-
Reason: string(apiv2.ReasonSyncFailed),
103+
Reason: string(apiv2.ConditionReasonSyncFailed),
104104
Message: err.Error(),
105105
})
106106
return ctrl.Result{}, err

0 commit comments

Comments
 (0)