Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Introduce config metadata #1049

Merged
merged 7 commits into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
finish it
  • Loading branch information
kyessenov committed Aug 17, 2017
commit 4e6298ad3d723e7f7b7b4435bef008aee30ee403
6 changes: 3 additions & 3 deletions cmd/pilot-discovery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var (
configClient, err := crd.NewClient(flags.kubeconfig, model.ConfigDescriptor{
model.RouteRule,
model.DestinationPolicy,
}, flags.controllerOptions.Namespace)
})
if err != nil {
return multierror.Prefix(err, "failed to open a config client.")
}
Expand All @@ -93,10 +93,10 @@ var (
serviceController := kube.NewController(client, mesh, flags.controllerOptions)
var configController model.ConfigStoreCache
if mesh.IngressControllerMode == proxyconfig.ProxyMeshConfig_OFF {
configController = crd.NewController(configClient, flags.controllerOptions.ResyncPeriod)
configController = crd.NewController(configClient, flags.controllerOptions)
} else {
configController, err = aggregate.MakeCache([]model.ConfigStoreCache{
crd.NewController(configClient, flags.controllerOptions.ResyncPeriod),
crd.NewController(configClient, flags.controllerOptions),
ingress.NewController(client, mesh, flags.controllerOptions),
})
if err != nil {
Expand Down
28 changes: 15 additions & 13 deletions model/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ func TestIstioRegistryRouteRules(t *testing.T) {
{
name: "Slice of unsorted RouteRules",
mockObjs: []Config{
{Name: "foo", Spec: routeRule1MatchNil},
{Name: "bar", Spec: routeRule3SourceMismatch},
{Name: "baz", Spec: routeRule2SourceEmpty},
{ConfigMeta: ConfigMeta{Name: "foo"}, Spec: routeRule1MatchNil},
{ConfigMeta: ConfigMeta{Name: "bar"}, Spec: routeRule3SourceMismatch},
{ConfigMeta: ConfigMeta{Name: "baz"}, Spec: routeRule2SourceEmpty},
},
want: map[string]*proxyconfig.RouteRule{
"//foo": routeRule1MatchNil,
Expand All @@ -220,7 +220,9 @@ func TestIstioRegistryIngressRules(t *testing.T) {
}

r.mock.EXPECT().List(IngressRule.Type, "").Return([]Config{{
Name: rule.Name,
ConfigMeta: ConfigMeta{
Name: rule.Name,
},
Spec: rule,
}}, nil)

Expand All @@ -244,12 +246,12 @@ func TestIstioRegistryRouteRulesBySource(t *testing.T) {
instances := []*ServiceInstance{serviceInstance1, serviceInstance2}

mockObjs := []Config{
{Name: "match-nil", Spec: routeRule1MatchNil},
{Name: "source-empty", Spec: routeRule2SourceEmpty},
{Name: "source-mismatch", Spec: routeRule3SourceMismatch},
{Name: "source-match", Spec: routeRule4SourceMatch},
{Name: "tag-subset-of-mismatch", Spec: routeRule5TagSubsetOfMismatch},
{Name: "tag-subset-of-match", Spec: routeRule6TagSubsetOfMatch},
{ConfigMeta: ConfigMeta{Name: "match-nil"}, Spec: routeRule1MatchNil},
{ConfigMeta: ConfigMeta{Name: "source-empty"}, Spec: routeRule2SourceEmpty},
{ConfigMeta: ConfigMeta{Name: "source-mismatch"}, Spec: routeRule3SourceMismatch},
{ConfigMeta: ConfigMeta{Name: "source-match"}, Spec: routeRule4SourceMatch},
{ConfigMeta: ConfigMeta{Name: "tag-subset-of-mismatch"}, Spec: routeRule5TagSubsetOfMismatch},
{ConfigMeta: ConfigMeta{Name: "tag-subset-of-match"}, Spec: routeRule6TagSubsetOfMatch},
}
want := []*proxyconfig.RouteRule{
routeRule6TagSubsetOfMatch,
Expand Down Expand Up @@ -284,9 +286,9 @@ func TestIstioRegistryPolicies(t *testing.T) {
{
name: "Slice of unsorted DestinationPolicy",
mockObjs: []Config{
{Name: "foo", Spec: dstPolicy1},
{Name: "bar", Spec: dstPolicy2},
{Name: "baz", Spec: dstPolicy3},
{ConfigMeta: ConfigMeta{Name: "foo"}, Spec: dstPolicy1},
{ConfigMeta: ConfigMeta{Name: "bar"}, Spec: dstPolicy2},
{ConfigMeta: ConfigMeta{Name: "baz"}, Spec: dstPolicy3},
},
want: []*proxyconfig.DestinationPolicy{
dstPolicy1, dstPolicy2, dstPolicy3,
Expand Down
10 changes: 10 additions & 0 deletions model/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ func (descriptor ConfigDescriptor) FromJSON(config JSONConfig) (*Config, error)
}, nil
}

// FromJSON deserializes and validates a YAML config object
func (descriptor ConfigDescriptor) FromYAML(content []byte) (*Config, error) {
out := JSONConfig{}
err := yaml.Unmarshal(content, &out)
if err != nil {
return nil, err
}
return descriptor.FromJSON(out)
}

// ToYAML serializes a config into a YAML form
func (descriptor ConfigDescriptor) ToYAML(config Config) (string, error) {
schema, exists := descriptor.GetByType(config.Type)
Expand Down
9 changes: 1 addition & 8 deletions proxy/envoy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"testing"
"time"

"github.com/ghodss/yaml"

"github.com/golang/protobuf/ptypes"

proxyconfig "istio.io/api/proxy/v1/config"
Expand Down Expand Up @@ -234,12 +232,7 @@ func addConfig(r model.ConfigStore, file string, t *testing.T) {
if err != nil {
t.Fatal(err)
}
out := model.JSONConfig{}
err = yaml.Unmarshal(content, &out)
if err != nil {
t.Fatal(err)
}
config, err := model.IstioConfigTypes.FromJSON(out)
config, err := model.IstioConfigTypes.FromYAML(content)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func parallel(fs map[string]func() status) error {

// connect to K8S cluster and register TPRs
func setupClient() error {
istioClient, err := crd.NewClient(kubeconfig, model.IstioConfigTypes, "dummy")
istioClient, err := crd.NewClient(kubeconfig, model.IstioConfigTypes)
if err != nil {
return err
}
Expand Down
25 changes: 11 additions & 14 deletions test/integration/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,31 +258,28 @@ func (infra *infra) clientRequest(app, url string, count int, extra string) resp
return out
}

func (infra *infra) applyConfig(inFile string, data map[string]string, typ string) error {
func (infra *infra) applyConfig(inFile string, data map[string]string) error {
config, err := fill(inFile, data)
if err != nil {
return err
}

schema, ok := model.IstioConfigTypes.GetByType(typ)
if !ok {
return fmt.Errorf("Invalid type %s", typ)
}
v, err := schema.FromYAML(config)
v, err := model.IstioConfigTypes.FromYAML([]byte(config))
if err != nil {
return err
}

istioClient, err := crd.NewClient(kubeconfig, model.IstioConfigTypes, infra.Namespace)
istioClient, err := crd.NewClient(kubeconfig, model.IstioConfigTypes)
if err != nil {
return err
}

_, exists, rev := istioClient.Get(typ, schema.Key(v))
old, exists := istioClient.Get(v.Type, v.Name, v.Namespace)
if exists {
_, err = istioClient.Update(v, rev)
v.ResourceVersion = old.ResourceVersion
_, err = istioClient.Update(*v)
} else {
_, err = istioClient.Create(v)
_, err = istioClient.Create(*v)
}
if err != nil {
return err
Expand All @@ -294,18 +291,18 @@ func (infra *infra) applyConfig(inFile string, data map[string]string, typ strin
}

func (infra *infra) deleteAllConfigs() error {
istioClient, err := crd.NewClient(kubeconfig, model.IstioConfigTypes, infra.Namespace)
istioClient, err := crd.NewClient(kubeconfig, model.IstioConfigTypes)
if err != nil {
return err
}
for _, desc := range istioClient.ConfigDescriptor() {
configs, err := istioClient.List(desc.Type)
configs, err := istioClient.List(desc.Type, infra.Namespace)
if err != nil {
return err
}
for _, config := range configs {
glog.Infof("Delete config %s %s", desc.Type, config.Key)
if err = istioClient.Delete(desc.Type, config.Key); err != nil {
glog.Infof("Delete config %s", config.Key())
if err = istioClient.Delete(desc.Type, config.Name, config.Namespace); err != nil {
return err
}
}
Expand Down
4 changes: 1 addition & 3 deletions test/integration/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
"io/ioutil"
"strings"

"istio.io/pilot/model"

"github.com/golang/glog"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -79,7 +77,7 @@ func (t *ingress) setup() error {
if err = t.applyConfig("rule-default-route.yaml.tmpl", map[string]string{
"Destination": "c",
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}

Expand Down
13 changes: 6 additions & 7 deletions test/integration/routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/golang/glog"
multierror "github.com/hashicorp/go-multierror"
"istio.io/pilot/model"
)

type routing struct {
Expand All @@ -46,7 +45,7 @@ func (t *routing) run() error {
if err := t.applyConfig("rule-default-route.yaml.tmpl", map[string]string{
"Destination": "c",
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}
if err := t.verifyRouting("a", "c", "", "",
Expand All @@ -62,7 +61,7 @@ func (t *routing) run() error {
if err := t.applyConfig("rule-weighted-route.yaml.tmpl", map[string]string{
"Destination": "c",
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}
if err := t.verifyRouting("a", "c", "", "",
Expand All @@ -79,7 +78,7 @@ func (t *routing) run() error {
"Source": "a",
"Destination": "c",
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}
if err := t.verifyRouting("a", "c", "version", "v2",
Expand All @@ -96,7 +95,7 @@ func (t *routing) run() error {
"Source": "a",
"Destination": "c",
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}
if err := t.verifyRouting("a", "c", "foo", "bar",
Expand All @@ -113,7 +112,7 @@ func (t *routing) run() error {
"Source": "a",
"Destination": "c",
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}
if err := t.verifyFaultInjection("a", "c", "version", "v2", time.Second*5, 503); err != nil {
Expand All @@ -130,7 +129,7 @@ func (t *routing) run() error {
"HostRedirect": redirectHost,
"Path": redirectPath,
"Namespace": t.Namespace,
}, model.RouteRule.Type); err != nil {
}); err != nil {
return err
}
if err := t.verifyRedirect("a", "c", redirectHost, redirectPath, "testredirect", "enabled", 200); err != nil {
Expand Down
27 changes: 15 additions & 12 deletions test/integration/testdata/rule-content-route.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
destination: {{.Destination}}.{{.Namespace}}.svc.cluster.local
type: route-rule
name: content-route
precedence: 2
match:
source: {{.Source}}.{{.Namespace}}.svc.cluster.local
sourceTags:
version: v1
httpHeaders:
version:
exact: v2
route:
- tags:
version: v2
namespace: {{.Namespace}}
spec:
destination: {{.Destination}}.{{.Namespace}}.svc.cluster.local
precedence: 2
match:
source: {{.Source}}.{{.Namespace}}.svc.cluster.local
sourceTags:
version: v1
httpHeaders:
version:
exact: v2
route:
- tags:
version: v2
15 changes: 9 additions & 6 deletions test/integration/testdata/rule-default-route.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
destination: "{{.Destination}}.{{.Namespace}}.svc.cluster.local"
type: route-rule
name: default-route
precedence: 1
route:
- tags:
version: v1
weight: 100
namespace: {{.Namespace}}
spec:
destination: "{{.Destination}}.{{.Namespace}}.svc.cluster.local"
precedence: 1
route:
- tags:
version: v1
weight: 100
41 changes: 22 additions & 19 deletions test/integration/testdata/rule-fault-injection.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
destination: {{.Destination}}.{{.Namespace}}.svc.cluster.local
type: route-rule
name: fault-route
precedence: 3
match:
source: {{.Source}}.{{.Namespace}}.svc.cluster.local
sourceTags:
version: v1
httpHeaders:
version:
exact: v2
route:
- tags:
version: v2
httpFault:
delay:
percent: 100
fixedDelay: 5s
abort:
percent: 100
httpStatus: 503
namespace: {{.Namespace}}
spec:
destination: {{.Destination}}.{{.Namespace}}.svc.cluster.local
precedence: 3
match:
source: {{.Source}}.{{.Namespace}}.svc.cluster.local
sourceTags:
version: v1
httpHeaders:
version:
exact: v2
route:
- tags:
version: v2
httpFault:
delay:
percent: 100
fixedDelay: 5s
abort:
percent: 100
httpStatus: 503
22 changes: 13 additions & 9 deletions test/integration/testdata/rule-redirect-injection.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
destination: {{.Destination}}.{{.Namespace}}.svc.cluster.local
type: route-rule
name: redirect-route
precedence: 5
match:
httpHeaders:
testredirect:
exact: enabled
redirect:
uri: {{.Path}}
authority: {{.HostRedirect}}
namespace: {{.Namespace}}
spec:
destination: {{.Destination}}.{{.Namespace}}.svc.cluster.local
name: redirect-route
precedence: 5
match:
httpHeaders:
testredirect:
exact: enabled
redirect:
uri: {{.Path}}
authority: {{.HostRedirect}}
Loading