Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #262 from atlassian/refactor-dependson
Browse files Browse the repository at this point in the history
Refactor dependsOn into References
  • Loading branch information
ash2k authored Apr 5, 2018
2 parents d075e6b + 1bc5334 commit 4cb5cd0
Show file tree
Hide file tree
Showing 21 changed files with 524 additions and 274 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

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

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It's functional and under active development.

## News

- 01.01.2018: [Milestone v1.0](https://github.com/atlassian/smith/milestones/v1.0) is complete and v1.0.0 released!
- 01.01.2018: [Milestone v1.0](https://github.com/atlassian/smith/milestones/v1.0) is complete and v1.0.0 released!

## The idea

Expand Down Expand Up @@ -110,7 +110,7 @@ Some resource types can have Outputs:
- New objects likes [Secrets](https://kubernetes.io/docs/user-guide/secrets/) and/or [ConfigMaps](https://kubernetes.io/docs/user-guide/configmap/)
- [Service Catalog](https://github.com/kubernetes-incubator/service-catalog) [objects](https://github.com/kubernetes-incubator/service-catalog/blob/master/docs/v1/api.md)
Resources can reference outputs of other resources within the same bundle. [See what is supported](./docs/design/field-references.md).
Resources can reference outputs of other resources within the same bundle. [See what is supported](./docs/design/field-references.md).
### Dependencies
Resources may depend on each other explicitly via `DependsOn` object references. Resources are created in the reverse dependency order.
Expand Down Expand Up @@ -146,7 +146,7 @@ See [an example](examples/service_catalog) and
### Presentations
Smith has been presented to:
- SIG Service Catalog - see information, screencast and recording [here](examples/service_catalog).
- SIG Apps - see [recoding of the meeting](https://youtu.be/Eak9EN1PVds?t=875).
- SIG Apps - see [recoding of the meeting](https://youtu.be/Eak9EN1PVds?t=875).

### On [App Controller](https://github.com/Mirantis/k8s-AppController)
Mirantis App Controller (discussed here https://github.com/kubernetes/kubernetes/issues/29453) is a very similar workflow engine with a few differences.
Expand Down Expand Up @@ -241,7 +241,7 @@ those contributing as an individual.
## Stargazers over time

[![Stargazers over time](https://starcharts.herokuapp.com/atlassian/smith.svg)](https://starcharts.herokuapp.com/atlassian/smith)

## License

Copyright (c) 2016-2018 Atlassian and others. Apache 2.0 licensed, see LICENSE file.
6 changes: 4 additions & 2 deletions it/sc/service_catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ func TestServiceCatalog(t *testing.T) {
},
},
{
Name: smith_v1.ResourceName(binding.Name),
DependsOn: []smith_v1.ResourceName{smith_v1.ResourceName(instance.Name)},
Name: smith_v1.ResourceName(binding.Name),
References: []smith_v1.Reference{
{Resource: smith_v1.ResourceName(instance.Name)},
},
Spec: smith_v1.ResourceSpec{
Object: binding,
},
Expand Down
6 changes: 4 additions & 2 deletions it/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ func TestWorkflow(t *testing.T) {
Spec: smith_v1.BundleSpec{
Resources: []smith_v1.Resource{
{
Name: "config1res",
DependsOn: []smith_v1.ResourceName{"secret2res"},
Name: "config1res",
References: []smith_v1.Reference{
{Resource: "secret2res"},
},
Spec: smith_v1.ResourceSpec{
Object: c1,
},
Expand Down
21 changes: 20 additions & 1 deletion pkg/apis/smith/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ func (bs *BundleStatus) GetResourceStatus(resName ResourceName) (int, *ResourceS
// ResourceName is a reference to another Resource in the same bundle.
type ResourceName string

// ReferenceName is a the name of a reference which can be used inside a resource.
type ReferenceName string

// PluginName is a name of a plugin to be invoked.
type PluginName string

Expand All @@ -194,11 +197,27 @@ type Resource struct {
Name ResourceName `json:"name"`

// Explicit dependencies.
DependsOn []ResourceName `json:"dependsOn,omitempty"`
References []Reference `json:"references,omitempty"`

Spec ResourceSpec `json:"spec"`
}

// +k8s:deepcopy-gen=true
// Refer to a part of another object
type Reference struct {
Name ReferenceName `json:"name,omitempty"`
Resource ResourceName `json:"resource"`
Path string `json:"path,omitempty"`
Example interface{} `json:"example,omitempty"`
Modifier string `json:"modifier,omitempty"`
}

// DeepCopyInto is an deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Reference) DeepCopyInto(out *Reference) {
*out = *in
out.Example = runtime.DeepCopyJSONValue(in.Example)
}

// +k8s:deepcopy-gen=true
// ResourceSpec is a union type - either object of plugin can be specified.
type ResourceSpec struct {
Expand Down
20 changes: 16 additions & 4 deletions pkg/apis/smith/v1/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions pkg/controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/diff:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/dynamic:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/bundle_sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ func sortBundle(bundle *smith_v1.Bundle) (*graph.Graph, []graph.V, error) {
}

for _, res := range bundle.Spec.Resources {
for _, d := range res.DependsOn {
if err := g.AddEdge(res.Name, d); err != nil {
for _, reference := range res.References {
if err := g.AddEdge(res.Name, reference.Resource); err != nil {
return nil, nil, err
}
}
Expand Down
90 changes: 78 additions & 12 deletions pkg/controller/controller_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,31 @@ func TestBundleSort(t *testing.T) {
Spec: smith_v1.BundleSpec{
Resources: []smith_v1.Resource{
{
Name: "a",
DependsOn: []smith_v1.ResourceName{"c"},
Name: "a",
References: []smith_v1.Reference{
{
Resource: "c",
},
},
},
{
Name: "b",
},
{
Name: "c",
DependsOn: []smith_v1.ResourceName{"b"},
Name: "c",
References: []smith_v1.Reference{
{
Resource: "b",
},
},
},
{
Name: "d",
DependsOn: []smith_v1.ResourceName{"e"},
Name: "d",
References: []smith_v1.Reference{
{
Resource: "e",
},
},
},
{
Name: "e",
Expand All @@ -48,19 +60,31 @@ func TestBundleSortMissingDependency(t *testing.T) {
Spec: smith_v1.BundleSpec{
Resources: []smith_v1.Resource{
{
Name: "a",
DependsOn: []smith_v1.ResourceName{"x"},
Name: "a",
References: []smith_v1.Reference{
{
Resource: "x",
},
},
},
{
Name: "b",
},
{
Name: "c",
DependsOn: []smith_v1.ResourceName{"b"},
Name: "c",
References: []smith_v1.Reference{
{
Resource: "b",
},
},
},
{
Name: "d",
DependsOn: []smith_v1.ResourceName{"e"},
Name: "d",
References: []smith_v1.Reference{
{
Resource: "e",
},
},
},
{
Name: "e",
Expand All @@ -71,3 +95,45 @@ func TestBundleSortMissingDependency(t *testing.T) {
_, sorted, err := sortBundle(&bundle)
require.EqualError(t, err, "vertex \"x\" not found", "%v", sorted)
}

func TestBundleSortSelfReference(t *testing.T) {
t.Parallel()
bundle := smith_v1.Bundle{
Spec: smith_v1.BundleSpec{
Resources: []smith_v1.Resource{
{
Name: "a",
References: []smith_v1.Reference{
{
Resource: "a",
},
},
},
{
Name: "b",
},
{
Name: "c",
References: []smith_v1.Reference{
{
Resource: "b",
},
},
},
{
Name: "d",
References: []smith_v1.Reference{
{
Resource: "e",
},
},
},
{
Name: "e",
},
},
},
}
_, sorted, err := sortBundle(&bundle)
require.EqualError(t, err, "cycle error: [a a]", "%v", sorted)
}
Loading

0 comments on commit 4cb5cd0

Please sign in to comment.