Skip to content

Commit bb35637

Browse files
committed
update github action and makefile (supprot buf install)
1 parent 3bd9957 commit bb35637

File tree

10 files changed

+2227
-105
lines changed

10 files changed

+2227
-105
lines changed

.github/workflows/check.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ jobs:
3333
run: |
3434
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.5/protoc-3.19.5-linux-x86_64.zip
3535
unzip protoc-3.19.5-linux-x86_64.zip -d protoc3
36+
rm -rf protoc-3.19.5-linux-x86_64.zip
37+
- name: Setup Buf
38+
run: |
39+
GO111MODULE=on GOBIN=/usr/local/bin go install github.com/bufbuild/buf/cmd/[email protected]
40+
GO111MODULE=on GOBIN=/usr/local/bin go install ./tools/protoc-gen-golang-deepcopy
3641
- name: Cache Go Dependencies
3742
uses: actions/cache@v2
3843
with:
@@ -42,9 +47,9 @@ jobs:
4247
- name: Run Unit Tests
4348
run: |
4449
export PATH="$PATH:$(pwd)/protoc3/bin"
50+
ls $(pwd)
4551
echo $PATH
4652
make test
47-
rm -rf protoc-3.19.5-linux-x86_64.zip
4853
rm -rf protoc3
4954
git status
5055
# TODO: enable after public

.github/workflows/release.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ jobs:
2828
run: |
2929
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.5/protoc-3.19.5-linux-x86_64.zip
3030
unzip protoc-3.19.5-linux-x86_64.zip -d protoc3
31+
rm -rf protoc-3.19.5-linux-x86_64.zip
32+
- name: Setup Buf
33+
run: |
34+
GO111MODULE=on GOBIN=/usr/local/bin go install github.com/bufbuild/buf/cmd/[email protected]
35+
GO111MODULE=on GOBIN=/usr/local/bin go install ./tools/protoc-gen-golang-deepcopy
3136
- name: Cache Go Dependencies
3237
uses: actions/cache@v2
3338
with:
@@ -39,7 +44,6 @@ jobs:
3944
export PATH="$PATH:$(pwd)/protoc3/bin"
4045
echo $PATH
4146
make test
42-
rm -rf protoc-3.19.5-linux-x86_64.zip
4347
rm -rf protoc3
4448
git status
4549

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ generate-client: controller-gen ## Generate code containing DeepCopy, DeepCopyIn
4545
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4646

4747
generate-protobuf: controller-gen ## Generate protobuf code.
48-
@artifacts/scripts/generate_protobuf.sh
48+
#@artifacts/scripts/generate_protobuf.sh
49+
buf generate --path pkg
4950
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
5051

5152
generate: generate-client generate-protobuf

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

