Skip to content

Commit a0fe006

Browse files
palnabarunmjudeikis
authored andcommitted
make the type and cluster reflection optional
Signed-off-by: Nabarun Pal <[email protected]>
1 parent ae2ca7e commit a0fe006

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

pkg/reconciler/tenancy/workspacemounts/workspacemounts_reconcile_updater.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,39 @@ func fillWorkspaceSpec(obj *unstructured.Unstructured, workspace *tenancyv1alpha
139139
}
140140
workspace.Spec.URL = statusURL
141141

142-
clusterName, _, _ := unstructured.NestedString(obj.Object, "status", "cluster")
143-
workspace.Spec.Cluster = clusterName
142+
// cluster is optional since not all moounts will point to a KCP workspace
143+
clusterName, found, err := unstructured.NestedString(obj.Object, "status", "cluster")
144+
if err != nil {
145+
return fmt.Errorf("unable to read .status.cluster, err: %w", err)
146+
}
147+
if found {
148+
workspace.Spec.Cluster = clusterName
149+
}
144150

151+
// type is optional since not all mounts will point to a KCP workspace
152+
_, found, err = unstructured.NestedStringMap(obj.Object, "status", "type")
153+
if err != nil {
154+
return fmt.Errorf("unable to read .status.type, err: %w", err)
155+
}
156+
if !found {
157+
return nil
158+
}
159+
160+
// at this point, the mount object has a type field, so we can attempt to read it's attributes
145161
wsTypeName, found, err := unstructured.NestedString(obj.Object, "status", "type", "name")
146162
if !found || err != nil {
147163
return fmt.Errorf("unable to read .status.type.name, found %v, err: %w", found, err)
148164
}
149165

150-
if workspace.Spec.Type == nil {
151-
workspace.Spec.Type = &tenancyv1alpha1.WorkspaceTypeReference{}
152-
}
153-
workspace.Spec.Type.Name = tenancyv1alpha1.WorkspaceTypeName(wsTypeName)
154-
155166
wsTypePath, found, err := unstructured.NestedString(obj.Object, "status", "type", "path")
156167
if !found || err != nil {
157168
return fmt.Errorf("unable to read .status.type.path, found %v, err: %w", found, err)
158169
}
170+
171+
if workspace.Spec.Type == nil {
172+
workspace.Spec.Type = &tenancyv1alpha1.WorkspaceTypeReference{}
173+
}
174+
workspace.Spec.Type.Name = tenancyv1alpha1.WorkspaceTypeName(wsTypeName)
159175
workspace.Spec.Type.Path = wsTypePath
160176

161177
return nil

0 commit comments

Comments
 (0)