@@ -91,6 +91,50 @@ func (r *schedulingReconciler) reconcile(ctx context.Context, workspace *tenancy
9191 case ! workspace .DeletionTimestamp .IsZero ():
9292 return reconcileStatusContinue , nil
9393 case workspace .Spec .URL != "" && workspace .Spec .Cluster != "" :
94+ // There might be change in kcp internal URL if underlaying host IP changes when running not in the container.
95+ // This is bit of edge case, but nevertheless we need to check if logical cluster url still matches the workspace url.
96+ clusterNameString , hasCluster := workspace .Annotations [workspaceClusterAnnotationKey ]
97+ clusterName := logicalcluster .Name (clusterNameString )
98+ shardNameHash , hasShard := workspace .Annotations [WorkspaceShardHashAnnotationKey ]
99+ if ! hasShard || ! hasCluster {
100+ return reconcileStatusContinue , nil
101+ }
102+ shard , err := r .getShardByHash (shardNameHash )
103+ if err != nil {
104+ if apierrors .IsNotFound (err ) {
105+ conditions .MarkFalse (workspace , tenancyv1alpha1 .WorkspaceScheduled , tenancyv1alpha1 .WorkspaceReasonUnschedulable , conditionsv1alpha1 .ConditionSeverityError , "chosen shard hash %q does not exist anymore: %v" , shardNameHash , err )
106+ return reconcileStatusContinue , nil
107+ }
108+ return reconcileStatusStopAndRequeue , err
109+ }
110+
111+ parentThis , err := r .getLogicalCluster (logicalcluster .From (workspace ))
112+ if err != nil && ! apierrors .IsNotFound (err ) {
113+ return reconcileStatusStopAndRequeue , err
114+ } else if apierrors .IsNotFound (err ) {
115+ return reconcileStatusStopAndRequeue , nil // wait for parent LogicalCluster to be created
116+ }
117+
118+ u , err := url .Parse (shard .Spec .ExternalURL )
119+ if err != nil {
120+ conditions .MarkFalse (workspace , tenancyv1alpha1 .WorkspaceScheduled , tenancyv1alpha1 .WorkspaceReasonReasonUnknown , conditionsv1alpha1 .ConditionSeverityError , "Invalid connection information on target Shard: %v." , err )
121+ return reconcileStatusStopAndRequeue , err // requeue
122+ }
123+
124+ canonicalPath := logicalcluster .From (workspace ).Path ().Join (workspace .Name )
125+ if parentThis != nil {
126+ if parentPath := parentThis .Annotations [core .LogicalClusterPathAnnotationKey ]; parentPath != "" {
127+ canonicalPath = logicalcluster .NewPath (parentThis .Annotations [core .LogicalClusterPathAnnotationKey ]).Join (workspace .Name )
128+ }
129+ }
130+
131+ u .Path = path .Join (u .Path , canonicalPath .RequestPath ())
132+ if workspace .Spec .URL != u .String () || workspace .Spec .Cluster != clusterName .String () {
133+ workspace .Spec .Cluster = clusterName .String ()
134+ workspace .Spec .URL = u .String ()
135+ return reconcileStatusStopAndRequeue , nil
136+ }
137+
94138 conditions .MarkTrue (workspace , tenancyv1alpha1 .WorkspaceScheduled )
95139 return reconcileStatusContinue , nil
96140 case workspace .Spec .URL == "" || workspace .Spec .Cluster == "" :
0 commit comments