tianxiaoliang commented on code in PR #1309: URL: https://github.com/apache/servicecomb-service-center/pull/1309#discussion_r910562743
########## istio/pkg/bootstrap/server.go: ########## @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package bootstrap + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/apache/servicecomb-service-center/istio/pkg/controllers/istio" + "github.com/apache/servicecomb-service-center/istio/pkg/controllers/service_center" + "github.com/apache/servicecomb-service-center/istio/pkg/event" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + "k8s.io/client-go/tools/leaderelection" + "k8s.io/client-go/tools/leaderelection/resourcelock" + + "istio.io/pkg/log" +) + +// cli args +type Args struct { + // servicecomb-service-center address + ServiceCenterAddr string + // kubeconfig file path + Kubeconfig string + // enable leader election or not for high abalibility + HA bool +} + +const ( + // leader election check locked resource namespace + lockNameSpace = "istio-system" + // leader election check locked resource name + resourceName = "servicecenter2mesh" + // LeaseDuration is the duration that non-leader candidates will + // wait to force acquire leadership. This is measured against time of + // last observed ack. + // + // A client needs to wait a full LeaseDuration without observing a change to + // the record before it can attempt to take over. When all clients are + // shutdown and a new set of clients are started with different names against + // the same leader record, they must wait the full LeaseDuration before + // attempting to acquire the lease. Thus LeaseDuration should be as short as + // possible (within your tolerance for clock skew rate) to avoid a possible + // long waits in the scenario. + // + // Core clients default this value to 15 seconds. + defaultLeaseDuration = 15 * time.Second + // RenewDeadline is the duration that the acting master will retry + // refreshing leadership before giving up. + // + // Core clients default this value to 10 seconds. + defaultRenewDeadline = 10 * time.Second + // RetryPeriod is the duration the LeaderElector clients should wait + // between tries of actions. + // + // Core clients default this value to 2 seconds. + defaultRetryPeriod = 2 * time.Second +) + +type Server struct { + // service center controller watches service center update, and push to istio controller + serviceCenterController *service_center.Controller + // istio controller receives updates from service center controller and push to k8s api server + istioController *istio.Controller Review Comment: istio.Controller leads missunderstanding please use istioConnector.Controller ########## istio/cmd/app/cmd.go: ########## @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package app + +import ( + "fmt" + "os" + "os/signal" + "syscall" + + "github.com/apache/servicecomb-service-center/istio/pkg/bootstrap" + + "github.com/spf13/cobra" + "istio.io/pkg/log" +) + +var inputArgs *bootstrap.Args +var loggingOptions = log.DefaultOptions() + +// NewRootCommand creates servicecomb-service-center-istio service cli args +func NewRootCommand() *cobra.Command { + rootCmd := &cobra.Command{ + Use: "servicecomb-service-center-to-istio", Review Comment: servicecomb-to-istio ########## istio/pkg/bootstrap/server.go: ########## @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package bootstrap + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/apache/servicecomb-service-center/istio/pkg/controllers/istio" Review Comment: istio/pkg/controllers/istio seems hard to stand your design, please use more specific pkg name ########## istio/pkg/bootstrap/server.go: ########## @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package bootstrap + +import ( + "context" + "fmt" + "os" + "time" + + "github.com/apache/servicecomb-service-center/istio/pkg/controllers/istio" + "github.com/apache/servicecomb-service-center/istio/pkg/controllers/service_center" + "github.com/apache/servicecomb-service-center/istio/pkg/event" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + "k8s.io/client-go/tools/leaderelection" + "k8s.io/client-go/tools/leaderelection/resourcelock" + + "istio.io/pkg/log" +) + +// cli args +type Args struct { + // servicecomb-service-center address + ServiceCenterAddr string + // kubeconfig file path + Kubeconfig string + // enable leader election or not for high abalibility + HA bool +} + +const ( + // leader election check locked resource namespace + lockNameSpace = "istio-system" + // leader election check locked resource name + resourceName = "servicecenter2mesh" + // LeaseDuration is the duration that non-leader candidates will + // wait to force acquire leadership. This is measured against time of + // last observed ack. + // + // A client needs to wait a full LeaseDuration without observing a change to + // the record before it can attempt to take over. When all clients are + // shutdown and a new set of clients are started with different names against + // the same leader record, they must wait the full LeaseDuration before + // attempting to acquire the lease. Thus LeaseDuration should be as short as + // possible (within your tolerance for clock skew rate) to avoid a possible + // long waits in the scenario. + // + // Core clients default this value to 15 seconds. + defaultLeaseDuration = 15 * time.Second + // RenewDeadline is the duration that the acting master will retry + // refreshing leadership before giving up. + // + // Core clients default this value to 10 seconds. + defaultRenewDeadline = 10 * time.Second + // RetryPeriod is the duration the LeaderElector clients should wait + // between tries of actions. + // + // Core clients default this value to 2 seconds. + defaultRetryPeriod = 2 * time.Second +) + +type Server struct { + // service center controller watches service center update, and push to istio controller + serviceCenterController *service_center.Controller Review Comment: service_center is bad naming convention -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
