Skip to content

Commit

Permalink
feat: add more APIs about krm-kcl spec and k8s objects
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Jul 12, 2024
1 parent 8b1ffe9 commit a90738c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/kube/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func UnstructuredToObjMetadata(obj *unstructured.Unstructured) ObjMetadata {
}
}

// ObjMetadataID returns the object ID in the format <kind>/<namespace>/<name>.
func ObjMetadataID(obj ObjMetadata) string {
// ID returns the object ID in the format <kind>/<namespace>/<name>.
func (obj *ObjMetadata) ID() string {
var builder strings.Builder
builder.WriteString(obj.GroupKind.Kind + "/")
if obj.Namespace != "" {
Expand Down
7 changes: 4 additions & 3 deletions pkg/kube/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{}),
})
}
Expand Down Expand Up @@ -118,7 +118,8 @@ func CopyAndRemoveMetadataAndStatus(object *unstructured.Unstructured) *unstruct

// UnstructuredID returns the object ID in the format <kind>/<namespace>/<name>.
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
Expand Down

0 comments on commit a90738c

Please sign in to comment.