Skip to content

Commit 802765f

Browse files
authored
Merge pull request #3474 from mjudeikis/mjudeikis/url.change.fix
Fix url update for workspace
2 parents 0fd800e + ae7a255 commit 802765f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pkg/reconciler/tenancy/workspace/workspace_reconcile_scheduling.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)