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
fix meta config
  • Loading branch information
kyessenov committed Aug 17, 2017
commit d6cbe1489e0f41d4ed55578929e0371668980a42
16 changes: 9 additions & 7 deletions adapter/config/crd/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ func convertObject(schema model.ProtoSchema, object IstioObject) (*model.Config,
}
meta := object.GetObjectMeta()
return &model.Config{
Type: schema.Type,
Name: meta.Name,
Namespace: meta.Namespace,
Labels: meta.Labels,
Annotations: meta.Annotations,
ResourceVersion: meta.ResourceVersion,
Spec: data,
ConfigMeta: model.ConfigMeta{
Type: schema.Type,
Name: meta.Name,
Namespace: meta.Namespace,
Labels: meta.Labels,
Annotations: meta.Annotations,
ResourceVersion: meta.ResourceVersion,
},
Spec: data,
}, nil
}

Expand Down
10 changes: 6 additions & 4 deletions adapter/config/ingress/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ func TestIngressController(t *testing.T) {
}

rule := model.Config{
Type: model.IngressRule.Type,
Name: "test",
Namespace: ns,
Spec: mock.ExampleIngressRule,
ConfigMeta: model.ConfigMeta{
Type: model.IngressRule.Type,
Name: "test",
Namespace: ns,
},
Spec: mock.ExampleIngressRule,
}

// make sure all operations error out
Expand Down
15 changes: 9 additions & 6 deletions adapter/config/ingress/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ func createIngressRule(name, host, path, domainSuffix string,
}

return model.Config{
Name: name,
Namespace: ingress.Namespace,
Labels: ingress.Labels,
Annotations: ingress.Annotations,
ResourceVersion: ingress.ResourceVersion,
Spec: rule,
ConfigMeta: model.ConfigMeta{
Type: model.IngressRule.Type,
Name: name,
Namespace: ingress.Namespace,
Labels: ingress.Labels,
Annotations: ingress.Annotations,
ResourceVersion: ingress.ResourceVersion,
},
Spec: rule,
}
}

Expand Down
14 changes: 10 additions & 4 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ import (
"istio.io/pilot/model/test"
)

