only run virtualservice and destinationrule controller when servicemesh is enabled (#2243)
This commit is contained in:
@@ -63,6 +63,7 @@ func addControllers(
|
|||||||
openpitrixClient openpitrix.Client,
|
openpitrixClient openpitrix.Client,
|
||||||
multiClusterEnabled bool,
|
multiClusterEnabled bool,
|
||||||
networkPolicyEnabled bool,
|
networkPolicyEnabled bool,
|
||||||
|
serviceMeshEnabled bool,
|
||||||
stopCh <-chan struct{}) error {
|
stopCh <-chan struct{}) error {
|
||||||
|
|
||||||
kubernetesInformer := informerFactory.KubernetesSharedInformerFactory()
|
kubernetesInformer := informerFactory.KubernetesSharedInformerFactory()
|
||||||
@@ -70,21 +71,24 @@ func addControllers(
|
|||||||
kubesphereInformer := informerFactory.KubeSphereSharedInformerFactory()
|
kubesphereInformer := informerFactory.KubeSphereSharedInformerFactory()
|
||||||
applicationInformer := informerFactory.ApplicationSharedInformerFactory()
|
applicationInformer := informerFactory.ApplicationSharedInformerFactory()
|
||||||
|
|
||||||
vsController := virtualservice.NewVirtualServiceController(kubernetesInformer.Core().V1().Services(),
|
var vsController, drController manager.Runnable
|
||||||
istioInformer.Networking().V1alpha3().VirtualServices(),
|
if serviceMeshEnabled {
|
||||||
istioInformer.Networking().V1alpha3().DestinationRules(),
|
vsController = virtualservice.NewVirtualServiceController(kubernetesInformer.Core().V1().Services(),
|
||||||
kubesphereInformer.Servicemesh().V1alpha2().Strategies(),
|
istioInformer.Networking().V1alpha3().VirtualServices(),
|
||||||
client.Kubernetes(),
|
istioInformer.Networking().V1alpha3().DestinationRules(),
|
||||||
client.Istio(),
|
kubesphereInformer.Servicemesh().V1alpha2().Strategies(),
|
||||||
client.KubeSphere())
|
client.Kubernetes(),
|
||||||
|
client.Istio(),
|
||||||
|
client.KubeSphere())
|
||||||
|
|
||||||
drController := destinationrule.NewDestinationRuleController(kubernetesInformer.Apps().V1().Deployments(),
|
drController = destinationrule.NewDestinationRuleController(kubernetesInformer.Apps().V1().Deployments(),
|
||||||
istioInformer.Networking().V1alpha3().DestinationRules(),
|
istioInformer.Networking().V1alpha3().DestinationRules(),
|
||||||
kubernetesInformer.Core().V1().Services(),
|
kubernetesInformer.Core().V1().Services(),
|
||||||
kubesphereInformer.Servicemesh().V1alpha2().ServicePolicies(),
|
kubesphereInformer.Servicemesh().V1alpha2().ServicePolicies(),
|
||||||
client.Kubernetes(),
|
client.Kubernetes(),
|
||||||
client.Istio(),
|
client.Istio(),
|
||||||
client.KubeSphere())
|
client.KubeSphere())
|
||||||
|
}
|
||||||
|
|
||||||
apController := application.NewApplicationController(kubernetesInformer.Core().V1().Services(),
|
apController := application.NewApplicationController(kubernetesInformer.Core().V1().Services(),
|
||||||
kubernetesInformer.Apps().V1().Deployments(),
|
kubernetesInformer.Apps().V1().Deployments(),
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ import (
|
|||||||
"k8s.io/client-go/tools/leaderelection"
|
"k8s.io/client-go/tools/leaderelection"
|
||||||
cliflag "k8s.io/component-base/cli/flag"
|
cliflag "k8s.io/component-base/cli/flag"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
kubesphereconfig "kubesphere.io/kubesphere/pkg/apiserver/config"
|
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
|
"kubesphere.io/kubesphere/pkg/simple/client/devops/jenkins"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
"kubesphere.io/kubesphere/pkg/simple/client/k8s"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/multicluster"
|
"kubesphere.io/kubesphere/pkg/simple/client/multicluster"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/network"
|
"kubesphere.io/kubesphere/pkg/simple/client/network"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||||
"kubesphere.io/kubesphere/pkg/simple/client/s3"
|
"kubesphere.io/kubesphere/pkg/simple/client/s3"
|
||||||
|
"kubesphere.io/kubesphere/pkg/simple/client/servicemesh"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -24,6 +24,7 @@ type KubeSphereControllerManagerOptions struct {
|
|||||||
OpenPitrixOptions *openpitrix.Options
|
OpenPitrixOptions *openpitrix.Options
|
||||||
NetworkOptions *network.Options
|
NetworkOptions *network.Options
|
||||||
MultiClusterOptions *multicluster.Options
|
MultiClusterOptions *multicluster.Options
|
||||||
|
ServiceMeshOptions *servicemesh.Options
|
||||||
LeaderElect bool
|
LeaderElect bool
|
||||||
LeaderElection *leaderelection.LeaderElectionConfig
|
LeaderElection *leaderelection.LeaderElectionConfig
|
||||||
WebhookCertDir string
|
WebhookCertDir string
|
||||||
@@ -37,6 +38,7 @@ func NewKubeSphereControllerManagerOptions() *KubeSphereControllerManagerOptions
|
|||||||
OpenPitrixOptions: openpitrix.NewOptions(),
|
OpenPitrixOptions: openpitrix.NewOptions(),
|
||||||
NetworkOptions: network.NewNetworkOptions(),
|
NetworkOptions: network.NewNetworkOptions(),
|
||||||
MultiClusterOptions: multicluster.NewOptions(),
|
MultiClusterOptions: multicluster.NewOptions(),
|
||||||
|
ServiceMeshOptions: servicemesh.NewServiceMeshOptions(),
|
||||||
LeaderElection: &leaderelection.LeaderElectionConfig{
|
LeaderElection: &leaderelection.LeaderElectionConfig{
|
||||||
LeaseDuration: 30 * time.Second,
|
LeaseDuration: 30 * time.Second,
|
||||||
RenewDeadline: 15 * time.Second,
|
RenewDeadline: 15 * time.Second,
|
||||||
@@ -49,13 +51,6 @@ func NewKubeSphereControllerManagerOptions() *KubeSphereControllerManagerOptions
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *KubeSphereControllerManagerOptions) ApplyTo(conf *kubesphereconfig.Config) {
|
|
||||||
s.S3Options.ApplyTo(conf.S3Options)
|
|
||||||
s.KubernetesOptions.ApplyTo(conf.KubernetesOptions)
|
|
||||||
s.DevopsOptions.ApplyTo(conf.DevopsOptions)
|
|
||||||
s.OpenPitrixOptions.ApplyTo(conf.OpenPitrixOptions)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
|
func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
|
||||||
fss := cliflag.NamedFlagSets{}
|
fss := cliflag.NamedFlagSets{}
|
||||||
|
|
||||||
@@ -65,6 +60,7 @@ func (s *KubeSphereControllerManagerOptions) Flags() cliflag.NamedFlagSets {
|
|||||||
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"), s.OpenPitrixOptions)
|
s.OpenPitrixOptions.AddFlags(fss.FlagSet("openpitrix"), s.OpenPitrixOptions)
|
||||||
s.NetworkOptions.AddFlags(fss.FlagSet("network"), s.NetworkOptions)
|
s.NetworkOptions.AddFlags(fss.FlagSet("network"), s.NetworkOptions)
|
||||||
s.MultiClusterOptions.AddFlags(fss.FlagSet("multicluster"), s.MultiClusterOptions)
|
s.MultiClusterOptions.AddFlags(fss.FlagSet("multicluster"), s.MultiClusterOptions)
|
||||||
|
s.ServiceMeshOptions.AddFlags(fss.FlagSet("servicemesh"), s.ServiceMeshOptions)
|
||||||
|
|
||||||
fs := fss.FlagSet("leaderelection")
|
fs := fss.FlagSet("leaderelection")
|
||||||
s.bindLeaderElectionFlags(s.LeaderElection, fs)
|
s.bindLeaderElectionFlags(s.LeaderElection, fs)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ func NewControllerManagerCommand() *cobra.Command {
|
|||||||
OpenPitrixOptions: conf.OpenPitrixOptions,
|
OpenPitrixOptions: conf.OpenPitrixOptions,
|
||||||
NetworkOptions: conf.NetworkOptions,
|
NetworkOptions: conf.NetworkOptions,
|
||||||
MultiClusterOptions: conf.MultiClusterOptions,
|
MultiClusterOptions: conf.MultiClusterOptions,
|
||||||
|
ServiceMeshOptions: conf.ServiceMeshOptions,
|
||||||
LeaderElection: s.LeaderElection,
|
LeaderElection: s.LeaderElection,
|
||||||
LeaderElect: s.LeaderElect,
|
LeaderElect: s.LeaderElect,
|
||||||
}
|
}
|
||||||
@@ -157,7 +158,9 @@ func Run(s *options.KubeSphereControllerManagerOptions, stopCh <-chan struct{})
|
|||||||
klog.Fatal("Unable to create namespace controller")
|
klog.Fatal("Unable to create namespace controller")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := addControllers(mgr, kubernetesClient, informerFactory, devopsClient, s3Client, openpitrixClient, s.MultiClusterOptions.Enable, s.NetworkOptions.EnableNetworkPolicy, stopCh); err != nil {
|
// TODO(jeff): refactor config with CRD
|
||||||
|
servicemeshEnabled := s.ServiceMeshOptions != nil && len(s.ServiceMeshOptions.IstioPilotHost) != 0
|
||||||
|
if err = addControllers(mgr, kubernetesClient, informerFactory, devopsClient, s3Client, openpitrixClient, s.MultiClusterOptions.Enable, s.NetworkOptions.EnableNetworkPolicy, servicemeshEnabled, stopCh); err != nil {
|
||||||
klog.Fatalf("unable to register controllers to the manager: %v", err)
|
klog.Fatalf("unable to register controllers to the manager: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user