Skip to content

Commit

Permalink
Disable Istio by default apache#833
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jul 22, 2019
1 parent d33cc45 commit 9afd9d0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/traits.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ More information can be found in the official Kubernetes documentation about htt
!===

| istio
| Knative (Kubernetes, OpenShift)
| All
| Allows to configure outbound traffic for Istio.
+
+
It's enabled by default when the Knative profile is active.
It's disabled by default.

[cols="m,"]
!===
Expand Down
8 changes: 4 additions & 4 deletions pkg/trait/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ func newIstioTrait() *istioTrait {
}

func (t *istioTrait) Configure(e *Environment) (bool, error) {
if t.Enabled != nil && !*t.Enabled {
return false, nil
if t.Enabled != nil && *t.Enabled {
return e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying), nil
}

return e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying), nil
return false, nil
}

func (t *istioTrait) Apply(e *Environment) error {
Expand All @@ -69,7 +69,7 @@ func (t *istioTrait) injectIstioAnnotation(annotations map[string]string, includ
}
annotations[istioOutboundIPRangesAnnotation] = t.Allow
if includeInject {
annotations[istioSidecarInjectAnnotation] = "true"
annotations[istioSidecarInjectAnnotation] = True
}
if t.Inject != nil {
annotations[istioSidecarInjectAnnotation] = strconv.FormatBool(*t.Inject)
Expand Down
40 changes: 32 additions & 8 deletions pkg/trait/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func NewIstioTestEnv(t *testing.T, d *appsv1.Deployment, s *serving.Service) Environment {
func NewIstioTestEnv(t *testing.T, d *appsv1.Deployment, s *serving.Service, enabled bool) Environment {
catalog, err := test.DefaultCatalog()
assert.Nil(t, err)

Expand All @@ -46,9 +46,7 @@ func NewIstioTestEnv(t *testing.T, d *appsv1.Deployment, s *serving.Service) Env
Spec: v1alpha1.IntegrationSpec{
Traits: map[string]v1alpha1.TraitSpec{
"istio": {
Configuration: map[string]string{
"enabled": "true",
},
Configuration: make(map[string]string),
},
},
},
Expand All @@ -66,6 +64,10 @@ func NewIstioTestEnv(t *testing.T, d *appsv1.Deployment, s *serving.Service) Env
Resources: kubernetes.NewCollection(s, d),
}

if enabled {
env.Integration.Spec.Traits["istio"].Configuration["enabled"] = "true"
}

return env
}

Expand All @@ -85,8 +87,7 @@ func TestIstioInject(t *testing.T) {
},
}

env := NewIstioTestEnv(t, &d, &s)

env := NewIstioTestEnv(t, &d, &s, true)
err := env.Catalog.apply(&env)
assert.Nil(t, err)

Expand All @@ -110,7 +111,7 @@ func TestIstioForcedInjectTrue(t *testing.T) {
},
}

env := NewIstioTestEnv(t, &d, &s)
env := NewIstioTestEnv(t, &d, &s, true)
env.Integration.Spec.Traits["istio"].Configuration["inject"] = "true"

err := env.Catalog.apply(&env)
Expand All @@ -136,7 +137,7 @@ func TestIstioForcedInjectFalse(t *testing.T) {
},
}

env := NewIstioTestEnv(t, &d, &s)
env := NewIstioTestEnv(t, &d, &s, true)
env.Integration.Spec.Traits["istio"].Configuration["inject"] = "false"

err := env.Catalog.apply(&env)
Expand All @@ -145,3 +146,26 @@ func TestIstioForcedInjectFalse(t *testing.T) {
assert.Equal(t, "false", s.Spec.RunLatest.Configuration.RevisionTemplate.Annotations[istioSidecarInjectAnnotation])
assert.Equal(t, "false", d.Spec.Template.Annotations[istioSidecarInjectAnnotation])
}

func TestIstioDisabled(t *testing.T) {
s := serving.Service{
Spec: serving.ServiceSpec{
RunLatest: &serving.RunLatestType{
Configuration: serving.ConfigurationSpec{
RevisionTemplate: serving.RevisionTemplateSpec{},
},
},
},
}
d := appsv1.Deployment{
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{},
},
}

env := NewIstioTestEnv(t, &d, &s, false)

err := env.Catalog.apply(&env)
assert.Nil(t, err)
assert.NotContains(t, env.ExecutedTraits, "istio")
}
2 changes: 2 additions & 0 deletions pkg/trait/trait_catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
c.tClasspath,
c.tProbes,
c.tRoute,
c.tIstio,
c.tOwner,
}
case v1alpha1.TraitProfileKubernetes:
Expand All @@ -165,6 +166,7 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
c.tClasspath,
c.tProbes,
c.tIngress,
c.tIstio,
c.tOwner,
}
case v1alpha1.TraitProfileKnative:
Expand Down

0 comments on commit 9afd9d0

Please sign in to comment.