Skip to content

Commit

Permalink
Use urn.Type instead of QualifiedType
Browse files Browse the repository at this point in the history
  • Loading branch information
rquitales committed Dec 14, 2023
1 parent 9f7d864 commit 876df53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Unreleased
- Fix: Refine URN lookup by implementing suffix search for more accurate resource identification (https://github.com/pulumi/pulumi-kubernetes/issues/2719)

## 4.6.1 (December 14, 2023)
- Fix: Refine URN lookup by using its core type for more accurate resource identification (https://github.com/pulumi/pulumi-kubernetes/issues/2719)

## 4.6.0 (December 13, 2023)
- Fix: Helm OCI chart deployment fails in Windows (https://github.com/pulumi/pulumi-kubernetes/pull/2648)
Expand Down
34 changes: 4 additions & 30 deletions provider/pkg/kinds/util.go
Original file line number Diff line number Diff line change
@@ -1,45 +1,19 @@
package kinds

import (
"strings"

"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
)

func suffixSearch(s string, suffixes []string) bool {
for _, suffix := range suffixes {
if strings.HasSuffix(s, suffix) {
return true
}
}
return false
}

// IsPatchURN returns true if the URN is for a Patch resource.
func IsPatchURN(urn resource.URN) bool {
urnS := urn.QualifiedType().String()
urnS := urn.Type().String()

// Do a simple O(1) lookup in a set of known patch types.
if PatchQualifiedTypes.Has(urnS) {
return true
}

// Do a suffix search in case the resource is a component resource containing
// a patch resource. Eg. a component resource patch resource could have the following URN:
// my:component:Resource$kubernetes:apps/v1:DaemonSetPatch.
return suffixSearch(urnS, PatchQualifiedTypes.SortedValues())
return PatchQualifiedTypes.Has(urnS)
}

// IsListURN returns true if the URN is for a List resource.
func IsListURN(urn resource.URN) bool {
urnS := urn.QualifiedType().String()

// Do a simple O(1) lookup in a set of known list types.
if ListQualifiedTypes.Has(urnS) {
return true
}
urnS := urn.Type().String()

// Do a suffix search in case the resource is a component resource containing
// a list resource.
return suffixSearch(urnS, ListQualifiedTypes.SortedValues())
return ListQualifiedTypes.Has(urnS)
}

0 comments on commit 876df53

Please sign in to comment.