-
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
WIP: Add option to list all profiles #4512
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
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 config | ||
|
||
import ( | ||
"os" | ||
"github.com/spf13/cobra" | ||
"k8s.io/minikube/pkg/minikube/console" | ||
"k8s.io/minikube/pkg/minikube/exit" | ||
pkgutil "k8s.io/minikube/pkg/util" | ||
"k8s.io/minikube/pkg/minikube/constants" | ||
) | ||
|
||
// ProfileCmd represents the profile command | ||
var ProfilesCmd = &cobra.Command{ | ||
Use: "profiles", | ||
Short: "profiles gets the list of all the present profiles", | ||
Long: "profiles displays a list of all the profiles which have been created earlier.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) > 1 { | ||
exit.Usage("usage: minikube profile [MINIKUBE_PROFILE_NAME]") | ||
} | ||
profiles, err := pkgutil.GetProfiles(constants.KubeconfigPath) | ||
if err != nil { | ||
exit.WithError("Failed to fetch profiles", err) | ||
} | ||
|
||
// check length og profiles, if zero then print suitable message | ||
if len(profiles) == 0 { | ||
console.OutLn("No profiles created yet") | ||
os.Exit(0) | ||
} | ||
|
||
for _, profile := range profiles { | ||
console.OutLn(profile) | ||
} | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -325,3 +325,16 @@ func UnsetCurrentContext(filename, machineName string) error { | |
} | ||
return nil | ||
} | ||
|
||
//Fetch all the profiles and return | ||
func GetProfiles(filename string) ([]string, error) { | ||
config, err := ReadConfigOrNew(filename) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Error getting kubeconfig status") | ||
} | ||
profiles := make([]string, 0, 4) | ||
for context, _ := range config.Contexts { | ||
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. I guess you are mean: "for _, context := ..." here, is it right? 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. Pls run |
||
profiles = append(profiles, context) | ||
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. This is getting all kubecontexts... Inclduing the ones not created by minikube. 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.
that code will get all the kubectl contexts, so for example if I have a GKE cluster or another k8s cluster, they will be in the list of kubectl config get-contexts, and when you create minikube profile it will create another context. if you get list of all contexts and show it as list of profiles, it will show my gke cluster or my other k8s cluster as a minikube profile , so it is wrong |
||
} | ||
return profiles, nil | ||
} |
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.
Change "ProfileCmd" to "ProfilesCmd"