Skip to content

Commit ae3aa02

Browse files
committed
npe fix
1 parent 0542a42 commit ae3aa02

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

pkg/index/index.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,20 @@ func (c *State) UpsertWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
117117
}
118118
}
119119

120-
if cluster := c.shardClusterWorkspaceNameCluster[shard][clusterName][ws.Name]; cluster.String() != ws.Spec.Cluster {
121-
if c.shardClusterWorkspaceNameCluster[shard] == nil {
122-
c.shardClusterWorkspaceNameCluster[shard] = map[logicalcluster.Name]map[string]logicalcluster.Name{}
123-
c.shardClusterWorkspaceName[shard] = map[logicalcluster.Name]string{}
124-
c.shardClusterParentCluster[shard] = map[logicalcluster.Name]logicalcluster.Name{}
125-
}
126-
if c.shardClusterWorkspaceNameCluster[shard][clusterName] == nil {
127-
c.shardClusterWorkspaceNameCluster[shard][clusterName] = map[string]logicalcluster.Name{}
120+
if ws.Spec.Mount == nil { // If there is no mount, spec.cluster is the only source of truth and should be set.
121+
if cluster := c.shardClusterWorkspaceNameCluster[shard][clusterName][ws.Name]; cluster.String() != ws.Spec.Cluster {
122+
if c.shardClusterWorkspaceNameCluster[shard] == nil {
123+
c.shardClusterWorkspaceNameCluster[shard] = map[logicalcluster.Name]map[string]logicalcluster.Name{}
124+
c.shardClusterWorkspaceName[shard] = map[logicalcluster.Name]string{}
125+
c.shardClusterParentCluster[shard] = map[logicalcluster.Name]logicalcluster.Name{}
126+
}
127+
if c.shardClusterWorkspaceNameCluster[shard][clusterName] == nil {
128+
c.shardClusterWorkspaceNameCluster[shard][clusterName] = map[string]logicalcluster.Name{}
129+
}
130+
c.shardClusterWorkspaceNameCluster[shard][clusterName][ws.Name] = logicalcluster.Name(ws.Spec.Cluster)
131+
c.shardClusterWorkspaceName[shard][logicalcluster.Name(ws.Spec.Cluster)] = ws.Name
132+
c.shardClusterParentCluster[shard][logicalcluster.Name(ws.Spec.Cluster)] = clusterName
128133
}
129-
c.shardClusterWorkspaceNameCluster[shard][clusterName][ws.Name] = logicalcluster.Name(ws.Spec.Cluster)
130-
c.shardClusterWorkspaceName[shard][logicalcluster.Name(ws.Spec.Cluster)] = ws.Name
131-
c.shardClusterParentCluster[shard][logicalcluster.Name(ws.Spec.Cluster)] = clusterName
132134
}
133135

134136
if ws.Spec.Mount != nil {

0 commit comments

Comments
 (0)