Skip to content

Commit fe7015a

Browse files
committed
add license and fix grpc client
1 parent 72f9a92 commit fe7015a

File tree

13 files changed

+170
-27
lines changed

13 files changed

+170
-27
lines changed

.licenserc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ header:
5757
- '.gitignore'
5858
- '.licenserc'
5959
- '**/zz_generated.deepcopy.go'
60+
- '**/*.connect.go'
6061
- '**/*.pb.go'
6162
- '**/*.proto'
63+
- '**/*.gen.go'
6264
comment: never
6365
license-location-threshold: 80

pkg/apis/ctrlmesh/proto/throtting_internal.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,29 @@ limitations under the License.
1515
*/
1616

1717
package proto
18+
19+
import (
20+
"context"
21+
"crypto/tls"
22+
"net"
23+
"net/http"
24+
"time"
25+
26+
"golang.org/x/net/http2"
27+
)
28+
29+
var (
30+
DefaultHttpClient = &http.Client{
31+
Transport: &http2.Transport{
32+
AllowHTTP: true,
33+
DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
34+
// TODO:
35+
// If you're also using this client for non-h2c traffic, you may want
36+
// to delegate to tls.Dial if the network isn't TCP or the addr isn't
37+
// in an allowlist.
38+
d := net.Dialer{Timeout: 5 * time.Second}
39+
return d.DialContext(ctx, network, addr)
40+
},
41+
},
42+
}
43+
)

pkg/utils/conv/convert.go renamed to pkg/apis/ctrlmesh/utils/conv/conv.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KusionStack 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+
117
package conv
218

319
import (

pkg/manager/controllers/circuitbreaker/cache.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KusionStack 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+
117
package circuitbreaker
218

319
import (

pkg/manager/controllers/circuitbreaker/circuitbreaker_controller.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ import (
2121
"errors"
2222
"flag"
2323
"fmt"
24-
"net/http"
2524
"os"
2625
"time"
2726

2827
"connectrpc.com/connect"
29-
"golang.org/x/net/http2"
3028
v1 "k8s.io/api/core/v1"
3129
"k8s.io/apimachinery/pkg/api/equality"
3230
k8sErr "k8s.io/apimachinery/pkg/api/errors"
@@ -45,9 +43,9 @@ import (
4543
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/constants"
4644
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
4745
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto/protoconnect"
46+
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/utils/conv"
4847
ctrlmeshv1alpha1 "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/v1alpha1"
4948
"github.com/KusionStack/controller-mesh/pkg/utils"
50-
"github.com/KusionStack/controller-mesh/pkg/utils/conv"
5149
)
5250

5351
var (
@@ -56,12 +54,6 @@ var (
5654

5755
defaultRequeueTime = 60 * time.Second
5856
concurrentReconciles = flag.Int("ctrlmesh-server-workers", 3, "Max concurrent workers for CtrlMesh Server controller.")
59-
60-
defaultHttpClient = &http.Client{
61-
Transport: &http2.Transport{
62-
AllowHTTP: true,
63-
},
64-
}
6557
)
6658

6759
// CircuitBreakerReconciler reconciles a CircuitBreaker object
@@ -288,11 +280,11 @@ func (r *CircuitBreakerReconciler) disableConfig(ctx context.Context, podIp stri
288280
}
289281

290282
func protoClient(podIp string) protoconnect.ThrottlingClient {
291-
return protoconnect.NewThrottlingClient(defaultHttpClient, podAddr(podIp))
283+
return protoconnect.NewThrottlingClient(proto.DefaultHttpClient, podAddr(podIp))
292284
}
293285

294286
func podAddr(podIp string) string {
295-
return fmt.Sprintf("%s:%d", podIp, constants.ProxyGRPCServerPort)
287+
return fmt.Sprintf("https://%s:%d", podIp, constants.ProxyGRPCServerPort)
296288
}
297289

298290
func isProxyAvailable(po *v1.Pod) bool {

pkg/manager/controllers/circuitbreaker/event_handler.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KusionStack 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+
117
package circuitbreaker
218

319
import (

pkg/manager/controllers/circuitbreaker/filter.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
/*
2+
Copyright 2023 The KusionStack 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+
117
package circuitbreaker
218

319
import (
420
"sigs.k8s.io/controller-runtime/pkg/event"
521

22+
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/utils/conv"
623
ctrlmeshv1alpha1 "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/v1alpha1"
7-
"github.com/KusionStack/controller-mesh/pkg/utils/conv"
824
)
925

1026
type BreakerPredicate struct {
@@ -17,9 +33,6 @@ func (b *BreakerPredicate) Create(event.CreateEvent) bool {
1733

1834
// Delete returns true if the Delete event should be processed
1935
func (b *BreakerPredicate) Delete(e event.DeleteEvent) bool {
20-
cb := e.Object.(*ctrlmeshv1alpha1.CircuitBreaker)
21-
protoCB := conv.ConvertCircuitBreaker(cb)
22-
defaultHashCache.DeleteHash(protoCB.ConfigHash)
2336
return true
2437
}
2538

@@ -30,7 +43,6 @@ func (b *BreakerPredicate) Update(e event.UpdateEvent) bool {
3043
oldProtoCB := conv.ConvertCircuitBreaker(oldCB)
3144
newProtoCB := conv.ConvertCircuitBreaker(newCB)
3245
if oldProtoCB.ConfigHash != newProtoCB.ConfigHash {
33-
defaultHashCache.DeleteHash(oldProtoCB.ConfigHash)
3446
return true
3547
}
3648
if newCB.DeletionTimestamp != nil {

pkg/proxy/cache/informer.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2023 The KusionStack 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+
117
package cache
218

319
import (

pkg/proxy/circuitbreaker/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2929

3030
ctrlmeshproto "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
31+
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/utils/conv"
3132
ctrlmeshv1alpha1 "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/v1alpha1"
32-
"github.com/KusionStack/controller-mesh/pkg/utils/conv"
3333
)
3434

3535
func init() {

pkg/proxy/circuitbreaker/store_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ import (
2727
"sigs.k8s.io/controller-runtime/pkg/log/zap"
2828

2929
ctrlmeshproto "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
30+
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/utils/conv"
3031
ctrlmeshv1alpha1 "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/v1alpha1"
31-
"github.com/KusionStack/controller-mesh/pkg/utils/conv"
3232
)
3333

3434
func init() {

0 commit comments

Comments
 (0)