Skip to content

Commit

Permalink
feat: set .Spec.ControlPlaneEndpoint if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
matskiv committed Jun 30, 2022
1 parent be165fb commit 0b963ab
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions controllers/vcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ func (r *VClusterReconciler) syncVClusterKubeconfig(ctx context.Context, vCluste
if err != nil {
return err
}
//TODO write back vcluster.spec.controlPlaneEndpoint.Host
// write the discovered host back into vCluster CR
vCluster.Spec.ControlPlaneEndpoint.Host = controlPlaneHost
if vCluster.Spec.ControlPlaneEndpoint.Port == 0 {
vCluster.Spec.ControlPlaneEndpoint.Port = DefaultControlPlanePort
}
}

for k := range kubeConfig.Clusters {
Expand Down Expand Up @@ -412,9 +416,9 @@ func DiscoverHostFromService(ctx context.Context, client client.Client, vCluster
service := &corev1.Service{}
err = client.Get(context.TODO(), types.NamespacedName{Namespace: vCluster.Namespace, Name: vCluster.Name}, service)
if err != nil {
// if kerrors.IsNotFound(err) {
// return true, nil
// }
if kerrors.IsNotFound(err) {
return true, nil
}

return false, err
}
Expand Down Expand Up @@ -444,6 +448,9 @@ func DiscoverHostFromService(ctx context.Context, client client.Client, vCluster
return "", fmt.Errorf("can not get vcluster service: %v", err)
}

if host == "" {
host = fmt.Sprintf("%s.%s.svc", vCluster.Name, vCluster.Namespace)
}
return host, nil
}

Expand Down

0 comments on commit 0b963ab

Please sign in to comment.