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

Put existing work for an experimental backpressure feature under a feature flag #1055

Merged
merged 4 commits into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions charts/osm/templates/osm-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ spec:
{{- if .Values.OpenServiceMesh.enableDebugServer }}
"--enableDebugServer",
{{- end }}
{{- if .Values.OpenServiceMesh.enableBackpressureExperimental }}
"--enable-backpressure-experimental",
{{- end }}
]
resources:
limits:
Expand Down
1 change: 1 addition & 0 deletions charts/osm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ OpenServiceMesh:
port: 9411
enableDebugServer: false
enablePermissiveTrafficPolicy: false
enableBackpressureExperimental: false
meshName: osm
3 changes: 3 additions & 0 deletions cmd/ads/ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func init() {
flags.IntVar(&injectorConfig.ListenPort, "webhook-port", constants.InjectorWebhookPort, "Webhook port for sidecar-injector")
flags.StringVar(&injectorConfig.InitContainerImage, "init-container-image", "", "InitContainer image")
flags.StringVar(&injectorConfig.SidecarImage, "sidecar-image", "", "Sidecar proxy Container image")

// feature flags
flags.BoolVar(&optionalFeatures.Backpressure, "enable-backpressure-experimental", false, "Enable experimental backpressure feature")
}

func main() {
Expand Down
33 changes: 18 additions & 15 deletions cmd/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,22 @@ const (
var chartTGZSource string

type installCmd struct {
out io.Writer
containerRegistry string
containerRegistrySecret string
chartPath string
osmImageTag string
certManager string
vaultHost string
vaultProtocol string
vaultToken string
vaultRole string
serviceCertValidityMinutes int
prometheusRetentionTime string
enableDebugServer bool
enablePermissiveTrafficPolicy bool
meshName string
out io.Writer
containerRegistry string
containerRegistrySecret string
chartPath string
osmImageTag string
certManager string
vaultHost string
vaultProtocol string
vaultToken string
vaultRole string
serviceCertValidityMinutes int
prometheusRetentionTime string
enableDebugServer bool
enablePermissiveTrafficPolicy bool
enableBackpressureExperimental bool
meshName string

// checker runs checks before any installation is attempted. Its type is
// abstract here to make testing easy.
Expand Down Expand Up @@ -113,6 +114,7 @@ func newInstallCmd(config *helm.Configuration, out io.Writer) *cobra.Command {
f.StringVar(&inst.prometheusRetentionTime, "prometheus-retention-time", constants.PrometheusDefaultRetentionTime, "Duration for which data will be retained in prometheus")
f.BoolVar(&inst.enableDebugServer, "enable-debug-server", false, "Enable the debug HTTP server")
f.BoolVar(&inst.enablePermissiveTrafficPolicy, "enable-permissive-traffic-policy", false, "Enable permissive traffic policy mode")
f.BoolVar(&inst.enableBackpressureExperimental, "enable-backpressure-experimental", false, "Enable experimental backpressure feature")
f.StringVar(&inst.meshName, "mesh-name", defaultMeshName, "Name of the service mesh")

return cmd
Expand Down Expand Up @@ -206,6 +208,7 @@ func (i *installCmd) resolveValues() (map[string]interface{}, error) {
fmt.Sprintf("OpenServiceMesh.prometheus.retention.time=%s", i.prometheusRetentionTime),
fmt.Sprintf("OpenServiceMesh.enableDebugServer=%t", i.enableDebugServer),
fmt.Sprintf("OpenServiceMesh.enablePermissiveTrafficPolicy=%t", i.enablePermissiveTrafficPolicy),
fmt.Sprintf("OpenServiceMesh.enableBackpressureExperimental=%t", i.enableBackpressureExperimental),
fmt.Sprintf("OpenServiceMesh.meshName=%s", i.meshName),
}

Expand Down
20 changes: 12 additions & 8 deletions cmd/cli/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ var _ = Describe("Running the install command", func() {
"retention": map[string]interface{}{
"time": "5d",
}},
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableBackpressureExperimental": false,
}}))
})

Expand Down Expand Up @@ -225,8 +226,9 @@ var _ = Describe("Running the install command", func() {
"retention": map[string]interface{}{
"time": "5d",
}},
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableBackpressureExperimental": false,
}}))
})

Expand Down Expand Up @@ -327,8 +329,9 @@ var _ = Describe("Running the install command", func() {
"time": "5d",
},
},
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableBackpressureExperimental": false,
}}))
})

