Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Moved flag for backpressure into 'featureflags' package
Browse files Browse the repository at this point in the history
  • Loading branch information
Jont828 committed Jul 13, 2020
1 parent e7ab58b commit fb2aa5e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
7 changes: 3 additions & 4 deletions cmd/ads/ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ var (
serviceCertValidityMinutes int
caBundleSecretName string
enableDebugServer bool
backpressureEnabled bool

injectorConfig injector.Config

Expand Down Expand Up @@ -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() {
Expand All @@ -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)

Expand Down
10 changes: 5 additions & 5 deletions pkg/featureflags/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// OptionalFeatures is a struct to enable/disable optional features
type OptionalFeatures struct {
SMIAccessControlDisabled bool
// BackpressureEnabled bool
BackpressureEnabled bool
}

var (
Expand All @@ -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
}
16 changes: 9 additions & 7 deletions pkg/smi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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()
}
Expand All @@ -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 {
Expand All @@ -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))
}

Expand Down

0 comments on commit fb2aa5e

Please sign in to comment.