@@ -30,21 +30,16 @@ import (
3030)
3131
3232type ResourceContext struct {
33- ResourceScope string `json:"resourceScope,omitempty"`
34- RawObject []byte `json:"-"`
35- Namespace string `json:"namespace"`
36- Name string `json:"name"`
37- ApiGroup string `json:"apiGroup"`
38- ApiVersion string `json:"apiVersion"`
39- Kind string `json:"kind"`
40- ClaimedMetadata * V2ObjectMetadata `json:"claimedMetadata"`
41- ObjLabels string `json:"objLabels"`
42- ObjMetaName string `json:"objMetaName"`
43- }
44-
45- type V2ObjectMetadata struct {
46- Annotations * ResourceAnnotation `json:"annotations"`
47- Labels * ResourceLabel `json:"labels"`
33+ ResourceScope string `json:"resourceScope,omitempty"`
34+ RawObject []byte `json:"-"`
35+ Namespace string `json:"namespace"`
36+ Name string `json:"name"`
37+ ApiGroup string `json:"apiGroup"`
38+ ApiVersion string `json:"apiVersion"`
39+ Kind string `json:"kind"`
40+ ClaimedMetadata * ObjectMetadata `json:"claimedMetadata"`
41+ ObjLabels string `json:"objLabels"`
42+ ObjMetaName string `json:"objMetaName"`
4843}
4944
5045func (resc * ResourceContext ) ResourceRef () * ResourceRef {
@@ -108,12 +103,12 @@ func (rc *ResourceContext) ExcludeDiffValue() bool {
108103 return false
109104}
110105
111- type V2ParsedRequest struct {
106+ type ParsedResource struct {
112107 JsonStr string
113108}
114109
115- func NewV2ParsedRequest (resource * unstructured.Unstructured ) * V2ParsedRequest {
116- var pr = & V2ParsedRequest {}
110+ func NewParsedResource (resource * unstructured.Unstructured ) * ParsedResource {
111+ var pr = & ParsedResource {}
117112 if resBytes , err := json .Marshal (resource ); err != nil {
118113 logger .WithFields (log.Fields {
119114 "err" : err ,
@@ -125,15 +120,15 @@ func NewV2ParsedRequest(resource *unstructured.Unstructured) *V2ParsedRequest {
125120 return pr
126121}
127122
128- func (pr * V2ParsedRequest ) getValue (path string ) string {
123+ func (pr * ParsedResource ) getValue (path string ) string {
129124 var v string
130125 if w := gjson .Get (pr .JsonStr , path ); w .Exists () {
131126 v = w .String ()
132127 }
133128 return v
134129}
135130
136- func (pr * V2ParsedRequest ) getArrayValue (path string ) []string {
131+ func (pr * ParsedResource ) getArrayValue (path string ) []string {
137132 var v []string
138133 if w := gjson .Get (pr .JsonStr , path ); w .Exists () {
139134 x := w .Array ()
@@ -144,7 +139,7 @@ func (pr *V2ParsedRequest) getArrayValue(path string) []string {
144139 return v
145140}
146141
147- func (pr * V2ParsedRequest ) getAnnotations (path string ) * ResourceAnnotation {
142+ func (pr * ParsedResource ) getAnnotations (path string ) * ResourceAnnotation {
148143 var r map [string ]string = map [string ]string {}
149144 if w := gjson .Get (pr .JsonStr , path ); w .Exists () {
150145 m := w .Map ()
@@ -158,7 +153,7 @@ func (pr *V2ParsedRequest) getAnnotations(path string) *ResourceAnnotation {
158153 }
159154}
160155
161- func (pr * V2ParsedRequest ) getLabels (path string ) * ResourceLabel {
156+ func (pr * ParsedResource ) getLabels (path string ) * ResourceLabel {
162157 var r map [string ]string = map [string ]string {}
163158 if w := gjson .Get (pr .JsonStr , path ); w .Exists () {
164159 m := w .Map ()
@@ -172,7 +167,7 @@ func (pr *V2ParsedRequest) getLabels(path string) *ResourceLabel {
172167 }
173168}
174169
175- func (pr * V2ParsedRequest ) getBool (path string , defaultValue bool ) bool {
170+ func (pr * ParsedResource ) getBool (path string , defaultValue bool ) bool {
176171 if w := gjson .Get (pr .JsonStr , path ); w .Exists () {
177172 v := w .String ()
178173 if b , err := strconv .ParseBool (v ); err != nil {
@@ -186,7 +181,7 @@ func (pr *V2ParsedRequest) getBool(path string, defaultValue bool) bool {
186181
187182func NewResourceContext (res * unstructured.Unstructured ) * ResourceContext {
188183
189- pr := NewV2ParsedRequest (res )
184+ pr := NewParsedResource (res )
190185
191186 name := pr .getValue ("name" )
192187 if name == "" {
@@ -198,7 +193,7 @@ func NewResourceContext(res *unstructured.Unstructured) *ResourceContext {
198193 namespace = pr .getValue ("metadata.namespace" )
199194 }
200195
201- claimedMetadata := & V2ObjectMetadata {
196+ claimedMetadata := & ObjectMetadata {
202197 Annotations : pr .getAnnotations ("metadata.annotations" ),
203198 Labels : pr .getLabels ("metadata.labels" ),
204199 }
0 commit comments