-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
duplicate detection for add commands #564
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,10 @@ type ResourceSpec struct { | |
|
||
var _ addhdlrs.ElementSpec = (*ResourceSpec)(nil) | ||
|
||
func (r *ResourceSpec) GetRawIdentity() metav1.Identity { | ||
return metav1.NewIdentity(r.Name, metav1.SystemIdentityVersion, r.Version) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this constant called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SystemIdentityVersion and SystemIdentityName are the two predefined identity properties use to identify elements (resources, sources, referebces) in CDs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added docu to their const definitions. |
||
} | ||
|
||
func (r *ResourceSpec) Info() string { | ||
return fmt.Sprintf("component %s:%s", r.Name, r.Version) | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -37,6 +37,10 @@ func ProcessDescriptions(ctx clictx.Context, printer common2.Printer, templ temp | |||||
} | ||||||
elems = append(elems, tmp...) | ||||||
} | ||||||
err := ValdateElementIdentities(h.Key(), elems) | ||||||
if err != nil { | ||||||
return nil, nil, err | ||||||
} | ||||||
ictx.Printf("found %d %s\n", len(elems), utils.Plural(h.Key(), len(elems))) | ||||||
return elems, ictx, nil | ||||||
} | ||||||
|
@@ -279,6 +283,39 @@ func Validate(r *ResourceInput, ctx inputs.Context, inputFilePath string) error | |||||
return allErrs.ToAggregate() | ||||||
} | ||||||
|
||||||
func ValdateElementIdentities(kind string, elems []Element) error { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||||||
list := errors.ErrList() | ||||||
ids := map[string]SourceInfo{} | ||||||
for _, r := range elems { | ||||||
var i interface{} | ||||||
err := runtime.DefaultYAMLEncoding.Unmarshal(r.Data(), &i) | ||||||
if err != nil { | ||||||
return errors.Wrapf(err, "cannot eval data %q", string(r.Data())) | ||||||
} | ||||||
id := r.Spec().GetRawIdentity() | ||||||
dig := id.Digest() | ||||||
if s, ok := ids[string(dig)]; ok { | ||||||
list.Add(fmt.Errorf("duplicate %s identity %s (%s and %s)", kind, id, r.Source(), s)) | ||||||
} | ||||||
ids[string(dig)] = r.Source() | ||||||
} | ||||||
return list.Result() | ||||||
} | ||||||
|
||||||
func ValdateElementSpecIdentities(kind string, src string, elems []ElementSpec) error { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the Please choose a more tangible parameter name or add helpful comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added doc to various types and functions |
||||||
list := errors.ErrList() | ||||||
ids := map[string]int{} | ||||||
for i, r := range elems { | ||||||
id := r.GetRawIdentity() | ||||||
dig := id.Digest() | ||||||
if s, ok := ids[string(dig)]; ok { | ||||||
list.Add(fmt.Errorf("duplicate %s identity %s (%s index %d and %d)", kind, id, src, i+1, s+1)) | ||||||
} | ||||||
ids[string(dig)] = i | ||||||
} | ||||||
return list.Result() | ||||||
} | ||||||
|
||||||
func PrintElements(p common2.Printer, elems []Element, outfile string, fss ...vfs.FileSystem) error { | ||||||
if outfile != "" && outfile != "-" { | ||||||
f, err := accessio.FileSystem(fss...).OpenFile(outfile, vfs.O_TRUNC|vfs.O_CREATE|vfs.O_WRONLY, 0o644) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: ocm.software/demo/test | ||
version: 1.0.0 | ||
provider: | ||
name: ocm.software | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
labels: | ||
- name: purpose | ||
value: test | ||
|
||
resources: | ||
- name: text | ||
type: PlainText | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
merge: | ||
algorithm: default | ||
config: | ||
overwrite: inbound | ||
input: | ||
type: file | ||
path: testdata | ||
- name: data | ||
type: PlainText | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
|
||
componentReferences: | ||
- name: ref | ||
version: v1 | ||
componentName: github.com/mandelsoft/test2 | ||
- name: ref | ||
version: v1 | ||
componentName: github.com/mandelsoft/test3 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: ocm.software/demo/test | ||
version: 1.0.0 | ||
provider: | ||
name: ocm.software | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
labels: | ||
- name: purpose | ||
value: test | ||
|
||
resources: | ||
- name: text | ||
type: PlainText | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
merge: | ||
algorithm: default | ||
config: | ||
overwrite: inbound | ||
input: | ||
type: file | ||
path: testdata | ||
- name: data | ||
type: PlainText | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
- name: text | ||
type: PlainText | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
|
||
componentReferences: | ||
- name: ref | ||
version: v1 | ||
componentName: github.com/mandelsoft/test2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: ocm.software/demo/test | ||
version: 1.0.0 | ||
provider: | ||
name: ocm.software | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
labels: | ||
- name: purpose | ||
value: test | ||
|
||
sources: | ||
- name: source | ||
type: DirectoryTree | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
- name: source | ||
type: DirectoryTree | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
|
||
resources: | ||
- name: text | ||
type: PlainText | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
merge: | ||
algorithm: default | ||
config: | ||
overwrite: inbound | ||
input: | ||
type: file | ||
path: testdata | ||
- name: data | ||
type: PlainText | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
|
||
componentReferences: | ||
- name: ref | ||
version: v1 | ||
componentName: github.com/mandelsoft/test2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
components: | ||
- name: ocm.software/demo/test | ||
provider: | ||
name: ocm.software | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
labels: | ||
- name: purpose | ||
value: test | ||
|
||
resources: | ||
- name: text | ||
type: PlainText | ||
labels: | ||
- name: city | ||
value: Karlsruhe | ||
merge: | ||
algorithm: default | ||
config: | ||
overwrite: inbound | ||
input: | ||
type: file | ||
path: testdata | ||
- name: data | ||
type: PlainText | ||
input: | ||
type: binary | ||
data: IXN0cmluZ2RhdGE= | ||
componentReferences: | ||
- name: ref | ||
version: v1 | ||
componentName: github.com/mandelsoft/test2 | ||
|
||
- name: ocm.software/demo/test | ||
provider: | ||
name: ocm.software | ||
labels: | ||
- name: city | ||
value: Karlsruhe |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
references: | ||
- name: testdata | ||
componentName: github.com/mandelsoft/ref | ||
version: v1.1.1 | ||
- name: testdata | ||
componentName: github.com/mandelsoft/ref2 | ||
version: v1.1.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is an elements source (
elem.Source()
)? Confusing name (especially since "Sources" actually are a core model element - is the core model element related to this function? If so, how?)The package addhdlrs (where this function is from) contains generally quite generic coding with non-tangible namings and no comments to support the understanding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added docu