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

Commit

Permalink
ref(*): move feature flags to meshconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Elliott <[email protected]>
  • Loading branch information
jaellio committed Jun 21, 2021
1 parent 09cdbc2 commit 6f7697d
Show file tree
Hide file tree
Showing 31 changed files with 239 additions and 192 deletions.
13 changes: 13 additions & 0 deletions charts/osm/crds/meshconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,16 @@ spec:
description: Sets the service certificate validity duration, represented as a sequence of decimal numbers each with optional fraction and a unit suffix.
type: string
default: "24h"
featureFlags:
description: OSM feature flags
type: object
properties:
enableWASMStats:
type: boolean
default: true
enableEgressPolicy:
type: boolean
default: true
enableMulticlusterMode:
type: boolean
default: false
9 changes: 0 additions & 9 deletions charts/osm/templates/osm-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ spec:
"--cert-manager-issuer-name", "{{.Values.OpenServiceMesh.certmanager.issuerName}}",
"--cert-manager-issuer-kind", "{{.Values.OpenServiceMesh.certmanager.issuerKind}}",
"--cert-manager-issuer-group", "{{.Values.OpenServiceMesh.certmanager.issuerGroup}}",
{{- if .Values.OpenServiceMesh.featureFlags.enableWASMStats }}
"--stats-wasm-experimental",
{{- end }}
{{- if .Values.OpenServiceMesh.featureFlags.enableEgressPolicy }}
"--enable-egress-policy",
{{- end }}
{{- if .Values.OpenServiceMesh.featureFlags.enableMulticlusterMode }}
"--enable-multicluster",
{{- end }}
]
resources:
limits:
Expand Down
6 changes: 5 additions & 1 deletion charts/osm/templates/preset-mesh-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ spec:
endpoint: {{.Values.OpenServiceMesh.tracing.endpoint | quote}}
{{- end }}
certificate:
serviceCertValidityDuration: {{.Values.OpenServiceMesh.serviceCertValidityDuration}}
serviceCertValidityDuration: {{.Values.OpenServiceMesh.serviceCertValidityDuration}}
featureFlags:
enableWASMStats: {{.Values.OpenServiceMesh.featureFlags.enableWASMStats}}
enableEgressPolicy: {{.Values.OpenServiceMesh.featureFlags.enableEgressPolicy}}
enableMulticlusterMode: {{.Values.OpenServiceMesh.featureFlags.enableMulticlusterMode}}
17 changes: 0 additions & 17 deletions cmd/osm-controller/osm-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main

