Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fix workspace output when enter into home workspace #2830

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pkg/cliplugins/workspace/plugin/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,21 @@ func (o *UseWorkspaceOptions) Run(ctx context.Context) error {
if err != nil {
return err
}
newServerHost = homeWorkspace.Spec.URL

u, homeCluster, err := pluginhelpers.ParseClusterURL(homeWorkspace.Spec.URL)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

homeWorkspace.Spec.URL has the path. We just have to extract it from the URL. We have a helper here somewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would rather not go through the LogicalCluster for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think currently the value lf homeWorkspace.Spec.URL is the same as path annotation in LogicalCluster. homeWorkspace.Spec.URL is https://xxx/clusters/kvdk2spgmbix while path annotation is user:kcp-admin. Should homeWorkspace.Spec.URL be https://xxx/clusters/user:kcp-admin?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would rather not go through the LogicalCluster for that.

@sttts what would be an alternate solution ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should homeWorkspace.Spec.URL be https://xxx/clusters/user:kcp-admin?

Yes, I think it should.

Copy link
Member

@davidfestal davidfestal Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so that means that the problem is at a different level, when this URL is set in the Spec.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sttts would you check if #2846 is the appropriate way.

if err != nil {
return fmt.Errorf("home URL %q does not point to a workspace: %w", homeWorkspace.Spec.URL, err)
}
homeLogicalCluster, err := o.kcpClusterClient.Cluster(homeCluster).CoreV1alpha1().LogicalClusters().Get(ctx, corev1alpha1.LogicalClusterName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get logical cluster of home workspace: %w", err)
}
homePath, ok := homeLogicalCluster.Annotations[core.LogicalClusterPathAnnotationKey]
if !ok {
return fmt.Errorf("cannot find the path info from the home workspace")
}
cluster := logicalcluster.NewPath(homePath)
u.Path = path.Join(u.Path, cluster.RequestPath())
newServerHost = u.String()
case ".":
cfg, err := o.ClientConfig.ClientConfig()
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/cliplugins/workspace/plugin/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,25 @@ func TestUse(t *testing.T) {
return false, nil, nil
})

client.PrependReactor("get", "logicalclusters", func(action kcptesting.Action) (handled bool, ret runtime.Object, err error) {
getAction := action.(kcptesting.GetAction)
if getAction.GetCluster() != homeWorkspaceLogicalCluster {
return false, nil, nil
}
if getAction.GetName() == corev1alpha1.LogicalClusterName {
logicalCluster := &corev1alpha1.LogicalCluster{
ObjectMeta: metav1.ObjectMeta{
Name: corev1alpha1.LogicalClusterName,
Annotations: map[string]string{
core.LogicalClusterPathAnnotationKey: homeWorkspaceLogicalCluster.String(),
},
},
}
return true, logicalCluster, nil
}
return false, nil, nil
})

// return nothing in the default case.
getAPIBindings := func(ctx context.Context, kcpClusterClient kcpclientset.ClusterInterface, host string) ([]apisv1alpha1.APIBinding, error) {
return nil, nil
Expand Down