K8s: Add generic support for status (#92378)

This commit is contained in:
Todd Treece
2024-08-28 03:45:04 +03:00
committed by GitHub
parent 39fda067cf
commit 85ef26a85d
14 changed files with 233 additions and 34 deletions
+34
View File
@@ -92,6 +92,10 @@ type GrafanaMetaAccessor interface {
GetOriginTimestamp() (*time.Time, error)
GetSpec() (any, error)
SetSpec(any) error
GetStatus() (any, error)
SetStatus(any) error
// Find a title in the object
// This will reflect the object and try to get:
@@ -504,6 +508,36 @@ func (m *grafanaMetaAccessor) GetSpec() (spec any, err error) {
return
}
func (m *grafanaMetaAccessor) SetSpec(s any) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("error setting spec")
}
}()
m.r.FieldByName("Spec").Set(reflect.ValueOf(s))
return
}
func (m *grafanaMetaAccessor) GetStatus() (status any, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("error reading status")
}
}()
status = m.r.FieldByName("Status").Interface()
return
}
func (m *grafanaMetaAccessor) SetStatus(s any) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("error setting status")
}
}()
m.r.FieldByName("Status").Set(reflect.ValueOf(s))
return
}
func (m *grafanaMetaAccessor) FindTitle(defaultTitle string) string {
// look for Spec.Title or Spec.Name
spec := m.r.FieldByName("Spec")