Skip to content

Commit 3981a95

Browse files
committed
fix:delete snapshot
1 parent 4a7aeef commit 3981a95

21 files changed

+1247
-601
lines changed

config/crd/bases/ctrlmesh.kusionstack.io_faultinjections.yaml

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ spec:
5151
httpStatus:
5252
description: HttpStatus is used to indicate the HTTP status
5353
code to return to the caller.
54-
format: int32
5554
type: integer
5655
percent:
5756
description: Percent of requests to be aborted with the

pkg/apis/ctrlmesh/constants/constants.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const (
6666
EnvDisableFaultInjection = "DISABLE_FAULT_INJECTION"
6767
EnvEnableApiServerCircuitBreaker = "ENABLE_API_SERVER_BREAKER"
6868
EnvEnableRestCircuitBreaker = "ENABLE_REST_BREAKER"
69-
EnvEnableRestFaultInjection = "ENABLE_REST_Fault_Injection"
69+
EnvEnableRestFaultInjection = "ENABLE_REST_FAULT_INJECTION"
7070

7171
EnvProxyGRPCServerPort = "PROXY_GRPC_SERVER_PORT"
7272
)
@@ -79,6 +79,7 @@ func AllProxySyncEnvKey() []string {
7979
EnvDisableCircuitBreaker,
8080
EnvEnableApiServerCircuitBreaker,
8181
EnvEnableRestCircuitBreaker,
82+
EnvEnableRestFaultInjection,
8283
}
8384
return keys
8485
}

pkg/apis/ctrlmesh/proto/faultinjection.pb.go

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

pkg/apis/ctrlmesh/proto/faultinjection.proto

-10
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ service FaultInject {
1515
message FaultInjectConfigResp {
1616
bool success = 1;
1717
string message = 2;
18-
repeated FaultInjectionSnapshot faultInjectionSnapshots = 3;
19-
}
20-
21-
message FaultInjectionSnapshot {
22-
string limitingName = 1;
23-
24-
FaultInjectionState state = 2;
25-
26-
k8s.io.apimachinery.pkg.apis.meta.v1.Time recoverTime = 3;
27-
k8s.io.apimachinery.pkg.apis.meta.v1.Time lastTransitionTime = 4;
2818
}
2919

3020
enum FaultInjectionState {

pkg/apis/ctrlmesh/proto/faultinjection_deepcopy.gen.go

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

pkg/apis/ctrlmesh/utils/conv/faultconv.go

-18
Original file line numberDiff line numberDiff line change
@@ -162,21 +162,3 @@ func ConvertRelatedResources(resourceRule *ctrlmeshv1alpha1.ResourceMatch) *ctrl
162162
return protoResourceRule
163163
}
164164

165-
func ConvertFaultInjectionSnapshots(in []*ctrlmeshproto.FaultInjectionSnapshot) []*ctrlmeshv1alpha1.FaultInjectionSnapshot {
166-
var res []*ctrlmeshv1alpha1.FaultInjectionSnapshot
167-
for _, s := range in {
168-
var state ctrlmeshv1alpha1.FaultInjectionState
169-
switch s.State {
170-
case ctrlmeshproto.FaultInjectionState_STATEOPENED:
171-
state = ctrlmeshv1alpha1.FaultInjectionStatusOpened
172-
case ctrlmeshproto.FaultInjectionState_STATECLOSED:
173-
state = ctrlmeshv1alpha1.FaultInjectionStatusClosed
174-
}
175-
res = append(res, &ctrlmeshv1alpha1.FaultInjectionSnapshot{
176-
Name: s.LimitingName,
177-
State: state,
178-
LastTransitionTime: s.LastTransitionTime,
179-
})
180-
}
181-
return res
182-
}

pkg/apis/ctrlmesh/utils/errors.go

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Copyright 2021 The Kruise Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package utils
18+
19+
import "fmt"
20+
21+
type HashChangedError struct {
22+
oldHash string
23+
newHash string
24+
}
25+
26+
func (e HashChangedError) Error() string {
27+
return e.String()
28+
}
29+
30+
func (e HashChangedError) String() string {
31+
return fmt.Sprintf("hash changed from %s to %s", e.oldHash, e.newHash)
32+
}
33+
34+
func IsHashChangedError(err error) bool {
35+
switch err.(type) {
36+
case HashChangedError:
37+
return true
38+
}
39+
return false
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package http
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
func ParseRawQuery(rawQuery string) (map[string]string, error) {
9+
result := map[string]string{}
10+
if rawQuery == "" {
11+
return result, nil
12+
}
13+
14+
pairs := strings.Split(rawQuery, "&")
15+
for _, pair := range pairs {
16+
kv := strings.Split(pair, "=")
17+
if len(kv) != 2 {
18+
return result, fmt.Errorf("invalid url query: %s", rawQuery)
19+
}
20+
21+
result[kv[0]] = kv[1]
22+
}
23+
24+
return result, nil
25+
}
26+
27+
func MarshalRawQuery(queryParm map[string]string) string {
28+
result := ""
29+
for k, v := range queryParm {
30+
if len(result) == 0 {
31+
result = result + fmt.Sprintf("%s=%s", k, v)
32+
} else {
33+
result = result + "&" + fmt.Sprintf("%s=%s", k, v)
34+
}
35+
}
36+
37+
return result
38+
}

0 commit comments

Comments
 (0)