Skip to content

Commit a6c4c1a

Browse files
committed
Merge resource editor when loaded from cluster with missing defaults
Signed-off-by: Tamal Saha <[email protected]>
1 parent dc9a000 commit a6c4c1a

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ require (
3232
kmodules.xyz/client-go v0.24.0
3333
kmodules.xyz/custom-resources v0.24.0
3434
kmodules.xyz/monitoring-agent-api v0.24.0
35-
kmodules.xyz/resource-metadata v0.11.4-0.20220615081635-1e5360d67b56
35+
kmodules.xyz/resource-metadata v0.11.4-0.20220616232800-ad7e72b89ad2
3636
kmodules.xyz/resource-metrics v0.10.1
3737
kmodules.xyz/sets v0.24.0
3838
kubepack.dev/kubepack v0.4.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1791,8 +1791,8 @@ kmodules.xyz/monitoring-agent-api v0.24.0 h1:CPFvzDppUKckMBLwaMnZbpYCuP7+NhcS4t7
17911791
kmodules.xyz/monitoring-agent-api v0.24.0/go.mod h1:lu1TmXRMx9IcjMpY8s5nc4HNOhOix5/z9caEnbL8JxA=
17921792
kmodules.xyz/offshoot-api v0.24.1 h1:8KCVNkLwdebzWmHcTdZPTQGxqI92bqA+vrmz65ueULY=
17931793
kmodules.xyz/offshoot-api v0.24.1/go.mod h1:fYu0051hoJXXs70OjmIE+Q5smOgmzvYFhRJXCiFShaY=
1794-
kmodules.xyz/resource-metadata v0.11.4-0.20220615081635-1e5360d67b56 h1:8W1WbxolW1CQb6fxlbCA3q2Ml+5tHbsxTSx9kI0AA44=
1795-
kmodules.xyz/resource-metadata v0.11.4-0.20220615081635-1e5360d67b56/go.mod h1:N3pgffPM+AOTBfswdZvCfFsB1IuZ8yzAceZAlnCm1eA=
1794+
kmodules.xyz/resource-metadata v0.11.4-0.20220616232800-ad7e72b89ad2 h1:klAVnT4sw3RBG58fYxcbNVsCdVVymrbFsYjreU7AOZE=
1795+
kmodules.xyz/resource-metadata v0.11.4-0.20220616232800-ad7e72b89ad2/go.mod h1:N3pgffPM+AOTBfswdZvCfFsB1IuZ8yzAceZAlnCm1eA=
17961796
kmodules.xyz/resource-metrics v0.10.1 h1:q1dhk0eYxkZqd1peRy9wHGd8tOktBBH3kzgeTVaNBiY=
17971797
kmodules.xyz/resource-metrics v0.10.1/go.mod h1:YK0hjiLq6oBaGROmLSVcVDbmEgSxT1vpt8BCZZ+9teY=
17981798
kmodules.xyz/sets v0.24.0 h1:GbltLEPVnURjcmWyf8eFstgJBpm9o151wsrABkByGrc=

vendor/kmodules.xyz/resource-metadata/hub/resourceeditors/lib.go

+34-1
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,46 @@ func LoadByGVR(kc client.Client, gvr schema.GroupVersionResource) (*v1alpha1.Res
119119
var ed v1alpha1.ResourceEditor
120120
err := kc.Get(context.TODO(), client.ObjectKey{Name: DefaultEditorName(gvr)}, &ed)
121121
if err == nil {
122-
return &ed, true
122+
d, _ := LoadDefaultByGVR(gvr)
123+
return merge(&ed, d), true
123124
} else if client.IgnoreNotFound(err) != nil {
124125
klog.V(3).InfoS(fmt.Sprintf("failed to load resource editor for %+v", gvr))
125126
}
126127
return LoadDefaultByGVR(gvr)
127128
}
128129

130+
func merge(in, d *v1alpha1.ResourceEditor) *v1alpha1.ResourceEditor {
131+
if d == nil {
132+
return in
133+
}
134+
135+
in.Labels = d.Labels
136+
in.Spec.Resource = d.Spec.Resource
137+
138+
if d.Spec.UI != nil {
139+
if in.Spec.UI == nil {
140+
in.Spec.UI = &v1alpha1.UIParameters{
141+
InstanceLabelPaths: d.Spec.UI.InstanceLabelPaths,
142+
}
143+
}
144+
145+
if d.Spec.UI.Options != nil && in.Spec.UI.Options == nil {
146+
in.Spec.UI.Options = d.Spec.UI.Options
147+
}
148+
if d.Spec.UI.Editor != nil && in.Spec.UI.Editor == nil {
149+
in.Spec.UI.Editor = d.Spec.UI.Editor
150+
}
151+
}
152+
153+
if len(in.Spec.Icons) == 0 {
154+
in.Spec.Icons = d.Spec.Icons
155+
}
156+
if in.Spec.Installer == nil {
157+
in.Spec.Installer = d.Spec.Installer
158+
}
159+
return in
160+
}
161+
129162
func LoadByResourceID(kc client.Client, rid *kmapi.ResourceID) (*v1alpha1.ResourceEditor, bool) {
130163
if rid == nil {
131164
return nil, false

vendor/modules.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ kmodules.xyz/monitoring-agent-api/client
19001900
# kmodules.xyz/offshoot-api v0.24.1
19011901
## explicit; go 1.18
19021902
kmodules.xyz/offshoot-api/api/v1
1903-
# kmodules.xyz/resource-metadata v0.11.4-0.20220615081635-1e5360d67b56
1903+
# kmodules.xyz/resource-metadata v0.11.4-0.20220616232800-ad7e72b89ad2
19041904
## explicit; go 1.18
19051905
kmodules.xyz/resource-metadata/apis/core/install
19061906
kmodules.xyz/resource-metadata/apis/core/v1alpha1

0 commit comments

Comments
 (0)