Skip to content

Commit 74546e8

Browse files
committed
issue fix and add some test cases
1 parent 14d26fc commit 74546e8

21 files changed

+554
-1293
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ vet: ## Run go vet against code.
6060
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
6161
test: fmt vet generate manifests ## Run tests.
6262
mkdir -p ${ENVTEST_ASSETS_DIR}
63-
source ./artifacts/scripts/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./pkg/... -p 1 -v -coverprofile cover.out
63+
source ./artifacts/scripts/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); go test ./pkg/... -coverprofile cover.out
6464

6565
##@ Build
6666

Diff for: config/crd/bases/ctrlmesh.kusionstack.io_faultinjections.yaml

+22-25
Original file line numberDiff line numberDiff line change
@@ -108,51 +108,48 @@ spec:
108108
description: Match specifies a set of criterion to be met in
109109
order for the rule to be applied to the HTTP request.
110110
properties:
111-
name:
112-
type: string
113-
relatedResources:
111+
httpMatch:
114112
items:
113+
description: HttpMatch specifies the criteria for matching
114+
HTTP requests to RESTful resources as part of HTTP FaultInjection.
115+
Each rule can target one or more URLs and HTTP methods.
115116
properties:
116-
apiGroups:
117+
method:
118+
description: 'Method specifies the http method of
119+
the request, like: PUT, POST, GET, DELETE.'
117120
items:
118121
type: string
119122
type: array
120-
namespaces:
123+
url:
124+
description: URL gives the location of the rest request,
125+
in standard URL form (`scheme://host:port/path`)
121126
items:
122127
type: string
123128
type: array
124-
resources:
129+
required:
130+
- method
131+
- url
132+
type: object
133+
type: array
134+
resources:
135+
items:
136+
properties:
137+
apiGroups:
125138
items:
126139
type: string
127140
type: array
128-
verbs:
141+
namespaces:
129142
items:
130143
type: string
131144
type: array
132-
type: object
133-
type: array
134-
restRules:
135-
items:
136-
description: MultiRestRule specifies the criteria for
137-
matching HTTP requests to RESTful resources as part
138-
of HTTP FaultInjection. Each rule can target one or
139-
more URLs and HTTP methods.
140-
properties:
141-
method:
142-
description: 'Method specifies the http method of
143-
the request, like: PUT, POST, GET, DELETE.'
145+
resources:
144146
items:
145147
type: string
146148
type: array
147-
url:
148-
description: URL gives the location of the rest request,
149-
in standard URL form (`scheme://host:port/path`)
149+
verbs:
150150
items:
151151
type: string
152152
type: array
153-
required:
154-
- method
155-
- url
156153
type: object
157154
type: array
158155
type: object

Diff for: pkg/apis/ctrlmesh/proto/faultinjection.pb.go

+100-115
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/apis/ctrlmesh/proto/faultinjection.proto

