MCPcopy Index your code
hub / github.com/databus23/helm-diff / ParseObject

Function ParseObject

manifest/parse.go:108–148  ·  view source on GitHub ↗
(object runtime.Object, defaultNamespace string, excludedHooks ...string)

Source from the content-addressed store, hash-verified

106}
107
108func ParseObject(object runtime.Object, defaultNamespace string, excludedHooks ...string) (*MappingResult, string, error) {
109 json, _ := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(object)
110 var objectMap map[string]interface{}
111 err := jsoniter.Unmarshal(json, &objectMap)
112 if err != nil {
113 return nil, "", fmt.Errorf("could not unmarshal byte sequence: %w", err)
114 }
115
116 metadata := objectMap["metadata"].(map[string]interface{})
117 var oldRelease string
118 if a := metadata["annotations"]; a != nil {
119 annotations := a.(map[string]interface{})
120 if releaseNs, ok := annotations["meta.helm.sh/release-namespace"].(string); ok {
121 oldRelease += releaseNs + "/"
122 }
123 if releaseName, ok := annotations["meta.helm.sh/release-name"].(string); ok {
124 oldRelease += releaseName
125 }
126 }
127
128 // Clean namespace metadata as it exists in Kubernetes but not in Helm manifest
129 purgedObj, _ := deleteStatusAndTidyMetadata(json)
130
131 content, err := yaml.Marshal(purgedObj)
132 if err != nil {
133 return nil, "", err
134 }
135
136 result, err := parseContent(content, defaultNamespace, true, excludedHooks...)
137 if err != nil {
138 return nil, "", err
139 }
140
141 if len(result) != 1 {
142 return nil, "", fmt.Errorf("failed to parse content of Kubernetes resource %s", metadata["name"])
143 }
144
145 result[0].Content = strings.TrimSuffix(result[0].Content, "\n")
146
147 return result[0], oldRelease, nil
148}
149
150func parseContent(content []byte, defaultNamespace string, normalizeManifests bool, excludedHooks ...string) ([]*MappingResult, error) {
151 var parsedMetadata metadata

Callers 2

checkOwnershipFunction · 0.92
TestParseObjectFunction · 0.85

Calls 2

parseContentFunction · 0.85

Tested by 1

TestParseObjectFunction · 0.68