[go: nahoru, domu]

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

Commit

Permalink
change workloadRefPath => workloadRefsPath since Scope accepts an arr…
Browse files Browse the repository at this point in the history
…ay of workloads

Signed-off-by: roy wang <seiwy2010@gmail.com>
  • Loading branch information
captainroy-hy committed Jul 18, 2020
1 parent c18f097 commit 177131d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions apis/core/v1alpha2/core_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ type ScopeDefinitionSpec struct {
// Reference to the CustomResourceDefinition that defines this scope kind.
Reference DefinitionReference `json:"definitionRef"`

// WorkloadRefPath indicates if/where a scope accepts a workloadRef object
WorkloadRefPath string `json:"workloadRefPath,omitempty"`
// WorkloadRefsPath indicates if/where a scope accepts workloadRef objects
WorkloadRefsPath string `json:"workloadRefsPath,omitempty"`

// AllowComponentOverlap specifies whether an OAM component may exist in
// multiple instances of this kind of scope.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ spec:
required:
- name
type: object
workloadRefPath:
description: WorkloadRefPath indicates if/where a scope accepts a workloadRef
object
workloadRefsPath:
description: WorkloadRefsPath indicates if/where a scope accepts workloadRef
objects
type: string
required:
- allowComponentOverlap
Expand Down
4 changes: 2 additions & 2 deletions design/one-pager-scope-workload-interaction-mechanism.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ But currently we can't, because OAM implementation assumes that every eligible `
The overall idea is for the applicationConfiguration controller to fill critical information in the workload and scope CRs.
In addition, we will provide a helper library so that scope controller developers can locate the resources they need with a simple function call.
Here is the list of changes that we propose.
1. Add an optional field called `workloadRefPath` to the `scopeDefinition` schema. This is for the scope owner to declare that the scope relies on the OAM scope/workload interaction mechanism.
1. Add an optional field called `workloadRefsPath` to the `scopeDefinition` schema. This is for the scope owner to declare that the scope relies on the OAM scope/workload interaction mechanism.
The value of the field is the path to the field that takes `workloadRef` objects.
In our example, the scope definition would look like below since our `HealthScope` takes the `workloadRef` field at `spec.workloadRefs`.
```yaml
Expand All @@ -106,7 +106,7 @@ In our example, the scope definition would look like below since our `HealthScop
metadata:
name: healthscopes.core.oam.dev
spec:
workloadRefPath: spec.workloadRefs
workloadRefsPath: spec.workloadRefs
definitionRef:
name: healthscopes.core.oam.dev
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: ScopeDefinition
metadata:
name: healthscope.core.oam.dev
spec:
workloadRefPath: spec.workloadRefs
workloadRefsPath: spec.workloadRefs
allowComponentOverlap: true
definitionRef:
name: healthscope.core.oam.dev
Expand Down
42 changes: 21 additions & 21 deletions pkg/controller/v1alpha2/applicationconfiguration/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import (

// Reconcile error strings.
const (
errFmtApplyWorkload = "cannot apply workload %q"
errFmtSetWorkloadRef = "cannot set trait %q reference to %q"
errFmtSetScopeWorkloadRef = "cannot set scope %q reference to %q"
errFmtGetTraitDefinition = "cannot find trait definition %q %q %q"
errFmtGetScopeDefinition = "cannot find scope definition %q %q %q"
errFmtGetScopeWorkloadRef = "cannot find scope workloadRef %q %q %q with workloadRefPath %q"
errFmtGetScopeWorkloadRefPath = "cannot get workloadRefPath for scope to be dereferenced %q %q %q"
errFmtApplyTrait = "cannot apply trait %q %q %q"
errFmtApplyScope = "cannot apply scope %q %q %q"
errFmtApplyWorkload = "cannot apply workload %q"
errFmtSetWorkloadRef = "cannot set trait %q reference to %q"
errFmtSetScopeWorkloadRef = "cannot set scope %q reference to %q"
errFmtGetTraitDefinition = "cannot find trait definition %q %q %q"
errFmtGetScopeDefinition = "cannot find scope definition %q %q %q"
errFmtGetScopeWorkloadRef = "cannot find scope workloadRef %q %q %q with workloadRefsPath %q"
errFmtGetScopeWorkloadRefsPath = "cannot get workloadRefsPath for scope to be dereferenced %q %q %q"
errFmtApplyTrait = "cannot apply trait %q %q %q"
errFmtApplyScope = "cannot apply scope %q %q %q"
)

// A WorkloadApplicator creates or updates workloads and their traits.
Expand Down Expand Up @@ -159,14 +159,14 @@ func (a *workloads) applyScope(ctx context.Context, wl Workload, s unstructured.
return errors.Wrapf(err, errFmtGetScopeDefinition, s.GetAPIVersion(), s.GetKind(), s.GetName())
}
// checkout whether scope asks for workloadRef
workloadRefPath := scopeDefinition.Spec.WorkloadRefPath
if len(workloadRefPath) == 0 {
workloadRefsPath := scopeDefinition.Spec.WorkloadRefsPath
if len(workloadRefsPath) == 0 {
// this scope does not ask for workloadRefs
return nil
}

var refs []interface{}
if value, err := fieldpath.Pave(s.UnstructuredContent()).GetValue(workloadRefPath); err == nil {
if value, err := fieldpath.Pave(s.UnstructuredContent()).GetValue(workloadRefsPath); err == nil {
refs = value.([]interface{})

for _, item := range refs {
Expand All @@ -179,11 +179,11 @@ func (a *workloads) applyScope(ctx context.Context, wl Workload, s unstructured.
}
}
} else {
return errors.Wrapf(err, errFmtGetScopeWorkloadRef, s.GetAPIVersion(), s.GetKind(), s.GetName(), workloadRefPath)
return errors.Wrapf(err, errFmtGetScopeWorkloadRef, s.GetAPIVersion(), s.GetKind(), s.GetName(), workloadRefsPath)
}

refs = append(refs, workloadRef)
if err := fieldpath.Pave(s.UnstructuredContent()).SetValue(workloadRefPath, refs); err != nil {
if err := fieldpath.Pave(s.UnstructuredContent()).SetValue(workloadRefsPath, refs); err != nil {
return errors.Wrapf(err, errFmtSetScopeWorkloadRef, s.GetName(), wl.Workload.GetName())
}

Expand Down Expand Up @@ -214,13 +214,13 @@ func (a *workloads) applyScopeRemoval(ctx context.Context, namespace string, ws
return errors.Wrapf(err, errFmtGetScopeDefinition, scopeObject.GetAPIVersion(), scopeObject.GetKind(), scopeObject.GetName())
}

workloadRefPath := scopeDefinition.Spec.WorkloadRefPath
if len(workloadRefPath) == 0 {
// Scopes to be dereferenced MUST have workloadRefPath
return errors.Errorf(errFmtGetScopeWorkloadRefPath, scopeObject.GetAPIVersion(), scopeObject.GetKind(), scopeObject.GetName())
workloadRefsPath := scopeDefinition.Spec.WorkloadRefsPath
if len(workloadRefsPath) == 0 {
// Scopes to be dereferenced MUST have workloadRefsPath
return errors.Errorf(errFmtGetScopeWorkloadRefsPath, scopeObject.GetAPIVersion(), scopeObject.GetKind(), scopeObject.GetName())
}

if value, err := fieldpath.Pave(scopeObject.UnstructuredContent()).GetValue(workloadRefPath); err == nil {
if value, err := fieldpath.Pave(scopeObject.UnstructuredContent()).GetValue(workloadRefsPath); err == nil {
refs := value.([]interface{})

workloadRefIndex := -1
Expand All @@ -239,7 +239,7 @@ func (a *workloads) applyScopeRemoval(ctx context.Context, namespace string, ws
refs[workloadRefIndex] = refs[len(refs)-1]
refs = refs[:len(refs)-1]

if err := fieldpath.Pave(scopeObject.UnstructuredContent()).SetValue(workloadRefPath, refs); err != nil {
if err := fieldpath.Pave(scopeObject.UnstructuredContent()).SetValue(workloadRefsPath, refs); err != nil {
return errors.Wrapf(err, errFmtSetScopeWorkloadRef, s.Reference.Name, ws.Reference.Name)
}

Expand All @@ -249,7 +249,7 @@ func (a *workloads) applyScopeRemoval(ctx context.Context, namespace string, ws
}
} else {
return errors.Wrapf(err, errFmtGetScopeWorkloadRef,
scopeObject.GetAPIVersion(), scopeObject.GetKind(), scopeObject.GetName(), workloadRefPath)
scopeObject.GetAPIVersion(), scopeObject.GetKind(), scopeObject.GetName(), workloadRefsPath)
}
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestApplyWorkloads(t *testing.T) {
Reference: v1alpha2.DefinitionReference{
Name: "scope-example.scope.oam.dev",
},
WorkloadRefPath: "spec.workloadRefs",
WorkloadRefsPath: "spec.workloadRefs",
},
}

Expand Down
2 changes: 1 addition & 1 deletion test/e2e-test/health_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var _ = Describe("HealthScope", func() {
},
Spec: v1alpha2.ScopeDefinitionSpec{
AllowComponentOverlap: true,
WorkloadRefPath: "spec.workloadRefs",
WorkloadRefsPath: "spec.workloadRefs",
Reference: v1alpha2.DefinitionReference{
Name: "healthscope.core.oam.dev",
},
Expand Down

0 comments on commit 177131d

Please sign in to comment.