// Config is a configuration unit consisting of the type of configuration, the
// key identifier that is unique per type, and the content represented as a
// protobuf message. The revision is optional, and if provided, identifies the
// ConfigMeta is metadata attached to each configuration unit.
// The revision is optional, and if provided, identifies the
// last update operation on the object.
type Config struct {
type ConfigMeta struct {
// Type is a short configuration name that matches the content message type
Type string

Expand Down Expand Up @@ -63,6 +62,13 @@ type Config struct {
// An empty revision carries a special meaning that the associated object has
// not been stored and assigned a revision.
ResourceVersion string
}

// Config is a configuration unit consisting of the type of configuration, the
// key identifier that is unique per type, and the content represented as a
// protobuf message.
type Config struct {
ConfigMeta

// Spec holds the configuration object as a protobuf message
Spec proto.Message
Expand Down
10 changes: 5 additions & 5 deletions model/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func TestIstioRegistryRouteRules(t *testing.T) {
},
}
for _, c := range cases {
r.mock.EXPECT().List(RouteRule.Type).Return(c.mockObjs, c.mockError)
r.mock.EXPECT().List(RouteRule.Type, "").Return(c.mockObjs, c.mockError)
if got := r.registry.RouteRules(); !reflect.DeepEqual(got, c.want) {
t.Errorf("%v with RouteRule failed: \ngot %+vwant %+v", c.name, spew.Sdump(got), spew.Sdump(c.want))
}
Expand All @@ -219,7 +219,7 @@ func TestIstioRegistryIngressRules(t *testing.T) {
Destination: "a.svc",
}

r.mock.EXPECT().List(IngressRule.Type).Return([]Config{{
r.mock.EXPECT().List(IngressRule.Type, "").Return([]Config{{
Name: rule.Name,
Spec: rule,
}}, nil)
Expand All @@ -230,7 +230,7 @@ func TestIstioRegistryIngressRules(t *testing.T) {
t.Errorf("IngressRules failed: \ngot %+vwant %+v", spew.Sdump(got), spew.Sdump(rule))
}

r.mock.EXPECT().List(IngressRule.Type).Return(nil, errors.New("cannot list"))
r.mock.EXPECT().List(IngressRule.Type, "").Return(nil, errors.New("cannot list"))
if got := r.registry.IngressRules(); len(got) > 0 {
t.Errorf("IngressRules failed: \ngot %+vwant empty", spew.Sdump(got))
}
Expand Down Expand Up @@ -258,7 +258,7 @@ func TestIstioRegistryRouteRulesBySource(t *testing.T) {
routeRule2SourceEmpty,
}

r.mock.EXPECT().List(RouteRule.Type).Return(mockObjs, nil)
r.mock.EXPECT().List(RouteRule.Type, "").Return(mockObjs, nil)
got := r.registry.RouteRulesBySource(instances)
if !reflect.DeepEqual(got, want) {
t.Errorf("Failed \ngot %+vwant %+v", spew.Sdump(got), spew.Sdump(want))
Expand Down Expand Up @@ -302,7 +302,7 @@ func TestIstioRegistryPolicies(t *testing.T) {
}

for _, c := range cases {
r.mock.EXPECT().List(DestinationPolicy.Type).Return(c.mockObjs, c.mockError)
r.mock.EXPECT().List(DestinationPolicy.Type, "").Return(c.mockObjs, c.mockError)
if got := r.registry.DestinationPolicies(); !reflect.DeepEqual(makeSet(got), makeSet(c.want)) {
t.Errorf("%v failed: \ngot %+vwant %+v", c.name, spew.Sdump(got), spew.Sdump(c.want))
}
Expand Down
68 changes: 40 additions & 28 deletions test/mock/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ var (
func Make(namespace string, i int) model.Config {
name := fmt.Sprintf("%s%d", "mock-config", i)
return model.Config{
Type: model.MockConfig.Type,
Name: name,
Namespace: namespace,
Labels: map[string]string{
"key": name,
},
Annotations: map[string]string{
"annotationkey": name,
ConfigMeta: model.ConfigMeta{
Type: model.MockConfig.Type,
Name: name,
Namespace: namespace,
Labels: map[string]string{
"key": name,
},
Annotations: map[string]string{
"annotationkey": name,
},
},
Spec: &test.MockConfig{
Key: name,
Expand Down Expand Up @@ -129,17 +131,21 @@ func CheckMapInvariant(r model.ConfigStore, t *testing.T, namespace string, n in
}

invalid := model.Config{
Type: model.MockConfig.Type,
Name: "invalid",
ResourceVersion: revs[0],
Spec: &test.MockConfig{},
ConfigMeta: model.ConfigMeta{
Type: model.MockConfig.Type,
Name: "invalid",
ResourceVersion: revs[0],
},
Spec: &test.MockConfig{},
}

missing := model.Config{
Type: model.MockConfig.Type,
Name: "missing",
ResourceVersion: revs[0],
Spec: &test.MockConfig{Key: "missing"},
ConfigMeta: model.ConfigMeta{
Type: model.MockConfig.Type,
Name: "missing",
ResourceVersion: revs[0],
},
Spec: &test.MockConfig{Key: "missing"},
}

if _, err := r.Create(invalid); err == nil {
Expand Down Expand Up @@ -238,26 +244,32 @@ func CheckMapInvariant(r model.ConfigStore, t *testing.T, namespace string, n in
func CheckIstioConfigTypes(store model.ConfigStore, namespace string, t *testing.T) {
name := "example"
if _, err := store.Create(model.Config{
Type: model.RouteRule.Type,
Name: name,
Namespace: namespace,
Spec: ExampleRouteRule,
ConfigMeta: model.ConfigMeta{
Type: model.RouteRule.Type,
Name: name,
Namespace: namespace,
},
Spec: ExampleRouteRule,
}); err != nil {
t.Errorf("Post(RouteRule) => got %v", err)
}
if _, err := store.Create(model.Config{
Type: model.IngressRule.Type,
Name: name,
Namespace: namespace,
Spec: ExampleIngressRule,
ConfigMeta: model.ConfigMeta{
Type: model.IngressRule.Type,
Name: name,
Namespace: namespace,
},
Spec: ExampleIngressRule,
}); err != nil {
t.Errorf("Post(IngressRule) => got %v", err)
}
if _, err := store.Create(model.Config{
Type: model.DestinationPolicy.Type,
Name: name,
Namespace: namespace,
Spec: ExampleDestinationPolicy,
ConfigMeta: model.ConfigMeta{
Type: model.DestinationPolicy.Type,
Name: name,
Namespace: namespace,
},
Spec: ExampleDestinationPolicy,
}); err != nil {
t.Errorf("Post(DestinationPolicy) => got %v", err)
}
Expand Down