diff --git a/cmd/ads/ads.go b/cmd/ads/ads.go index 0379083deb..6f5fc80d10 100644 --- a/cmd/ads/ads.go +++ b/cmd/ads/ads.go @@ -53,7 +53,6 @@ var ( serviceCertValidityMinutes int caBundleSecretName string enableDebugServer bool - backpressureEnabled bool injectorConfig injector.Config @@ -98,8 +97,7 @@ func init() { // feature flags flags.BoolVar(&optionalFeatures.SMIAccessControlDisabled, "disable-smi-access-control-policy", false, "Disable SMI access control policies") - - flags.BoolVar(&backpressureEnabled, "enable-backpressure-experimental", false, "Enable experimental backpressure feature") + flags.BoolVar(&optionalFeatures.BackpressureEnabled, "enable-backpressure-experimental", false, "Enable experimental backpressure feature") } func main() { @@ -125,7 +123,8 @@ func main() { stop := signals.RegisterExitHandlers() namespaceController := namespace.NewNamespaceController(kubeConfig, meshName, stop) - meshSpec := smi.NewMeshSpecClient(kubeConfig, osmNamespace, namespaceController, stop, backpressureEnabled) + meshSpec := smi.NewMeshSpecClient(kubeConfig, osmNamespace, namespaceController, stop) + log.Info().Msgf("Backpressure enabled: %v\n", optionalFeatures.BackpressureEnabled) certManager, certDebugger := certManagers[certificateManagerKind(*certManagerKind)](kubeConfig, enableDebugServer) diff --git a/pkg/featureflags/featureflags.go b/pkg/featureflags/featureflags.go index 4f9e2aa693..e699ca66fe 100644 --- a/pkg/featureflags/featureflags.go +++ b/pkg/featureflags/featureflags.go @@ -9,7 +9,7 @@ import ( // OptionalFeatures is a struct to enable/disable optional features type OptionalFeatures struct { SMIAccessControlDisabled bool - // BackpressureEnabled bool + BackpressureEnabled bool } var ( @@ -32,7 +32,7 @@ func IsSMIAccessControlDisabled() bool { return Features.SMIAccessControlDisabled } -// // IsBackpressureEnabled returns a boolean indicating if the experimental backpressure feature is enabled -// func IsBackpressureEnabled() bool { -// // return Features.BackpressureEnabled -// } +// IsBackpressureEnabled returns a boolean indicating if the experimental backpressure feature is enabled +func IsBackpressureEnabled() bool { + return Features.BackpressureEnabled +} diff --git a/pkg/smi/client.go b/pkg/smi/client.go index 23046f70b4..65074dc55a 100644 --- a/pkg/smi/client.go +++ b/pkg/smi/client.go @@ -7,6 +7,7 @@ import ( backpressure "github.com/open-service-mesh/osm/experimental/pkg/apis/policy/v1alpha1" backpressureClient "github.com/open-service-mesh/osm/experimental/pkg/client/clientset/versioned" backpressureInformers "github.com/open-service-mesh/osm/experimental/pkg/client/informers/externalversions" + target "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/access/v1alpha1" spec "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/specs/v1alpha2" split "github.com/servicemeshinterface/smi-sdk-go/pkg/apis/split/v1alpha2" @@ -22,6 +23,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" + "github.com/open-service-mesh/osm/pkg/featureflags" k8s "github.com/open-service-mesh/osm/pkg/kubernetes" "github.com/open-service-mesh/osm/pkg/namespace" "github.com/open-service-mesh/osm/pkg/service" @@ -31,17 +33,17 @@ import ( const kubernetesClientName = "MeshSpec" // NewMeshSpecClient implements mesh.MeshSpec and creates the Kubernetes client, which retrieves SMI specific CRDs. -func NewMeshSpecClient(kubeConfig *rest.Config, osmNamespace string, namespaceController namespace.Controller, stop chan struct{}, backpressureEnabled bool) MeshSpec { +func NewMeshSpecClient(kubeConfig *rest.Config, osmNamespace string, namespaceController namespace.Controller, stop chan struct{}) MeshSpec { kubeClient := kubernetes.NewForConfigOrDie(kubeConfig) smiTrafficSplitClientSet := smiTrafficSplitClient.NewForConfigOrDie(kubeConfig) smiTrafficSpecClientSet := smiTrafficSpecClient.NewForConfigOrDie(kubeConfig) smiTrafficTargetClientSet := smiTrafficTargetClient.NewForConfigOrDie(kubeConfig) var backpressureClientSet *backpressureClient.Clientset - if backpressureEnabled { + if featureflags.IsBackpressureEnabled() { backpressureClientSet = backpressureClient.NewForConfigOrDie(kubeConfig) } - client := newSMIClient(kubeClient, smiTrafficSplitClientSet, smiTrafficSpecClientSet, smiTrafficTargetClientSet, backpressureClientSet, osmNamespace, namespaceController, kubernetesClientName, backpressureEnabled) + client := newSMIClient(kubeClient, smiTrafficSplitClientSet, smiTrafficSpecClientSet, smiTrafficTargetClientSet, backpressureClientSet, osmNamespace, namespaceController, kubernetesClientName) err := client.run(stop) if err != nil { @@ -103,7 +105,7 @@ func (c *Client) GetAnnouncementsChannel() <-chan interface{} { } // newClient creates a provider based on a Kubernetes client instance. -func newSMIClient(kubeClient *kubernetes.Clientset, smiTrafficSplitClient *smiTrafficSplitClient.Clientset, smiTrafficSpecClient *smiTrafficSpecClient.Clientset, smiTrafficTargetClient *smiTrafficTargetClient.Clientset, backpressureClient *backpressureClient.Clientset, osmNamespace string, namespaceController namespace.Controller, providerIdent string, backpressureEnabled bool) *Client { +func newSMIClient(kubeClient *kubernetes.Clientset, smiTrafficSplitClient *smiTrafficSplitClient.Clientset, smiTrafficSpecClient *smiTrafficSpecClient.Clientset, smiTrafficTargetClient *smiTrafficTargetClient.Clientset, backpressureClient *backpressureClient.Clientset, osmNamespace string, namespaceController namespace.Controller, providerIdent string) *Client { informerFactory := informers.NewSharedInformerFactory(kubeClient, k8s.DefaultKubeEventResyncInterval) smiTrafficSplitInformerFactory := smiTrafficSplitInformers.NewSharedInformerFactory(smiTrafficSplitClient, k8s.DefaultKubeEventResyncInterval) smiTrafficSpecInformerFactory := smiTrafficSpecInformers.NewSharedInformerFactory(smiTrafficSpecClient, k8s.DefaultKubeEventResyncInterval) @@ -123,7 +125,7 @@ func newSMIClient(kubeClient *kubernetes.Clientset, smiTrafficSplitClient *smiTr TrafficSpec: informerCollection.TrafficSpec.GetStore(), TrafficTarget: informerCollection.TrafficTarget.GetStore(), } - if backpressureEnabled { + if featureflags.IsBackpressureEnabled() { informerCollection.Backpressure = backPressureInformerFactory.Policy().V1alpha1().Backpressures().Informer() cacheCollection.Backpressure = informerCollection.Backpressure.GetStore() } @@ -136,7 +138,7 @@ func newSMIClient(kubeClient *kubernetes.Clientset, smiTrafficSplitClient *smiTr announcements: make(chan interface{}), osmNamespace: osmNamespace, namespaceController: namespaceController, - backpressureEnabled: backpressureEnabled, + backpressureEnabled: featureflags.IsBackpressureEnabled(), } shouldObserve := func(obj interface{}) bool { @@ -147,7 +149,7 @@ func newSMIClient(kubeClient *kubernetes.Clientset, smiTrafficSplitClient *smiTr informerCollection.TrafficSplit.AddEventHandler(k8s.GetKubernetesEventHandlers("TrafficSplit", "SMI", client.announcements, shouldObserve)) informerCollection.TrafficSpec.AddEventHandler(k8s.GetKubernetesEventHandlers("TrafficSpec", "SMI", client.announcements, shouldObserve)) informerCollection.TrafficTarget.AddEventHandler(k8s.GetKubernetesEventHandlers("TrafficTarget", "SMI", client.announcements, shouldObserve)) - if backpressureEnabled { + if featureflags.IsBackpressureEnabled() { informerCollection.Backpressure.AddEventHandler(k8s.GetKubernetesEventHandlers("Backpressure", "SMI", client.announcements, shouldObserve)) }