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

[WIP]Component versioning fix and e2e tests #171

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 28 additions & 0 deletions design/one-pager-component-mutable-and-versioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,34 @@ spec:

Still, the `Traffic` trait should handle garbage collection things for the old workloads when no longer needed.

#### Multiple revisions of one Component can exist together

It's allowed to have multiple revisions of the same Component existing simultaneously.

```yaml
apiVersion: core.oam.dev/v1alpha2
kind: ApplicationConfiguration
metadata:
name: my-app-deployment
annotations:
version: v1.0.0
description: "Description of this deployment"
spec:
components:
- revisionName: example-component-1
traits:
- apiversion:core.oam.dev/v1alpha2
kind: ManualScaler
spec:
replicaCount: 3
- revisionName: example-component-2
traits:
- apiversion:core.oam.dev/v1alpha2
kind: ManualScaler
spec:
replicaCount: 2
Comment on lines +376 to +387
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are considering it's an anti-pattern, as we could use two different components to do the same thing. Using different revisions of one component seems don't bring any extra bonus.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, before the proposal is ready, let's suspend this PR. But I will separate e2e test covering current versioning mechanism into another PR as well as the fix of #170.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, we can hold this PR until we have a conclusion on that issue

```

## Example: A blue-green workflow

Let's say we have a `Rollout` Trait with definition like below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ func (c *ComponentHandler) createControllerRevision(mt metav1.Object, obj runtim
// set annotation to component
revision := appsv1.ControllerRevision{
ObjectMeta: metav1.ObjectMeta{
Name: revisionName,
Name: revisionName,
Namespace: curComp.Namespace,
Comment on lines +147 to +148
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you help split the namespace in a separated PR as a BUG fix, thanks.

Copy link
Contributor Author

@captainroy-hy captainroy-hy Aug 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will fix it in another PR.

OwnerReferences: []metav1.OwnerReference{
{
APIVersion: v1alpha2.SchemeGroupVersion.String(),
Expand Down
12 changes: 10 additions & 2 deletions pkg/controller/v1alpha2/applicationconfiguration/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (r *components) renderComponent(ctx context.Context, acc v1alpha2.Applicati
traits = append(traits, &Trait{Object: *t})
traitDefs = append(traitDefs, *traitDef)
}
if err := SetWorkloadInstanceName(traitDefs, w, c); err != nil {
if err := SetWorkloadInstanceName(acc.RevisionName, traitDefs, w, c); err != nil {
return nil, err
}

Expand Down Expand Up @@ -212,12 +212,20 @@ func setTraitProperties(t *unstructured.Unstructured, traitName, namespace strin
}

// SetWorkloadInstanceName will set metadata.name for workload CR according to createRevision flag in traitDefinition
func SetWorkloadInstanceName(traitDefs []v1alpha2.TraitDefinition, w *unstructured.Unstructured, c *v1alpha2.Component) error {
func SetWorkloadInstanceName(revisionName string, traitDefs []v1alpha2.TraitDefinition, w *unstructured.Unstructured, c *v1alpha2.Component) error {
//Don't override the specified name
if w.GetName() != "" {
return nil
}
pv := fieldpath.Pave(w.UnstructuredContent())

// if specified revisionName assigned, use revisionName as the workload name
if revisionName != "" {
if err := pv.SetString(instanceNamePath, revisionName); err != nil {
return errors.Wrapf(err, errSetValueForField, instanceNamePath, revisionName)
}
return nil
}
if isRevisionEnabled(traitDefs) {
// if revisionEnabled, use revisionName as the workload name
if err := pv.SetString(instanceNamePath, c.Status.LatestRevision.Name); err != nil {
Expand Down
18 changes: 15 additions & 3 deletions pkg/controller/v1alpha2/applicationconfiguration/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func TestRenderComponents(t *testing.T) {
Workload: func() *unstructured.Unstructured {
w := &unstructured.Unstructured{}
w.SetNamespace(namespace)
w.SetName(componentName)
w.SetName(revisionName)
w.SetOwnerReferences([]metav1.OwnerReference{*ref})
return w
}(),
Expand Down Expand Up @@ -721,6 +721,7 @@ func TestGetCRDName(t *testing.T) {

func TestSetWorkloadInstanceName(t *testing.T) {
tests := map[string]struct {
rName string
traitDefs []v1alpha2.TraitDefinition
u *unstructured.Unstructured
c *v1alpha2.Component
Expand All @@ -742,6 +743,17 @@ func TestSetWorkloadInstanceName(t *testing.T) {
}},
reason: "workloadName should not change if already set",
},
"with a specified revisionName": {
rName: "specifiedRevisionName",
u: &unstructured.Unstructured{Object: map[string]interface{}{}},
exp: &unstructured.Unstructured{Object: map[string]interface{}{
"metadata": map[string]interface{}{
"name": "specifiedRevisionName",
},
}},
expErr: nil,
reason: "workloadName should use specified revisionName if provide",
},
"revisionEnabled true, set revisionName": {
traitDefs: []v1alpha2.TraitDefinition{
{
Expand Down Expand Up @@ -795,9 +807,9 @@ func TestSetWorkloadInstanceName(t *testing.T) {
for name, ti := range tests {
t.Run(name, func(t *testing.T) {
if ti.expErr != nil {
assert.Equal(t, ti.expErr.Error(), SetWorkloadInstanceName(ti.traitDefs, ti.u, ti.c).Error())
assert.Equal(t, ti.expErr.Error(), SetWorkloadInstanceName(ti.rName, ti.traitDefs, ti.u, ti.c).Error())
} else {
err := SetWorkloadInstanceName(ti.traitDefs, ti.u, ti.c)
err := SetWorkloadInstanceName(ti.rName, ti.traitDefs, ti.u, ti.c)
assert.NoError(t, err)
assert.Equal(t, ti.exp, ti.u, ti.reason)
}
Expand Down
Loading