Expand Down Expand Up @@ -586,8 +589,9 @@ var _ = Describe("Resolving values for install command with vault parameters", f
"time": "5d",
},
},
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableDebugServer": false,
"enablePermissiveTrafficPolicy": false,
"enableBackpressureExperimental": false,
}}))
})
})
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,8 @@ k8s.io/cli-runtime v0.18.0/go.mod h1:1eXfmBsIJosjn9LjEBUd2WVPoPAY9XGTqTFcPMIBsUQ
k8s.io/client-go v0.17.4/go.mod h1:ouF6o5pz3is8qU0/qYL2RnoxOPqgfuidYLowytyLJmc=
k8s.io/client-go v0.18.0 h1:yqKw4cTUQraZK3fcVCMeSa+lqKwcjZ5wtcOIPnxQno4=
k8s.io/client-go v0.18.0/go.mod h1:uQSYDYs4WhVZ9i6AIoEZuwUggLVEF64HOD37boKAtF8=
k8s.io/client-go v1.5.1 h1:XaX/lo2/u3/pmFau8HN+sB5C/b4dc4Dmm2eXjBH4p1E=
k8s.io/client-go v11.0.0+incompatible h1:LBbX2+lOwY9flffWlJM7f1Ct8V2SRNiMRDFeiwnJo9o=
k8s.io/code-generator v0.17.4/go.mod h1:l8BLVwASXQZTo2xamW5mQNFCe1XPiAesVq7Y1t7PiQQ=
k8s.io/code-generator v0.18.0/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
k8s.io/code-generator v0.18.3 h1:5H57pYEbkMMXCLKD16YQH3yDPAbVLweUsB1M3m70D1c=
Expand Down
6 changes: 6 additions & 0 deletions pkg/featureflags/featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// OptionalFeatures is a struct to enable/disable optional features
type OptionalFeatures struct {
// FeatureName bool
Backpressure bool
}

var (
Expand All @@ -32,3 +33,8 @@ func IsFeatureNameEnabled() bool {
return Features.FeatureName
}
*/

// IsBackpressureEnabled returns a boolean indicating if the experimental backpressure feature is enabled
func IsBackpressureEnabled() bool {
Jont828 marked this conversation as resolved.
Show resolved Hide resolved
return Features.Backpressure
}
23 changes: 19 additions & 4 deletions pkg/smi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 @@ -35,7 +36,10 @@ func NewMeshSpecClient(smiKubeConfig *rest.Config, kubeClient kubernetes.Interfa
smiTrafficSplitClientSet := smiTrafficSplitClient.NewForConfigOrDie(smiKubeConfig)
smiTrafficSpecClientSet := smiTrafficSpecClient.NewForConfigOrDie(smiKubeConfig)
smiTrafficTargetClientSet := smiTrafficTargetClient.NewForConfigOrDie(smiKubeConfig)
backpressureClientSet := backpressureClient.NewForConfigOrDie(smiKubeConfig)
var backpressureClientSet *backpressureClient.Clientset
if featureflags.IsBackpressureEnabled() {
backpressureClientSet = backpressureClient.NewForConfigOrDie(smiKubeConfig)
}

client := newSMIClient(kubeClient, smiTrafficSplitClientSet, smiTrafficSpecClientSet, smiTrafficTargetClientSet, backpressureClientSet, osmNamespace, namespaceController, kubernetesClientName)

Expand Down Expand Up @@ -111,15 +115,18 @@ func newSMIClient(kubeClient kubernetes.Interface, smiTrafficSplitClient *smiTra
TrafficSplit: smiTrafficSplitInformerFactory.Split().V1alpha2().TrafficSplits().Informer(),
TrafficSpec: smiTrafficSpecInformerFactory.Specs().V1alpha2().HTTPRouteGroups().Informer(),
TrafficTarget: smiTrafficTargetInformerFactory.Access().V1alpha1().TrafficTargets().Informer(),
Backpressure: backPressureInformerFactory.Policy().V1alpha1().Backpressures().Informer(),
}

cacheCollection := CacheCollection{
Services: informerCollection.Services.GetStore(),
TrafficSplit: informerCollection.TrafficSplit.GetStore(),
TrafficSpec: informerCollection.TrafficSpec.GetStore(),
TrafficTarget: informerCollection.TrafficTarget.GetStore(),
Backpressure: informerCollection.Backpressure.GetStore(),
}

if featureflags.IsBackpressureEnabled() {
informerCollection.Backpressure = backPressureInformerFactory.Policy().V1alpha1().Backpressures().Informer()
cacheCollection.Backpressure = informerCollection.Backpressure.GetStore()
}

client := Client{
Expand All @@ -140,7 +147,9 @@ func newSMIClient(kubeClient kubernetes.Interface, smiTrafficSplitClient *smiTra
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))
informerCollection.Backpressure.AddEventHandler(k8s.GetKubernetesEventHandlers("Backpressure", "SMI", client.announcements, shouldObserve))
if featureflags.IsBackpressureEnabled() {
informerCollection.Backpressure.AddEventHandler(k8s.GetKubernetesEventHandlers("Backpressure", "SMI", client.announcements, shouldObserve))
}
Jont828 marked this conversation as resolved.
Show resolved Hide resolved

return &client
}
Expand Down Expand Up @@ -199,6 +208,12 @@ func (c *Client) ListTrafficTargets() []*target.TrafficTarget {
// ListBackpressures implements smi.MeshSpec by returning the list of backpressures
func (c *Client) ListBackpressures() []*backpressure.Backpressure {
var backpressureList []*backpressure.Backpressure

if !featureflags.IsBackpressureEnabled() {
log.Info().Msgf("Backpressure turned off!")
return nil
}

for _, pressureIface := range c.caches.Backpressure.List() {
backpressure := pressureIface.(*backpressure.Backpressure)
// TODO: Add type assertion check using renamed variable when merging with main
Expand Down