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
update configs
  • Loading branch information
kyessenov committed Aug 17, 2017
commit 12b7f5303219a20dea3f8eed687453c6d832818b
1 change: 0 additions & 1 deletion adapter/config/crd/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ go_library(
"//platform/kube:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@com_github_hashicorp_go_multierror//:go_default_library",
"@io_k8s_api//core/v1:go_default_library",
"@io_k8s_apiextensions_apiserver//pkg/apis/apiextensions/v1beta1:go_default_library",
"@io_k8s_apiextensions_apiserver//pkg/client/clientset/clientset:go_default_library",
"@io_k8s_apimachinery//pkg/api/errors:go_default_library",
Expand Down
1 change: 0 additions & 1 deletion cmd/istioctl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ go_library(
"//platform/kube/inject:go_default_library",
"//tools/version:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_golang_glog//:go_default_library",
"@com_github_googleapis_googleapis//:go_default_library",
"@com_github_hashicorp_go_multierror//:go_default_library",
Expand Down
10 changes: 8 additions & 2 deletions cmd/istioctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ istioctl mixer command documentation.
return errors.New("nothing to create")
}
for _, config := range varr {
if config.Namespace == "" {
config.Namespace = namespace
}
rev, err := configClient.Create(config)
if err != nil {
return err
Expand Down Expand Up @@ -125,6 +128,9 @@ istioctl mixer command documentation.
return errors.New("nothing to replace")
}
for _, config := range varr {
if config.Namespace == "" {
config.Namespace = namespace
}
// fill up revision
if config.ResourceVersion == "" {
current, exists := configClient.Get(config.Type, config.Name, config.Namespace)
Expand Down Expand Up @@ -360,15 +366,15 @@ func readInputs() ([]model.Config, error) {
// Print a simple list of names
func printShortOutput(configList []model.Config) {
for _, c := range configList {
fmt.Printf("%v\n", c.Key)
fmt.Printf("%v\n", c.Key())
}
}

// Print as YAML
func printYamlOutput(configList []model.Config) {
for _, c := range configList {
yaml, _ := configClient.ConfigDescriptor().ToYAML(c)
fmt.Println(yaml)
fmt.Print(yaml)
fmt.Println("---")
}
}
6 changes: 0 additions & 6 deletions model/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,6 @@ func ValidateRouteRule(msg proto.Message) error {
}

var errs error
if value.Name == "" {
errs = multierror.Append(errs, fmt.Errorf("route rule must have a name"))
}
if !IsDNS1123Label(value.Name) {
errs = multierror.Append(errs, fmt.Errorf("route rule name must be a host name label"))
}
if value.Destination == "" {
errs = multierror.Append(errs, fmt.Errorf("route rule must have a destination service"))
}
Expand Down
2 changes: 1 addition & 1 deletion proxy/envoy/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ go_test(
"//test/util:go_default_library",
"@com_github_davecgh_go_spew//spew:go_default_library",
"@com_github_emicklei_go_restful//:go_default_library",
"@com_github_golang_protobuf//proto:go_default_library",
"@com_github_ghodss_yaml//:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library",
"@io_istio_api//:go_default_library",
],
Expand Down
66 changes: 7 additions & 59 deletions proxy/envoy/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
package envoy

import (
"fmt"
"io/ioutil"
"reflect"
"sort"
"testing"
"time"

"github.com/golang/protobuf/proto"
"github.com/ghodss/yaml"

"github.com/golang/protobuf/ptypes"

proxyconfig "istio.io/api/proxy/v1/config"
Expand Down Expand Up @@ -229,76 +229,24 @@ const (
rewriteRouteRule = "testdata/rewrite-route.yaml.golden"
)

func configObjectFromYAML(kind, file string) (proto.Message, error) {
schema, ok := model.IstioConfigTypes.GetByType(kind)
if !ok {
return nil, fmt.Errorf("Missing kind %q", kind)
}
func addConfig(r model.ConfigStore, file string, t *testing.T) {
content, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
return schema.FromYAML(string(content))
}

func addCircuitBreaker(r model.ConfigStore, t *testing.T) {
msg, err := configObjectFromYAML(model.DestinationPolicy.Type, cbPolicy)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}

func addRewrite(r model.ConfigStore, t *testing.T) {
msg, err := configObjectFromYAML(model.RouteRule.Type, rewriteRouteRule)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}

func addRedirect(r model.ConfigStore, t *testing.T) {
msg, err := configObjectFromYAML(model.RouteRule.Type, redirectRouteRule)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}

func addTimeout(r model.ConfigStore, t *testing.T) {
msg, err := configObjectFromYAML(model.RouteRule.Type, timeoutRouteRule)
out := model.JSONConfig{}
err = yaml.Unmarshal(content, &out)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}

func addWeightedRoute(r model.ConfigStore, t *testing.T) {
msg, err := configObjectFromYAML(model.RouteRule.Type, weightedRouteRule)
config, err := model.IstioConfigTypes.FromJSON(out)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}

func addFaultRoute(r model.ConfigStore, t *testing.T) {
msg, err := configObjectFromYAML(model.RouteRule.Type, faultRouteRule)
_, err = r.Create(*config)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}

func makeMeshConfig() proxyconfig.ProxyMeshConfig {
Expand Down
30 changes: 9 additions & 21 deletions proxy/envoy/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestClusterDiscovery(t *testing.T) {
func TestClusterDiscoveryCircuitBreaker(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addCircuitBreaker(registry, t)
addConfig(registry, cbPolicy, t)
ds := makeDiscoveryService(t, registry, &mesh)
url := fmt.Sprintf("/v1/clusters/%s/%s", ds.Mesh.IstioServiceCluster, mock.ProxyV0.ServiceNode())
response := makeDiscoveryRequest(ds, "GET", url, t)
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestRouteDiscoveryV1(t *testing.T) {
func TestRouteDiscoveryTimeout(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addTimeout(registry, t)
addConfig(registry, timeoutRouteRule, t)
ds := makeDiscoveryService(t, registry, &mesh)
url := fmt.Sprintf("/v1/routes/80/%s/%s", ds.Mesh.IstioServiceCluster, mock.ProxyV0.ServiceNode())
response := makeDiscoveryRequest(ds, "GET", url, t)
Expand All @@ -240,7 +240,7 @@ func TestRouteDiscoveryTimeout(t *testing.T) {
func TestRouteDiscoveryWeighted(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addWeightedRoute(registry, t)
addConfig(registry, weightedRouteRule, t)
ds := makeDiscoveryService(t, registry, &mesh)
url := fmt.Sprintf("/v1/routes/80/%s/%s", ds.Mesh.IstioServiceCluster, mock.ProxyV0.ServiceNode())
response := makeDiscoveryRequest(ds, "GET", url, t)
Expand All @@ -250,7 +250,7 @@ func TestRouteDiscoveryWeighted(t *testing.T) {
func TestRouteDiscoveryFault(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addFaultRoute(registry, t)
addConfig(registry, faultRouteRule, t)
ds := makeDiscoveryService(t, registry, &mesh)

// fault rule is source based: we check that the rule only affect v0 and not v1
Expand All @@ -266,7 +266,7 @@ func TestRouteDiscoveryFault(t *testing.T) {
func TestRouteDiscoveryRedirect(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addRedirect(registry, t)
addConfig(registry, redirectRouteRule, t)
ds := makeDiscoveryService(t, registry, &mesh)

// fault rule is source based: we check that the rule only affect v0 and not v1
Expand All @@ -278,7 +278,7 @@ func TestRouteDiscoveryRedirect(t *testing.T) {
func TestRouteDiscoveryRewrite(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addRewrite(registry, t)
addConfig(registry, rewriteRouteRule, t)
ds := makeDiscoveryService(t, registry, &mesh)

// fault rule is source based: we check that the rule only affect v0 and not v1
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestRouteDiscoveryIngressWeighted(t *testing.T) {
mesh := makeMeshConfig()
registry := memory.Make(model.IstioConfigTypes)
addIngressRoutes(registry, t)
addWeightedRoute(registry, t)
addConfig(registry, weightedRouteRule, t)
ds := makeDiscoveryService(t, registry, &mesh)

url := fmt.Sprintf("/v1/routes/80/%s/%s", ds.Mesh.IstioServiceCluster, mock.Ingress.ServiceNode())
Expand All @@ -333,33 +333,27 @@ func TestSidecarListenerDiscovery(t *testing.T) {
/* these configs do not affect listeners
{
name: "cb",
typ: model.DestinationPolicy,
file: cbPolicy,
},
{
name: "redirect",
typ: model.RouteRule,
file: redirectRouteRule,
},
{
name: "rewrite",
typ: model.RouteRule,
file: rewriteRouteRule,
},
{
name: "timeout",
typ: model.RouteRule,
file: timeoutRouteRule,
},
*/
{
name: "weighted",
typ: model.RouteRule.Type,
file: weightedRouteRule,
},
{
name: "fault",
typ: model.RouteRule.Type,
file: faultRouteRule,
},
}
Expand All @@ -368,14 +362,8 @@ func TestSidecarListenerDiscovery(t *testing.T) {
t.Run(testCase.name, func(t *testing.T) {
registry := memory.Make(model.IstioConfigTypes)

if testCase.typ != "" {
msg, err := configObjectFromYAML(testCase.typ, testCase.file)
if err != nil {
t.Fatal(err)
}
if _, err = registry.Create(msg); err != nil {
t.Fatal(err)
}
if testCase.file != "" {
addConfig(registry, testCase.file, t)
}

// test with no auth
Expand Down
11 changes: 2 additions & 9 deletions proxy/envoy/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ const (
)

func addIngressRoutes(r model.ConfigStore, t *testing.T) {
for _, file := range []string{ingressRouteRule1, ingressRouteRule2} {
msg, err := configObjectFromYAML(model.IngressRule.Type, file)
if err != nil {
t.Fatal(err)
}
if _, err = r.Create(msg); err != nil {
t.Fatal(err)
}
}
addConfig(r, ingressRouteRule1, t)
addConfig(r, ingressRouteRule2, t)
}

func TestRouteCombination(t *testing.T) {
Expand Down
28 changes: 16 additions & 12 deletions proxy/envoy/testdata/cb-policy.yaml.golden
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
destination: world.default.svc.cluster.local
policy:
- circuit_breaker:
simple_cb:
max_connections: 100
sleep_window: 15.5s
http_max_requests: 100
http_max_requests_per_connection: 100
http_max_pending_requests: 100
http_consecutive_errors: 10
http_detection_interval: 30s
http_max_ejection_percent: 100
type: destination-policy
name: world
namespace: default
spec:
destination: world.default.svc.cluster.local
policy:
- circuit_breaker:
simple_cb:
max_connections: 100
sleep_window: 15.5s
http_max_requests: 100
http_max_requests_per_connection: 100
http_max_pending_requests: 100
http_consecutive_errors: 10
http_detection_interval: 30s
http_max_ejection_percent: 100
46 changes: 24 additions & 22 deletions proxy/envoy/testdata/fault-route.yaml.golden
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
destination: world.default.svc.cluster.local
type: route-rule
name: fault-route
match:
source: hello.default.svc.cluster.local
source_tags:
version: v0
httpHeaders:
scooby:
exact: doo
animal:
prefix: dog.cat
name:
regex: "sco+do+"
route:
- tags:
version: v1
http_fault:
delay:
percent: 100
fixed_delay: 5s
abort:
percent: 100
http_status: 503
spec:
destination: world.default.svc.cluster.local
match:
source: hello.default.svc.cluster.local
source_tags:
version: v0
httpHeaders:
scooby:
exact: doo
animal:
prefix: dog.cat
name:
regex: "sco+do+"
route:
- tags:
version: v1
http_fault:
delay:
percent: 100
fixed_delay: 5s
abort:
percent: 100
http_status: 503
Loading