-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Added update-context and kubeconfig to status #1578
Merged
+370
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/golang/glog" | ||
"github.com/spf13/cobra" | ||
cmdUtil "k8s.io/minikube/cmd/util" | ||
"k8s.io/minikube/pkg/minikube/cluster" | ||
"k8s.io/minikube/pkg/minikube/constants" | ||
kcfg "k8s.io/minikube/pkg/minikube/kubeconfig" | ||
"k8s.io/minikube/pkg/minikube/machine" | ||
) | ||
|
||
// updateContextCmd represents the update-context command | ||
var updateContextCmd = &cobra.Command{ | ||
Use: "update-context", | ||
Short: "Verify the IP address of the running cluster in kubeconfig.", | ||
Long: `Retrieves the IP address of the running cluster, checks it | ||
with IP in kubeconfig, and corrects kubeconfig if incorrect.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
api, err := machine.NewAPIClient(clientType) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Error getting client: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer api.Close() | ||
ip, err := cluster.GetHostDriverIP(api) | ||
if err != nil { | ||
glog.Errorln("Error host driver ip status:", err) | ||
cmdUtil.MaybeReportErrorAndExit(err) | ||
} | ||
kstatus, err := kcfg.UpdateKubeconfigIP(ip, constants.KubeconfigPath) | ||
if err != nil { | ||
glog.Errorln("Error kubeconfig status:", err) | ||
cmdUtil.MaybeReportErrorAndExit(err) | ||
} | ||
if kstatus { | ||
fmt.Println("Reconfigured kubeconfig IP, now pointing at " + ip.String()) | ||
} else { | ||
fmt.Println("Kubeconfig IP correctly configured, pointing at " + ip.String()) | ||
} | ||
|
||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(updateContextCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,6 +165,24 @@ func GetLocalkubeStatus(api libmachine.API) (string, error) { | |
} | ||
} | ||
|
||
// GetHostDriverIP gets the ip address of the current minikube cluster | ||
func GetHostDriverIP(api libmachine.API) (net.IP, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, I can't believe we didn't have something like this before. Out of scope for this PR, but we might want to consider moving some of our other functions that just call Driver.GetIP() directly to use this, so we can pass around a real |
||
host, err := CheckIfApiExistsAndLoad(api) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
ipStr, err := host.Driver.GetIP() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Error getting IP") | ||
} | ||
ip := net.ParseIP(ipStr) | ||
if ip == nil { | ||
return nil, errors.Wrap(err, "Error parsing IP") | ||
} | ||
return ip, nil | ||
} | ||
|
||
// StartCluster starts a k8s cluster on the specified Host. | ||
func StartCluster(api libmachine.API, kubernetesConfig KubernetesConfig) error { | ||
h, err := CheckIfApiExistsAndLoad(api) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once #1544 is merged, this will become
machine.NewAPIClient()