+83-101
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,22 @@ spec:
6868
properties:
6969
additionalProperties:
7070
type: string
71-
description: 'Properties defines the additional properties of
72-
the policy, like: SleepingWindowSize'
71+
description: 'ValidatePolicy determine the opportunity to validate
72+
req ValidatePolicy ValidatePolicy `json:"validatePolicy,omitempty"`
73+
Properties defines the additional properties of the policy,
74+
like: SleepingWindowSize'
7375
type: object
7476
recoverPolicy:
7577
description: RecoverPolicy defines how the circuit-breaking
7678
policy recovered from 'Opened' to 'Closed'
77-
type: string
79+
properties:
80+
sleepingWindowSize:
81+
type: string
82+
type:
83+
type: string
84+
required:
85+
- type
86+
type: object
7887
resourceRules:
7988
description: ResourceRules defines the target k8s resource of
8089
the limiting policy
@@ -143,10 +152,6 @@ spec:
143152
description: TriggerPolicy defines how the circuit-breaking
144153
policy triggered from 'Closed' to 'Opened'
145154
type: string
146-
validatePolicy:
147-
description: ValidatePolicy determine the opportunity to validate
148-
req
149-
type: string
150155
required:
151156
- bucket
152157
- name
@@ -157,59 +162,48 @@ spec:
157162
selector:
158163
description: Selector is a label query over pods of this application.
159164
properties:
160-
labelSelector:
161-
description: A label selector is a label query over a set of resources.
162-
The result of matchLabels and matchExpressions are ANDed. An
163-
empty label selector matches all objects. A null label selector
164-
matches no objects.
165-
properties:
166-
matchExpressions:
167-
description: matchExpressions is a list of label selector
168-
requirements. The requirements are ANDed.
169-
items:
170-
description: A label selector requirement is a selector
171-
that contains values, a key, and an operator that relates
172-
the key and values.
173-
properties:
174-
key:
175-
description: key is the label key that the selector
176-
applies to.
177-
type: string
178-
operator:
179-
description: operator represents a key's relationship
180-
to a set of values. Valid operators are In, NotIn,
181-
Exists and DoesNotExist.
182-
type: string
183-
values:
184-
description: values is an array of string values. If
185-
the operator is In or NotIn, the values array must
186-
be non-empty. If the operator is Exists or DoesNotExist,
187-
the values array must be empty. This array is replaced
188-
during a strategic merge patch.
189-
items:
190-
type: string
191-
type: array
192-
required:
193-
- key
194-
- operator
195-
type: object
196-
type: array
197-
matchLabels:
198-
additionalProperties:
199-
type: string
200-
description: matchLabels is a map of {key,value} pairs. A
201-
single {key,value} in the matchLabels map is equivalent
202-
to an element of matchExpressions, whose key field is "key",
203-
the operator is "In", and the values array contains only
204-
"value". The requirements are ANDed.
205-
type: object
206-
type: object
207-
x-kubernetes-map-type: atomic
208-
targets:
165+
matchExpressions:
166+
description: matchExpressions is a list of label selector requirements.
167+
The requirements are ANDed.
209168
items:
210-
type: string
169+
description: A label selector requirement is a selector that
170+
contains values, a key, and an operator that relates the key
171+
and values.
172+
properties:
173+
key:
174+
description: key is the label key that the selector applies
175+
to.
176+
type: string
177+
operator:
178+
description: operator represents a key's relationship to
179+
a set of values. Valid operators are In, NotIn, Exists
180+
and DoesNotExist.
181+
type: string
182+
values:
183+
description: values is an array of string values. If the
184+
operator is In or NotIn, the values array must be non-empty.
185+
If the operator is Exists or DoesNotExist, the values
186+
array must be empty. This array is replaced during a strategic
187+
merge patch.
188+
items:
189+
type: string
190+
type: array
191+
required:
192+
- key
193+
- operator
194+
type: object
211195
type: array
196+
matchLabels:
197+
additionalProperties:
198+
type: string
199+
description: matchLabels is a map of {key,value} pairs. A single
200+
{key,value} in the matchLabels map is equivalent to an element
201+
of matchExpressions, whose key field is "key", the operator
202+
is "In", and the values array contains only "value". The requirements
203+
are ANDed.
204+
type: object
212205
type: object
206+
x-kubernetes-map-type: atomic
213207
trafficInterceptRules:
214208
description: TrafficInterceptRules defines the traffic rules
215209
items:
@@ -247,66 +241,54 @@ spec:
247241
type: object
248242
type: array
249243
required:
250-
- rateLimitings
244+
- selector
251245
type: object
252246
status:
253247
description: CircuitBreakerStatus defines the observed state of CircuitBreaker
254248
properties:
249+
currentSpecHash:
250+
type: string
255251
lastUpdatedTime:
256252
format: date-time
257253
type: string
258-
limitingSnapshots:
254+
observedGeneration:
255+
format: int64
256+
type: integer
257+
targetStatus:
259258
items:
260-
description: LimitingSnapshot defines the snapshot of the whole
261-
limiting policy
262259
properties:
263-
bucket:
264-
description: Bucket defines the whole snapshot of the token
265-
bucket
266-
properties:
267-
availableTokens:
268-
description: AvailableTokens defines the rest tokens of
269-
the bucket.
270-
format: int64
271-
type: integer
272-
lastAcquireTimestamp:
273-
description: LastAcquireTimestamp is the unix timestamp
274-
that the last token(s) were acquired.
275-
format: int64
276-
type: integer
277-
required:
278-
- availableTokens
279-
- lastAcquireTimestamp
280-
type: object
281-
endpoint:
282-
description: Endpoint specifies the users who use this rule
260+
configHash:
283261
type: string
284-
lastTransitionTime:
285-
description: LastTransitionTime is the last time that the status
286-
changed
287-
format: date-time
262+
limitingSnapshots:
263+
items:
264+
description: LimitingSnapshot defines the snapshot of the
265+
whole limiting policy
266+
properties:
267+
lastTransitionTime:
268+
description: LastTransitionTime is the last time that
269+
the status changed
270+
format: date-time
271+
type: string
272+
name:
273+
description: Name specifies the name of the policy
274+
type: string
275+
state:
276+
description: Status is the status of the circuit breaker,
277+
which may be 'Opened' or 'Closed'.
278+
type: string
279+
required:
280+
- name
281+
- state
282+
type: object
283+
type: array
284+
message:
288285
type: string
289-
name:
290-
description: Name specifies the name of the policy
286+
podIP:
291287
type: string
292288
podName:
293-
description: PodName specifies the users pod name
294-
type: string
295-
status:
296-
description: Status is the status of the circuit breaker, which
297-
may be 'Opened' or 'Closed'.
298289
type: string
299-
required:
300-
- bucket
301-
- name
302-
- status
303290
type: object
304291
type: array
305-
observedGeneration:
306-
format: int64
307-
type: integer
308-
required:
309-
- limitingSnapshots
310292
type: object
311293
type: object
312294
served: true

