From a90738c67ae2b8eb817f3ab994ba18b151e553cc Mon Sep 17 00:00:00 2001 From: peefy Date: Fri, 12 Jul 2024 13:47:26 +0800 Subject: [PATCH] feat: add more APIs about krm-kcl spec and k8s objects Signed-off-by: peefy --- pkg/kube/metadata.go | 4 ++-- pkg/kube/utils.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/kube/metadata.go b/pkg/kube/metadata.go index c5c5b59..82edae6 100644 --- a/pkg/kube/metadata.go +++ b/pkg/kube/metadata.go @@ -27,8 +27,8 @@ func UnstructuredToObjMetadata(obj *unstructured.Unstructured) ObjMetadata { } } -// ObjMetadataID returns the object ID in the format //. -func ObjMetadataID(obj ObjMetadata) string { +// ID returns the object ID in the format //. +func (obj *ObjMetadata) ID() string { var builder strings.Builder builder.WriteString(obj.GroupKind.Kind + "/") if obj.Namespace != "" { diff --git a/pkg/kube/utils.go b/pkg/kube/utils.go index de5842d..c6b1f05 100644 --- a/pkg/kube/utils.go +++ b/pkg/kube/utils.go @@ -32,7 +32,7 @@ func YamlByteToUnstructured(yamlByte []byte) (*unstructured.Unstructured, error) } // YamlByteToUnstructured returns the manifests list from the YAML stream data. -func YamlStreamByteToUnstructuredList(yamlByte []byte) (result []unstructured.Unstructured, err error) { +func YamlStreamByteToUnstructuredList(yamlByte []byte) (result []*unstructured.Unstructured, err error) { bytes, err := krmyaml.SplitDocuments(string(yamlByte)) if err != nil { return @@ -50,7 +50,7 @@ func YamlStreamByteToUnstructuredList(yamlByte []byte) (result []unstructured.Un return nil, err } - result = append(result, unstructured.Unstructured{ + result = append(result, &unstructured.Unstructured{ Object: normalizedData.(map[string]interface{}), }) } @@ -118,7 +118,8 @@ func CopyAndRemoveMetadataAndStatus(object *unstructured.Unstructured) *unstruct // UnstructuredID returns the object ID in the format //. func UnstructuredID(obj *unstructured.Unstructured) string { - return ObjMetadataID(UnstructuredToObjMetadata(obj)) + m := UnstructuredToObjMetadata(obj) + return m.ID() } // NormalizeServerSideFields removes the metadata and status fields from the object to