Skip to content

Commit

Permalink
Make additionalPrinterColumns simple dict
Browse files Browse the repository at this point in the history
  • Loading branch information
RafikFarhad committed Dec 31, 2023
1 parent 95f5b42 commit 384aa43
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
13 changes: 4 additions & 9 deletions modules/api/pkg/resource/customresourcedefinition/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,12 @@ type CustomResourceDefinitionVersion struct {
AdditionalPrinterColumns []AdditionalPrinterColumn `json:"additionalPrinterColumns"`
}

type AdditionalPrinterColumnWithValue struct {
Name string `json:"name"`
Value string `json:"value"`
}

// CustomResourceObject represents a custom resource object.
type CustomResourceObject struct {
AdditionalPrinterColumns []AdditionalPrinterColumnWithValue `json:"additionalPrinterColumns,omitempty"`
RawObject unstructured.Unstructured `json:"-"` // the raw object as map[string]interface{} to grep the value for AdditionalPrinterColumnWithValue which is present on the CRD Details
TypeMeta api.TypeMeta `json:"typeMeta"`
ObjectMeta api.ObjectMeta `json:"objectMeta"`
AdditionalPrinterColumns map[string]interface{} `json:"additionalPrinterColumns,omitempty"`
RawObject unstructured.Unstructured `json:"-"` // the raw object as map[string]interface{} to grep the value for AdditionalPrinterColumnWithValue which is present on the CRD Details
TypeMeta api.TypeMeta `json:"typeMeta"`
ObjectMeta api.ObjectMeta `json:"objectMeta"`
}

func (r *CustomResourceObject) UnmarshalJSON(data []byte) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,10 @@ func toCRDObject(object *types.CustomResourceObject, crd *apiextensionsv1.Custom
object.TypeMeta.Kind = api.ResourceKind(crd.Name)
crdSubresources := crd.Spec.Versions[0].Subresources
object.TypeMeta.Scalable = crdSubresources != nil && crdSubresources.Scale != nil
object.AdditionalPrinterColumns = make(map[string]interface{})
for _, col := range crd.Spec.Versions[0].AdditionalPrinterColumns {
val, _, _ := unstructured.NestedString(object.RawObject.Object, splitJsonPath(col.JSONPath)...)
//if val != "" {
object.AdditionalPrinterColumns = append(object.AdditionalPrinterColumns, types.AdditionalPrinterColumnWithValue{
Name: col.Name,
Value: val,
})
//}
object.AdditionalPrinterColumns[col.Name] = val
}
}

Expand Down

0 comments on commit 384aa43

Please sign in to comment.