+6-12
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ message HTTPFaultInjection {
4040
// service, giving the impression that the upstream service is faulty.
4141
Abort abort = 2;
4242

43-
HTTPMatchRequest match = 3;
43+
Match match = 3;
4444

4545
string Name = 4;
4646

@@ -105,26 +105,20 @@ message EffectiveTimeRange {
105105

106106

107107

108-
message MultiRestRule {
108+
message HttpMatch {
109109
repeated string url = 1;
110110
repeated string method = 2;
111111
}
112112

113-
message HTTPMatchRequest {
114-
// The name assigned to a match. The match's name will be
115-
// concatenated with the parent route's name and will be logged in
116-
// the access logs for requests matching this route.
117-
string name = 1;
118-
119-
//
120-
repeated ResourceMatch relatedResources = 2;
121-
repeated MultiRestRule restRules = 3;
113+
message Match {
114+
repeated ResourceMatch resources = 1;
115+
repeated HttpMatch httpMatch = 2;
122116
}
123117

124118
// Describes how to match K8s resources.
125119
//
126120
// ```yaml
127-
// relatedResources:
121+
// resources:
128122
// - apiGroups:
129123
// - ""
130124
// namespaces:

Diff for: pkg/apis/ctrlmesh/proto/faultinjection_deepcopy.gen.go

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/apis/ctrlmesh/utils/conv/faultconv.go

+17-18
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020
"strconv"
2121
"time"
2222

23+
"google.golang.org/protobuf/types/known/durationpb"
24+
2325
ctrlmeshproto "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
2426
ctrlmeshv1alpha1 "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/v1alpha1"
2527
"github.com/KusionStack/controller-mesh/pkg/utils"
26-
"google.golang.org/protobuf/types/known/durationpb"
2728
)
2829

2930
func ConvertFaultInjection(faultInjection *ctrlmeshv1alpha1.FaultInjection) *ctrlmeshproto.FaultInjection {
@@ -84,33 +85,31 @@ func ConvertHTTPFaultInjection(faultInjection *ctrlmeshv1alpha1.HTTPFaultInjecti
8485
return protoFaultInjection
8586
}
8687

87-
func ConvertHTTPMatch(match *ctrlmeshv1alpha1.HTTPMatchRequest) *ctrlmeshproto.HTTPMatchRequest {
88-
httpMatchRequest := &ctrlmeshproto.HTTPMatchRequest{
89-
Name: match.Name,
90-
}
91-
if match.RestRules != nil {
92-
httpMatchRequest.RestRules = make([]*ctrlmeshproto.MultiRestRule, len(match.RestRules))
93-
for i, restRule := range match.RestRules {
94-
httpMatchRequest.RestRules[i] = &ctrlmeshproto.MultiRestRule{}
88+
func ConvertHTTPMatch(match *ctrlmeshv1alpha1.Match) *ctrlmeshproto.Match {
89+
Match := &ctrlmeshproto.Match{}
90+
if match.HttpMatch != nil {
91+
Match.HttpMatch = make([]*ctrlmeshproto.HttpMatch, len(match.HttpMatch))
92+
for i, restRule := range match.HttpMatch {
93+
Match.HttpMatch[i] = &ctrlmeshproto.HttpMatch{}
9594
if restRule.URL != nil {
96-
httpMatchRequest.RestRules[i].Url = make([]string, len(restRule.URL))
97-
copy(httpMatchRequest.RestRules[i].Url, restRule.URL)
95+
Match.HttpMatch[i].Url = make([]string, len(restRule.URL))
96+
copy(Match.HttpMatch[i].Url, restRule.URL)
9897
}
9998
if restRule.Method != nil {
100-
httpMatchRequest.RestRules[i].Method = make([]string, len(restRule.Method))
101-
copy(httpMatchRequest.RestRules[i].Method, restRule.Method)
99+
Match.HttpMatch[i].Method = make([]string, len(restRule.Method))
100+
copy(Match.HttpMatch[i].Method, restRule.Method)
102101
}
103102
}
104103
}
105-
if match.RelatedResources != nil {
106-
httpMatchRequest.RelatedResources = make([]*ctrlmeshproto.ResourceMatch, len(match.RelatedResources))
107-
for i, relatedResource := range match.RelatedResources {
104+
if match.Resources != nil {
105+
Match.Resources = make([]*ctrlmeshproto.ResourceMatch, len(match.Resources))
106+
for i, relatedResource := range match.Resources {
108107

109-
httpMatchRequest.RelatedResources[i] = ConvertRelatedResources(relatedResource)
108+
Match.Resources[i] = ConvertRelatedResources(relatedResource)
110109
}
111110

112111
}
113-
return httpMatchRequest
112+
return Match
114113
}
115114

116115
func ConvertEffectiveTime(timeRange *ctrlmeshv1alpha1.EffectiveTimeRange) *ctrlmeshproto.EffectiveTimeRange {

Diff for: pkg/apis/ctrlmesh/utils/http/request_util.go

-54
This file was deleted.

0 commit comments

Comments
 (0)