4 Star 3 Fork 0

Gitee 极速下载/submariner

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/rancher/submariner
克隆/下载
main.go 5.12 KB
一键复制 编辑 原始数据 按行查看 历史
Tom Pantelis 提交于 2024-12-06 00:04 +08:00 . Remove wait-for-node-ready in GW and RA main
/*
SPDX-License-Identifier: Apache-2.0
Copyright Contributors to the Submariner project.
Licensed 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 main
import (
"flag"
"time"
"github.com/kelseyhightower/envconfig"
"github.com/submariner-io/admiral/pkg/http"
"github.com/submariner-io/admiral/pkg/log"
"github.com/submariner-io/admiral/pkg/log/kzerolog"
"github.com/submariner-io/admiral/pkg/names"
"github.com/submariner-io/admiral/pkg/syncer/broker"
"github.com/submariner-io/admiral/pkg/util"
admversion "github.com/submariner-io/admiral/pkg/version"
"github.com/submariner-io/admiral/pkg/watcher"
subv1 "github.com/submariner-io/submariner/pkg/apis/submariner.io/v1"
"github.com/submariner-io/submariner/pkg/cableengine"
submarinerClientset "github.com/submariner-io/submariner/pkg/client/clientset/versioned"
"github.com/submariner-io/submariner/pkg/gateway"
"github.com/submariner-io/submariner/pkg/natdiscovery"
"github.com/submariner-io/submariner/pkg/types"
"github.com/submariner-io/submariner/pkg/versions"
"golang.org/x/net/http/httpproxy"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
)
var (
localMasterURL string
localKubeconfig string
showVersion = false
logger = log.Logger{Logger: logf.Log.WithName("main")}
)
func init() {
flag.StringVar(&localKubeconfig, "kubeconfig", "", "Path to kubeconfig of local cluster. Only required if out-of-cluster.")
flag.StringVar(&localMasterURL, "master", "",
"The address of the Kubernetes API server. Overrides any value in kubeconfig. Only required if out-of-cluster.")
flag.BoolVar(&showVersion, "version", showVersion, "Show version")
}
type leaderConfig struct {
LeaseDuration int64
RenewDeadline int64
RetryPeriod int64
}
const leadershipConfigEnvPrefix = "leadership"
func main() {
kzerolog.AddFlags(nil)
flag.Parse()
admversion.Print(names.GatewayComponent, versions.Submariner())
if showVersion {
return
}
kzerolog.InitK8sLogging()
versions.Log(&logger)
gwLeadershipConfig := leaderConfig{}
logger.FatalfOnError(envconfig.Process(leadershipConfigEnvPrefix, &gwLeadershipConfig), "Error processing %s env vars",
leadershipConfigEnvPrefix)
submSpec := types.SubmarinerSpecification{}
logger.FatalOnError(envconfig.Process("submariner", &submSpec), "Error processing env vars")
logger.Infof("Parsed env variables: %#v", submSpec)
proxyEnv := httpproxy.FromEnvironment()
logger.Infof("Proxy env variables: HTTP_PROXY: %v, HTTPS_PROXY: %v, NO_PROXY: %v",
proxyEnv.HTTPProxy, proxyEnv.HTTPSProxy, proxyEnv.NoProxy)
defer http.StartServer(http.Metrics|http.Profile, submSpec.MetricsPort)()
var err error
util.AddCertificateErrorHandler(submSpec.HaltOnCertError)
restConfig, err := clientcmd.BuildConfigFromFlags(localMasterURL, localKubeconfig)
logger.FatalOnError(err, "Error building kubeconfig")
submarinerClient, err := submarinerClientset.NewForConfig(restConfig)
logger.FatalOnError(err, "Error creating submariner clientset")
k8sClient, err := kubernetes.NewForConfig(restConfig)
logger.FatalOnError(err, "Error creating Kubernetes clientset")
leClient, err := kubernetes.NewForConfig(rest.AddUserAgent(restConfig, "leader-election"))
logger.FatalOnError(err, "Error creating leader election kubernetes clientset")
dynClient, err := dynamic.NewForConfig(restConfig)
logger.FatalOnError(err, "Error creating dynamic client")
restMapper, err := util.BuildRestMapper(restConfig)
logger.FatalOnError(err, "Error building the REST mapper")
logger.FatalOnError(subv1.AddToScheme(scheme.Scheme), "Error adding submariner types to the scheme")
ctx := signals.SetupSignalHandler()
gw, err := gateway.New(ctx, &gateway.Config{
LeaderElectionConfig: gateway.LeaderElectionConfig{
LeaseDuration: time.Duration(gwLeadershipConfig.LeaseDuration) * time.Second,
RenewDeadline: time.Duration(gwLeadershipConfig.RenewDeadline) * time.Second,
RetryPeriod: time.Duration(gwLeadershipConfig.RetryPeriod) * time.Second,
},
Spec: submSpec,
SyncerConfig: broker.SyncerConfig{
LocalRestConfig: restConfig,
LocalClient: dynClient,
RestMapper: restMapper,
},
WatcherConfig: watcher.Config{
RestConfig: restConfig,
},
SubmarinerClient: submarinerClient,
KubeClient: k8sClient,
LeaderElectionClient: leClient,
NewCableEngine: cableengine.NewEngine,
NewNATDiscovery: natdiscovery.New,
})
logger.FatalOnError(err, "Error creating gateway instance")
err = gw.Run(ctx)
logger.FatalOnError(err, "Error running the gateway")
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mirrors/submariner.git
git@gitee.com:mirrors/submariner.git
mirrors
submariner
submariner
devel

搜索帮助