pkg/proxy/grpcserver/server_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"testing"
23+
"time"
2324

2425
"connectrpc.com/connect"
2526
"github.com/onsi/gomega"
@@ -39,7 +40,7 @@ func TestServer(t *testing.T) {
3940
breakerMgr := circuitbreaker.NewManager(ctx)
4041
proxyServer := &GrpcServer{BreakerMgr: breakerMgr}
4142
go proxyServer.Start(ctx)
42-
43+
<-time.After(2 * time.Second)
4344
fmt.Println(proto.TrafficInterceptRule_NORMAL.String())
4445
grpcClient := protoconnect.NewThrottlingClient(proto.DefaultHttpClient, "http://127.0.0.1:8889")
4546

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build:
2+
go install .
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2019 Istio Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"google.golang.org/protobuf/compiler/protogen"
19+
"google.golang.org/protobuf/types/descriptorpb"
20+
)
21+
22+
func main() {
23+
protogen.Options{}.Run(func(gen *protogen.Plugin) error {
24+
for _, f := range gen.Files {
25+
if !f.Generate {
26+
continue
27+
}
28+
generateFile(gen, f)
29+
}
30+
return nil
31+
})
32+
}
33+
34+
func generateFile(gen *protogen.Plugin, file *protogen.File) {
35+
filename := file.GeneratedFilenamePrefix + "_deepcopy.gen.go"
36+
p := gen.NewGeneratedFile(filename, file.GoImportPath)
37+
38+
protoIdent := protogen.GoIdent{
39+
GoName: "Clone",
40+
GoImportPath: "google.golang.org/protobuf/proto",
41+
}
42+
p.P("// Code generated by protoc-gen-deepcopy. DO NOT EDIT.")
43+
p.P("package ", file.GoPackageName)
44+
var process func([]*protogen.Message)
45+
46+
process = func(messages []*protogen.Message) {
47+
for _, message := range messages {
48+
// skip maps in protos.
49+
if message.Desc.Options().(*descriptorpb.MessageOptions).GetMapEntry() {
50+
continue
51+
}
52+
typeName := message.GoIdent.GoName
53+
// Generate DeepCopyInto() method for this type
54+
p.P(`// DeepCopyInto supports using `, typeName, ` within kubernetes types, where deepcopy-gen is used.`)
55+
p.P(`func (in *`, typeName, `) DeepCopyInto(out *`, typeName, `) {`)
56+
p.P(`p := `, protoIdent, `(in).(*`, typeName, `)`)
57+
p.P(`*out = *p`)
58+
p.P(`}`)
59+
60+
// Generate DeepCopy() method for this type
61+
p.P(`// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new `, typeName, `. Required by controller-gen.`)
62+
p.P(`func (in *`, typeName, `) DeepCopy() *`, typeName, ` {`)
63+
p.P(`if in == nil { return nil }`)
64+
p.P(`out := new(`, typeName, `)`)
65+
p.P(`in.DeepCopyInto(out)`)
66+
p.P(`return out`)
67+
p.P(`}`)
68+
69+
// Generate DeepCopyInterface() method for this type
70+
p.P(`// DeepCopyInterface is an autogenerated deepcopy function, copying the receiver, creating a new `, typeName, `. Required by controller-gen.`)
71+
p.P(`func (in *`, typeName, `) DeepCopyInterface() interface{} {`)
72+
p.P(`return in.DeepCopy()`)
73+
p.P(`}`)
74+
process(message.Messages)
75+
}
76+
}
77+
process(file.Messages)
78+
}

0 commit comments

Comments
 (0)