Skip to content

Commit

Permalink
microshift: Use api.crc.testing kubeconfig to connect to cluster
Browse files Browse the repository at this point in the history
With 4.13, after starting the microshift service it create different
kubeconfig according to different additional names/IP. we were using
the localhost one which is mostly for localhost API access so in this
PR we are going to make use of `api.crc.testing` kubecofig file instead
localhost one.

- https://github.com/openshift/microshift/blob/main/docs/howto_kubeconfig.md
- https://access.redhat.com/documentation/en-us/red_hat_build_of_microshift/4.13/html/configuring/microshift-kubeconfig#remote-access-con_microshift-kubeconfig
  • Loading branch information
praveenkumar committed Jun 23, 2023
1 parent bb83956 commit 52cb9b2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 17 deletions.
13 changes: 0 additions & 13 deletions pkg/crc/machine/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,6 @@ func contains(arr []string, str string) bool {
return false
}

func updateServerDetailsToKubeConfig(input, output string) error {
cfg, err := clientcmd.LoadFromFile(input)
if err != nil {
return err
}
for name, cluster := range cfg.Clusters {
if name == "microshift" && cluster.Server == "https://127.0.0.1:6443" {
cluster.Server = fmt.Sprintf("https://api%s:6443", constants.ClusterDomain)
}
}
return clientcmd.WriteToFile(*cfg, output)
}

func mergeKubeConfigFile(kubeConfigFile string) error {
globalConfigPath, kubeConf1, err := getGlobalKubeConfig()
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions pkg/crc/machine/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,15 +1040,12 @@ func startMicroshift(ctx context.Context, sshRunner *crcssh.Runner, ocConfig oc.
if _, _, err := sshRunner.RunPrivileged("Starting microshift service", "systemctl", "start", "microshift"); err != nil {
return err
}
if err := sshRunner.CopyFileFromVM("/var/lib/microshift/resources/kubeadmin/kubeconfig", constants.KubeconfigFilePath, 0600); err != nil {
if err := sshRunner.CopyFileFromVM(fmt.Sprintf("/var/lib/microshift/resources/kubeadmin/api%s/kubeconfig", constants.ClusterDomain), constants.KubeconfigFilePath, 0600); err != nil {
return err
}
if err := sshRunner.CopyFile(constants.KubeconfigFilePath, "/opt/kubeconfig", 0644); err != nil {
return err
}
if err := updateServerDetailsToKubeConfig(constants.KubeconfigFilePath, constants.KubeconfigFilePath); err != nil {
return err
}

if err := cluster.WaitForAPIServer(ctx, ocConfig); err != nil {
return err
Expand Down

0 comments on commit 52cb9b2

Please sign in to comment.