Skip to content

Commit

Permalink
Use fully qualified ARM ID to disambiguate importers (#3203)
Browse files Browse the repository at this point in the history
  • Loading branch information
theunrepentantgeek authored Aug 22, 2023
1 parent 5761dfb commit 239eea7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
5 changes: 5 additions & 0 deletions v2/cmd/asoctl/internal/importing/importable_arm_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func (i *importableARMResource) Name() string {
return i.armID.Name
}

// Id returns the full ARM ID of the resource we're importing
func (i *importableARMResource) Id() string {
return i.armID.String()
}

// Resource returns the actual resource that is being imported.
// Only available after the import is complete.
func (i *importableARMResource) Resource() genruntime.MetaObject {
Expand Down
7 changes: 6 additions & 1 deletion v2/cmd/asoctl/internal/importing/importable_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ type ImportableResource interface {
// (may be empty if the GK can't be determined)
GroupKind() schema.GroupKind

// Name is a unique identifier for this resource
// Name is a human readable identifier for this resource
Name() string

// Id is a unique identifier for this resource.
// The Id of a resource unique within the import operation; the easiest way to achive this is
// to make it globally unique.
Id() string

// Resource returns the actual resource that has been imported.
// Only available after the import is complete (nil otherwise).
Resource() genruntime.MetaObject
Expand Down
10 changes: 5 additions & 5 deletions v2/cmd/asoctl/internal/importing/resource_importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func (ri *ResourceImporter) addImpl(importer ImportableResource) {
// This happens frequently with extension resources as they can be inherited onto many regular resources
// and we don't want to attempt to import them more than once.
// It can also happen with regular resources if they are referenced by multiple other resources.
if ri.unique.Contains(importer.Name()) {
if ri.unique.Contains(importer.Id()) {
return
}

// Add it to our map and our queue
ri.queue = append(ri.queue, importer.Name())
ri.pending[importer.Name()] = importer
ri.unique.Add(importer.Name())
ri.queue = append(ri.queue, importer.Id())
ri.pending[importer.Id()] = importer
ri.unique.Add(importer.Id())
}

// Import imports all the resources that have been added to the importer.
Expand Down Expand Up @@ -246,7 +246,7 @@ func (ri *ResourceImporter) Complete(importer ImportableResource, pending []Impo
defer ri.lock.Unlock()

// Add it to our map and our queue
ri.imported[importer.Name()] = importer
ri.imported[importer.Id()] = importer
for _, p := range pending {
ri.addImpl(p)
}
Expand Down

0 comments on commit 239eea7

Please sign in to comment.