import (
"context"
"encoding/json"
"flag"
"fmt"
"net/http"
Expand Down Expand Up @@ -34,7 +33,6 @@ import (
"github.com/openservicemesh/osm/pkg/endpoint/providers/kube"
"github.com/openservicemesh/osm/pkg/envoy/ads"
"github.com/openservicemesh/osm/pkg/envoy/registry"
"github.com/openservicemesh/osm/pkg/featureflags"
"github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned"
"github.com/openservicemesh/osm/pkg/health"
"github.com/openservicemesh/osm/pkg/httpserver"
Expand Down Expand Up @@ -68,9 +66,6 @@ var (
vaultOptions providers.VaultOptions
certManagerOptions providers.CertManagerOptions

// feature flag options
optionalFeatures featureflags.OptionalFeatures

scheme = runtime.NewScheme()
)

Expand Down Expand Up @@ -103,11 +98,6 @@ func init() {
flags.StringVar(&certManagerOptions.IssuerKind, "cert-manager-issuer-kind", "Issuer", "cert-manager issuer kind")
flags.StringVar(&certManagerOptions.IssuerGroup, "cert-manager-issuer-group", "cert-manager.io", "cert-manager issuer group")

// feature flags
flags.BoolVar(&optionalFeatures.WASMStats, "stats-wasm-experimental", false, "Enable a WebAssembly module that generates additional Envoy statistics")
flags.BoolVar(&optionalFeatures.EgressPolicy, "enable-egress-policy", false, "Enable OSM's Egress policy API")
flags.BoolVar(&optionalFeatures.MulticlusterMode, "enable-multicluster", false, "Enable multicluster mode in OSM")

_ = clientgoscheme.AddToScheme(scheme)
_ = admissionv1.AddToScheme(scheme)
}
Expand All @@ -122,13 +112,6 @@ func main() {
log.Fatal().Err(err).Msg("Error setting log level")
}

if featureFlagsJSON, err := json.Marshal(featureflags.Features); err != nil {
log.Error().Err(err).Msgf("Error marshaling feature flags struct: %+v", featureflags.Features)
} else {
log.Info().Msgf("Feature flags: %s", string(featureFlagsJSON))
}

featureflags.Initialize(optionalFeatures)
events.GetPubSubInstance() // Just to generate the interface, single routine context

// Initialize kube config and client
Expand Down
15 changes: 15 additions & 0 deletions pkg/apis/config/v1alpha1/mesh_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type MeshConfigSpec struct {

// Certificate defines the certificate management configurations for a mesh instance.
Certificate CertificateSpec `json:"certificate,omitempty"`

// FeatureFlags defines the feature flags for a mesh instance.
FeatureFlags FeatureFlags `json:"featureFlags,omitempty"`
}

// SidecarSpec is the type used to represent the specifications for the proxy sidecar.
Expand Down Expand Up @@ -150,3 +153,15 @@ type MeshConfigList struct {

Items []MeshConfig `json:"items"`
}

// FeatureFlags is a type to represent OSM's feature flags.
type FeatureFlags struct {
// EnableWASMStats defines if WASM Stats are enabled.
EnableWASMStats bool `json:"enableWASMStats,omitempty"`

// EnableEgressPolicy defines if OSM's Egress policy is enabled.
EnableEgressPolicy bool `json:"enableEgressPolicy,omitempty"`

// EnableMulticlusterMode defines if Multicluster mode is enabled.
EnableMulticlusterMode bool `json:"enableMulticlusterMode,omitempty"`
}
3 changes: 1 addition & 2 deletions pkg/catalog/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
policyV1alpha1 "github.com/openservicemesh/osm/pkg/apis/policy/v1alpha1"

"github.com/openservicemesh/osm/pkg/constants"
"github.com/openservicemesh/osm/pkg/featureflags"
"github.com/openservicemesh/osm/pkg/identity"
"github.com/openservicemesh/osm/pkg/service"
"github.com/openservicemesh/osm/pkg/trafficpolicy"
)

// GetEgressTrafficPolicy returns the Egress traffic policy associated with the given service identity
func (mc *MeshCatalog) GetEgressTrafficPolicy(serviceIdentity identity.ServiceIdentity) (*trafficpolicy.EgressTrafficPolicy, error) {
if !featureflags.IsEgressPolicyEnabled() {
if !mc.configurator.GetFeatureFlags().EnableEgressPolicy {
return nil, nil
}

Expand Down
15 changes: 7 additions & 8 deletions pkg/catalog/egress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,22 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"

"github.com/openservicemesh/osm/pkg/apis/config/v1alpha1"
policyV1alpha1 "github.com/openservicemesh/osm/pkg/apis/policy/v1alpha1"
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/identity"
"github.com/openservicemesh/osm/pkg/policy"

"github.com/openservicemesh/osm/pkg/featureflags"
"github.com/openservicemesh/osm/pkg/service"
"github.com/openservicemesh/osm/pkg/smi"
"github.com/openservicemesh/osm/pkg/trafficpolicy"
)

func init() {
optionalFeatures := featureflags.OptionalFeatures{
EgressPolicy: true,
}
featureflags.Initialize(optionalFeatures)
}

func TestGetEgressTrafficPolicy(t *testing.T) {
assert := tassert.New(t)
mockCtrl := gomock.NewController(t)
mockCfg := configurator.NewMockConfigurator(mockCtrl)

defer mockCtrl.Finish()

testCases := []struct {
Expand Down Expand Up @@ -354,9 +350,12 @@ func TestGetEgressTrafficPolicy(t *testing.T) {

mc := &MeshCatalog{
meshSpec: mockMeshSpec,
configurator: mockCfg,
policyController: mockPolicyController,
}

mockCfg.EXPECT().GetFeatureFlags().Return(v1alpha1.FeatureFlags{EnableEgressPolicy: true}).Times(1)

actual, err := mc.GetEgressTrafficPolicy(testSourceIdentity)
assert.Equal(tc.expectError, err != nil)
assert.ElementsMatch(tc.expectedEgressPolicy.TrafficMatches, actual.TrafficMatches)
Expand Down
2 changes: 1 addition & 1 deletion pkg/catalog/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type MeshCataloger interface {
// ListMeshServicesForIdentity lists the services for a given service identity.
ListMeshServicesForIdentity(identity.ServiceIdentity) []service.MeshService

// GetEgressTrafficPolicy returns the Egress traffic policy associated with the given service identity
// GetEgressTrafficPolicy returns the Egress traffic policy associated with the given service identity.
GetEgressTrafficPolicy(identity.ServiceIdentity) (*trafficpolicy.EgressTrafficPolicy, error)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/configurator/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ func (c *Client) GetInboundExternalAuthConfig() auth.ExtAuthConfig {

return extAuthConfig
}

// GetFeatureFlags returns OSM's feature flags
func (c *Client) GetFeatureFlags() v1alpha1.FeatureFlags {
return c.getMeshConfig().Spec.FeatureFlags
}
45 changes: 45 additions & 0 deletions pkg/configurator/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,51 @@ func TestCreateUpdateConfig(t *testing.T) {
assert.Equal(resource.MustParse("512M"), res.Limits[v1.ResourceMemory])
},
},
{
name: "IsWASMStatsEnabled",
initialMeshConfigData: &v1alpha1.MeshConfigSpec{},
checkCreate: func(assert *tassert.Assertions, cfg Configurator) {
assert.Equal(false, cfg.GetFeatureFlags().EnableWASMStats)
},
updatedMeshConfigData: &v1alpha1.MeshConfigSpec{
FeatureFlags: v1alpha1.FeatureFlags{
EnableWASMStats: true,
},
},
checkUpdate: func(assert *tassert.Assertions, cfg Configurator) {
assert.Equal(true, cfg.GetFeatureFlags().EnableWASMStats)
},
},
{
name: "IsEgressPolicyEnabled",
initialMeshConfigData: &v1alpha1.MeshConfigSpec{},
checkCreate: func(assert *tassert.Assertions, cfg Configurator) {
assert.Equal(false, cfg.GetFeatureFlags().EnableEgressPolicy)
},
updatedMeshConfigData: &v1alpha1.MeshConfigSpec{
FeatureFlags: v1alpha1.FeatureFlags{
EnableEgressPolicy: true,
},
},
checkUpdate: func(assert *tassert.Assertions, cfg Configurator) {
assert.Equal(true, cfg.GetFeatureFlags().EnableEgressPolicy)
},
},
{
name: "IsMulticlusterModeEnabled",
initialMeshConfigData: &v1alpha1.MeshConfigSpec{},
checkCreate: func(assert *tassert.Assertions, cfg Configurator) {
assert.Equal(false, cfg.GetFeatureFlags().EnableMulticlusterMode)
},
updatedMeshConfigData: &v1alpha1.MeshConfigSpec{
FeatureFlags: v1alpha1.FeatureFlags{
EnableMulticlusterMode: true,
},
},
checkUpdate: func(assert *tassert.Assertions, cfg Configurator) {
assert.Equal(true, cfg.GetFeatureFlags().EnableMulticlusterMode)
},
},
}

for _, test := range tests {
Expand Down
15 changes: 15 additions & 0 deletions pkg/configurator/mock_client_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pkg/configurator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/cache"

"github.com/openservicemesh/osm/pkg/apis/config/v1alpha1"
"github.com/openservicemesh/osm/pkg/auth"
"github.com/openservicemesh/osm/pkg/logger"
)
Expand Down Expand Up @@ -96,4 +97,7 @@ type Configurator interface {

// GetInboundExternalAuthConfig returns the External Authentication configuration for incoming traffic, if any
GetInboundExternalAuthConfig() auth.ExtAuthConfig

// GetFeatureFlags returns OSM's feature flags
GetFeatureFlags() v1alpha1.FeatureFlags
}
7 changes: 3 additions & 4 deletions pkg/debugger/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ import (
"encoding/json"
"fmt"
"net/http"

"github.com/openservicemesh/osm/pkg/featureflags"
)

func (ds DebugConfig) getFeatureFlags() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if featureFlagsJSON, err := json.Marshal(featureflags.Features); err != nil {
log.Error().Err(err).Msgf("Error marshaling feature flags struct: %+v", featureflags.Features)
featureFlags := ds.configurator.GetFeatureFlags()
if featureFlagsJSON, err := json.Marshal(featureFlags); err != nil {
log.Error().Err(err).Msgf("Error marshaling feature flags struct: %+v", featureFlags)
} else {
_, _ = fmt.Fprint(w, string(featureFlagsJSON))
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/envoy/ads/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
testclient "k8s.io/client-go/kubernetes/fake"

"github.com/openservicemesh/osm/pkg/apis/config/v1alpha1"
"github.com/openservicemesh/osm/pkg/auth"
configFake "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned/fake"

Expand Down Expand Up @@ -129,6 +130,10 @@ var _ = Describe("Test ADS response functions", func() {
mockConfigurator.EXPECT().IsPermissiveTrafficPolicyMode().Return(false).AnyTimes()
mockConfigurator.EXPECT().GetServiceCertValidityPeriod().Return(certDuration).AnyTimes()
mockConfigurator.EXPECT().IsDebugServerEnabled().Return(true).AnyTimes()
mockConfigurator.EXPECT().GetFeatureFlags().Return(v1alpha1.FeatureFlags{
EnableWASMStats: false,
EnableEgressPolicy: false,
}).AnyTimes()

It("returns Aggregated Discovery Service response", func() {
s := NewADSServer(mc, proxyRegistry, true, tests.Namespace, mockConfigurator, mockCertManager)
Expand Down
3 changes: 1 addition & 2 deletions pkg/envoy/lds/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/openservicemesh/osm/pkg/configurator"
"github.com/openservicemesh/osm/pkg/constants"
"github.com/openservicemesh/osm/pkg/envoy"
"github.com/openservicemesh/osm/pkg/featureflags"
)

// trafficDirection defines, for filter terms, the direction of the traffic from an application
Expand Down Expand Up @@ -77,7 +76,7 @@ func getHTTPConnectionManager(routeName string, cfg configurator.Configurator, h
connManager.Tracing = tracing
}

if featureflags.IsWASMStatsEnabled() {
if cfg.GetFeatureFlags().EnableWASMStats {
statsFilter, err := getStatsWASMFilter()
if err != nil {
log.Error().Err(err).Msg("failed to get stats WASM filter")
Expand Down
Loading

0 comments on commit 6f7697d

Please sign in to comment.