Skip to content

Commit 5391576

Browse files
authored
fix: resource ID should remain 4 parts (#40)
1 parent 5c4dd6c commit 5391576

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

pkg/resources/kubernetes/kubernetes.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ import (
2727
// its GroupVersionKind and ObjectMeta.
2828
func ToKusionResourceID(gvk schema.GroupVersionKind, objectMeta metav1.ObjectMeta) string {
2929
// resource id example: apps/v1:Deployment:nginx:nginx-deployment
30-
if gvk.Group == "" {
31-
gvk.Group = "core"
32-
}
33-
34-
id := gvk.Group + resources.SegmentSeparator + gvk.Version + resources.SegmentSeparator + gvk.Kind
30+
apiVersion, kind := gvk.ToAPIVersionAndKind()
31+
id := apiVersion + resources.SegmentSeparator + kind
3532
if objectMeta.Namespace != "" {
3633
id += resources.SegmentSeparator + objectMeta.Namespace
3734
}

pkg/resources/terraform/terraform.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ func ToKusionResourceID(p Provider, resourceType, resourceName string) (string,
7070
return "", err
7171
}
7272

73-
tfProviderStr := tfProvider.String()
74-
return strings.Join([]string{tfProviderStr, resourceType, resourceName}, resources.SegmentSeparator), nil
73+
tfProviderIDStr := tfProvider.IDString()
74+
return strings.Join([]string{tfProviderIDStr, resourceType, resourceName}, resources.SegmentSeparator), nil
7575
}
7676

7777
// NewKusionResource creates a Kusion Resource object with the given resourceType, resourceID, attributes.

pkg/resources/terraform/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,8 @@ type TFProvider struct {
4848
func (tp TFProvider) String() string {
4949
return tp.Hostname.ForDisplay() + resources.SegmentSeparator + tp.Namespace + resources.SegmentSeparator + tp.Type
5050
}
51+
52+
// IDString returns the ProviderNamespace:ProviderName string, intended for use in a kusion resource ID.
53+
func (tp TFProvider) IDString() string {
54+
return tp.Namespace + resources.SegmentSeparator + tp.Type
55+
}

0 commit comments

Comments
 (0)