@@ -53,11 +53,11 @@ func New(rewriters []PathRewriter) *State {
5353 return & State {
5454 rewriters : rewriters ,
5555
56- clusterShards : map [logicalcluster.Name ]string {},
57- shardWorkspaceNameCluster : map [string ]map [logicalcluster.Name ]map [string ]logicalcluster.Name {},
58- shardWorkspaceName : map [string ]map [logicalcluster.Name ]string {},
59- shardClusterParentCluster : map [string ]map [logicalcluster.Name ]logicalcluster.Name {},
60- shardBaseURLs : map [string ]string {},
56+ clusterShards : map [logicalcluster.Name ]string {},
57+ shardClusterWorkspaceNameCluster : map [string ]map [logicalcluster.Name ]map [string ]logicalcluster.Name {},
58+ shardClusterWorkspaceName : map [string ]map [logicalcluster.Name ]string {},
59+ shardClusterParentCluster : map [string ]map [logicalcluster.Name ]logicalcluster.Name {},
60+ shardBaseURLs : map [string ]string {},
6161 // Experimental feature: allow mounts to be used with Workspaces
6262 // structure: (shard, logical cluster, workspace name) -> string serialized mount objects
6363 // This should be simplified once we promote this to workspace structure.
@@ -75,12 +75,12 @@ func New(rewriters []PathRewriter) *State {
7575type State struct {
7676 rewriters []PathRewriter
7777
78- lock sync.RWMutex
79- clusterShards map [logicalcluster.Name ]string // logical cluster -> shard name
80- shardWorkspaceNameCluster map [string ]map [logicalcluster.Name ]map [string ]logicalcluster.Name // (shard name, logical cluster, workspace name) -> logical cluster
81- shardWorkspaceName map [string ]map [logicalcluster.Name ]string // (shard name, logical cluster) -> workspace name
82- shardClusterParentCluster map [string ]map [logicalcluster.Name ]logicalcluster.Name // (shard name, logical cluster) -> parent logical cluster
83- shardBaseURLs map [string ]string // shard name -> base URL
78+ lock sync.RWMutex
79+ clusterShards map [logicalcluster.Name ]string // logical cluster -> shard name
80+ shardClusterWorkspaceNameCluster map [string ]map [logicalcluster.Name ]map [string ]logicalcluster.Name // (shard name, logical cluster, workspace name) -> logical cluster
81+ shardClusterWorkspaceName map [string ]map [logicalcluster.Name ]string // (shard name, logical cluster) -> workspace name
82+ shardClusterParentCluster map [string ]map [logicalcluster.Name ]logicalcluster.Name // (shard name, logical cluster) -> parent logical cluster
83+ shardBaseURLs map [string ]string // shard name -> base URL
8484 // Experimental feature: allow mounts to be used with Workspaces
8585 shardClusterWorkspaceMountAnnotation map [string ]map [logicalcluster.Name ]map [string ]string // (shard name, logical cluster, workspace name) -> mount object string
8686
@@ -103,29 +103,29 @@ func (c *State) UpsertWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
103103 if c .shardClusterWorkspaceNameErrorCode [shard ] == nil {
104104 c .shardClusterWorkspaceNameErrorCode [shard ] = map [logicalcluster.Name ]map [string ]int {}
105105 }
106- if c .shardClusterWorkspaceNameErrorCode [shard ][logicalcluster . Name ( ws . Spec . Cluster ) ] == nil {
107- c .shardClusterWorkspaceNameErrorCode [shard ][logicalcluster . Name ( ws . Spec . Cluster ) ] = map [string ]int {}
106+ if c.shardClusterWorkspaceNameErrorCode [shard ][clusterName ] == nil {
107+ c.shardClusterWorkspaceNameErrorCode [shard ][clusterName ] = map [string ]int {}
108108 }
109109 // Unavailable workspaces should return 503
110- c .shardClusterWorkspaceNameErrorCode [shard ][logicalcluster . Name ( ws . Spec . Cluster ) ][ws .Name ] = 503
110+ c.shardClusterWorkspaceNameErrorCode [shard ][clusterName ][ws .Name ] = 503
111111 } else {
112- delete (c .shardClusterWorkspaceNameErrorCode [shard ][logicalcluster . Name ( ws . Spec . Cluster ) ], ws .Name )
113- if len (c .shardClusterWorkspaceNameErrorCode [shard ][logicalcluster . Name ( ws . Spec . Cluster ) ]) == 0 {
114- delete (c .shardClusterWorkspaceNameErrorCode [shard ], logicalcluster . Name ( ws . Spec . Cluster ) )
112+ delete (c.shardClusterWorkspaceNameErrorCode [shard ][clusterName ], ws .Name )
113+ if len (c.shardClusterWorkspaceNameErrorCode [shard ][clusterName ]) == 0 {
114+ delete (c .shardClusterWorkspaceNameErrorCode [shard ], clusterName )
115115 }
116116 }
117117
118- if cluster := c.shardWorkspaceNameCluster [shard ][clusterName ][ws .Name ]; cluster .String () != ws .Spec .Cluster {
119- if c .shardWorkspaceNameCluster [shard ] == nil {
120- c .shardWorkspaceNameCluster [shard ] = map [logicalcluster.Name ]map [string ]logicalcluster.Name {}
121- c .shardWorkspaceName [shard ] = map [logicalcluster.Name ]string {}
118+ if cluster := c.shardClusterWorkspaceNameCluster [shard ][clusterName ][ws .Name ]; cluster .String () != ws .Spec .Cluster {
119+ if c .shardClusterWorkspaceNameCluster [shard ] == nil {
120+ c .shardClusterWorkspaceNameCluster [shard ] = map [logicalcluster.Name ]map [string ]logicalcluster.Name {}
121+ c .shardClusterWorkspaceName [shard ] = map [logicalcluster.Name ]string {}
122122 c .shardClusterParentCluster [shard ] = map [logicalcluster.Name ]logicalcluster.Name {}
123123 }
124- if c.shardWorkspaceNameCluster [shard ][clusterName ] == nil {
125- c.shardWorkspaceNameCluster [shard ][clusterName ] = map [string ]logicalcluster.Name {}
124+ if c.shardClusterWorkspaceNameCluster [shard ][clusterName ] == nil {
125+ c.shardClusterWorkspaceNameCluster [shard ][clusterName ] = map [string ]logicalcluster.Name {}
126126 }
127- c.shardWorkspaceNameCluster [shard ][clusterName ][ws .Name ] = logicalcluster .Name (ws .Spec .Cluster )
128- c .shardWorkspaceName [shard ][logicalcluster .Name (ws .Spec .Cluster )] = ws .Name
127+ c.shardClusterWorkspaceNameCluster [shard ][clusterName ][ws .Name ] = logicalcluster .Name (ws .Spec .Cluster )
128+ c .shardClusterWorkspaceName [shard ][logicalcluster .Name (ws .Spec .Cluster )] = ws .Name
129129 c .shardClusterParentCluster [shard ][logicalcluster .Name (ws .Spec .Cluster )] = clusterName
130130 }
131131
@@ -144,7 +144,7 @@ func (c *State) DeleteWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
144144 clusterName := logicalcluster .From (ws )
145145
146146 c .lock .RLock ()
147- _ , foundCluster := c.shardWorkspaceNameCluster [shard ][clusterName ][ws .Name ]
147+ _ , foundCluster := c.shardClusterWorkspaceNameCluster [shard ][clusterName ][ws .Name ]
148148 _ , foundMount := c.shardClusterWorkspaceMountAnnotation [shard ][clusterName ][ws .Name ]
149149 c .lock .RUnlock ()
150150
@@ -155,18 +155,18 @@ func (c *State) DeleteWorkspace(shard string, ws *tenancyv1alpha1.Workspace) {
155155 c .lock .Lock ()
156156 defer c .lock .Unlock ()
157157
158- if _ , foundCluster = c.shardWorkspaceNameCluster [shard ][clusterName ][ws .Name ]; foundCluster {
159- delete (c.shardWorkspaceNameCluster [shard ][clusterName ], ws .Name )
160- if len (c.shardWorkspaceNameCluster [shard ][clusterName ]) == 0 {
161- delete (c .shardWorkspaceNameCluster [shard ], clusterName )
158+ if _ , foundCluster = c.shardClusterWorkspaceNameCluster [shard ][clusterName ][ws .Name ]; foundCluster {
159+ delete (c.shardClusterWorkspaceNameCluster [shard ][clusterName ], ws .Name )
160+ if len (c.shardClusterWorkspaceNameCluster [shard ][clusterName ]) == 0 {
161+ delete (c .shardClusterWorkspaceNameCluster [shard ], clusterName )
162162 }
163- if len (c .shardWorkspaceNameCluster [shard ]) == 0 {
164- delete (c .shardWorkspaceNameCluster , shard )
163+ if len (c .shardClusterWorkspaceNameCluster [shard ]) == 0 {
164+ delete (c .shardClusterWorkspaceNameCluster , shard )
165165 }
166166
167- delete (c .shardWorkspaceName [shard ], logicalcluster .Name (ws .Spec .Cluster ))
168- if len (c .shardWorkspaceName [shard ]) == 0 {
169- delete (c .shardWorkspaceName , shard )
167+ delete (c .shardClusterWorkspaceName [shard ], logicalcluster .Name (ws .Spec .Cluster ))
168+ if len (c .shardClusterWorkspaceName [shard ]) == 0 {
169+ delete (c .shardClusterWorkspaceName , shard )
170170 }
171171
172172 delete (c .shardClusterParentCluster [shard ], logicalcluster .Name (ws .Spec .Cluster ))
@@ -238,9 +238,9 @@ func (c *State) DeleteShard(shardName string) {
238238 delete (c .clusterShards , lc )
239239 }
240240 }
241- delete (c .shardWorkspaceNameCluster , shardName )
241+ delete (c .shardClusterWorkspaceNameCluster , shardName )
242242 delete (c .shardBaseURLs , shardName )
243- delete (c .shardWorkspaceName , shardName )
243+ delete (c .shardClusterWorkspaceName , shardName )
244244 delete (c .shardClusterParentCluster , shardName )
245245 delete (c .shardClusterWorkspaceNameErrorCode , shardName )
246246}
@@ -285,19 +285,18 @@ func (c *State) Lookup(path logicalcluster.Path) (Result, bool) {
285285 }
286286 }
287287
288+ if ec , found := c.shardClusterWorkspaceNameErrorCode [shard ][cluster ][s ]; found {
289+ errorCode = ec
290+ }
288291 var found bool
289- cluster , found = c.shardWorkspaceNameCluster [shard ][cluster ][s ]
292+ cluster , found = c.shardClusterWorkspaceNameCluster [shard ][cluster ][s ]
290293 if ! found {
291294 return Result {}, false
292295 }
293296 shard , found = c .clusterShards [cluster ]
294297 if ! found {
295298 return Result {}, false
296299 }
297- ec , found := c.shardClusterWorkspaceNameErrorCode [shard ][cluster ][s ]
298- if found {
299- errorCode = ec
300- }
301300 }
302301 return Result {Shard : shard , Cluster : cluster , ErrorCode : errorCode }, true
303302}
0 commit comments