本文整理汇总了Golang中k8s/io/kubernetes/pkg/util/homedir.HomeDir函数的典型用法代码示例。如果您正苦于以下问题:Golang HomeDir函数的具体用法?Golang HomeDir怎么用?Golang HomeDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HomeDir函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getFabric8BinLocation
func getFabric8BinLocation() string {
home := homedir.HomeDir()
if home == "" {
util.Fatalf("No user home environment variable found for OS %s", runtime.GOOS)
}
return filepath.Join(home, ".fabric8", "bin")
}
示例2: currentMigrationRules
// currentMigrationRules returns a map that holds the history of recommended home directories used in previous versions.
// Any future changes to RecommendedHomeFile and related are expected to add a migration rule here, in order to make
// sure existing config files are migrated to their new locations properly.
func currentMigrationRules() map[string]string {
oldRecommendedHomeFile := path.Join(homedir.HomeDir(), ".kube/.config")
oldRecommendedWindowsHomeFile := path.Join(os.Getenv("HOME"), OpenShiftConfigHomeDirFileName)
migrationRules := map[string]string{}
migrationRules[RecommendedHomeFile] = oldRecommendedHomeFile
if runtime.GOOS == "windows" {
migrationRules[RecommendedHomeFile] = oldRecommendedWindowsHomeFile
}
return migrationRules
}
示例3: isInstalled
func isInstalled(isMinishift bool) bool {
home := homedir.HomeDir()
if home == "" {
util.Fatalf("No user home environment variable found for OS %s", runtime.GOOS)
}
// check if we can find a local kube config file
if _, err := os.Stat(home + "/.kube/config"); os.IsNotExist(err) {
return false
}
// check for kubectl
_, err := exec.LookPath(kubectl)
if err != nil {
return false
}
if isMinishift {
// check for minishift
_, err = exec.LookPath(minishift)
if err != nil {
return false
}
// check for oc client
_, err = exec.LookPath(oc)
if err != nil {
return false
}
} else {
// check for minikube
_, err = exec.LookPath(minikube)
if err != nil {
return false
}
}
return true
}
示例4: currentMigrationRules
clientcmdapi "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api"
clientcmdlatest "k8s.io/kubernetes/pkg/client/unversioned/clientcmd/api/latest"
"k8s.io/kubernetes/pkg/runtime"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/homedir"
)
const (
RecommendedConfigPathFlag = "kubeconfig"
RecommendedConfigPathEnvVar = "KUBECONFIG"
RecommendedHomeDir = ".kube"
RecommendedFileName = "config"
RecommendedSchemaName = "schema"
)
var RecommendedHomeFile = path.Join(homedir.HomeDir(), RecommendedHomeDir, RecommendedFileName)
var RecommendedSchemaFile = path.Join(homedir.HomeDir(), RecommendedHomeDir, RecommendedSchemaName)
// currentMigrationRules returns a map that holds the history of recommended home directories used in previous versions.
// Any future changes to RecommendedHomeFile and related are expected to add a migration rule here, in order to make
// sure existing config files are migrated to their new locations properly.
func currentMigrationRules() map[string]string {
oldRecommendedHomeFile := path.Join(os.Getenv("HOME"), "/.kube/.kubeconfig")
oldRecommendedWindowsHomeFile := path.Join(os.Getenv("HOME"), RecommendedHomeDir, RecommendedFileName)
migrationRules := map[string]string{}
migrationRules[RecommendedHomeFile] = oldRecommendedHomeFile
if goruntime.GOOS == "windows" {
migrationRules[RecommendedHomeFile] = oldRecommendedWindowsHomeFile
}
return migrationRules
示例5: NewFactory
// NewFactory creates an object that holds common methods across all OpenShift commands
func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
restMapper := registered.RESTMapper()
clients := &clientCache{
clients: make(map[string]*client.Client),
configs: make(map[string]*restclient.Config),
loader: clientConfig,
}
w := &Factory{
Factory: cmdutil.NewFactory(clientConfig),
OpenShiftClientConfig: clientConfig,
clients: clients,
ImageResolutionOptions: &imageResolutionOptions{},
}
w.Object = func(bool) (meta.RESTMapper, runtime.ObjectTyper) {
defaultMapper := ShortcutExpander{RESTMapper: kubectl.ShortcutExpander{RESTMapper: restMapper}}
defaultTyper := api.Scheme
// Output using whatever version was negotiated in the client cache. The
// version we decode with may not be the same as what the server requires.
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return defaultMapper, defaultTyper
}
cmdApiVersion := unversioned.GroupVersion{}
if cfg.GroupVersion != nil {
cmdApiVersion = *cfg.GroupVersion
}
// at this point we've negotiated and can get the client
oclient, err := clients.ClientForVersion(nil)
if err != nil {
return defaultMapper, defaultTyper
}
cacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube"), cfg.Host)
cachedDiscoverClient := NewCachedDiscoveryClient(client.NewDiscoveryClient(oclient.RESTClient), cacheDir, time.Duration(10*time.Minute))
// if we can't find the server version or its too old to have Kind information in the discovery doc, skip the discovery RESTMapper
// and use our hardcoded levels
mapper := registered.RESTMapper()
if serverVersion, err := cachedDiscoverClient.ServerVersion(); err == nil && useDiscoveryRESTMapper(serverVersion.GitVersion) {
mapper = restmapper.NewDiscoveryRESTMapper(cachedDiscoverClient)
}
mapper = NewShortcutExpander(cachedDiscoverClient, kubectl.ShortcutExpander{RESTMapper: mapper})
return kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}, api.Scheme
}
w.UnstructuredObject = func() (meta.RESTMapper, runtime.ObjectTyper, error) {
// load a discovery client from the default config
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return nil, nil, err
}
dc, err := discovery.NewDiscoveryClientForConfig(cfg)
if err != nil {
return nil, nil, err
}
cacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube"), cfg.Host)
cachedDiscoverClient := NewCachedDiscoveryClient(client.NewDiscoveryClient(dc.RESTClient), cacheDir, time.Duration(10*time.Minute))
// enumerate all group resources
groupResources, err := discovery.GetAPIGroupResources(cachedDiscoverClient)
if err != nil {
return nil, nil, err
}
// Register unknown APIs as third party for now to make
// validation happy. TODO perhaps make a dynamic schema
// validator to avoid this.
for _, group := range groupResources {
for _, version := range group.Group.Versions {
gv := unversioned.GroupVersion{Group: group.Group.Name, Version: version.Version}
if !registered.IsRegisteredVersion(gv) {
registered.AddThirdPartyAPIGroupVersions(gv)
}
}
}
// construct unstructured mapper and typer
mapper := discovery.NewRESTMapper(groupResources, meta.InterfacesForUnstructured)
typer := discovery.NewUnstructuredObjectTyper(groupResources)
return NewShortcutExpander(cachedDiscoverClient, kubectl.ShortcutExpander{RESTMapper: mapper}), typer, nil
}
kClientForMapping := w.Factory.ClientForMapping
w.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
mappingVersion := mapping.GroupVersionKind.GroupVersion()
client, err := clients.ClientForVersion(&mappingVersion)
if err != nil {
return nil, err
}
return client.RESTClient, nil
}
return kClientForMapping(mapping)
//.........这里部分代码省略.........
示例6:
DefaultDNSPort = 53
AlternateDNSPort = 8053
cmdDetermineNodeHost = "for name in %s; do ls /var/lib/origin/openshift.local.config/node-$name &> /dev/null && echo $name && break; done"
)
var (
openShiftContainerBinds = []string{
"/var/log:/var/log:rw",
"/var/run:/var/run:rw",
"/sys:/sys:ro",
"/var/lib/docker:/var/lib/docker",
}
BasePorts = []int{80, 443, 4001, 7001, 8443, 10250}
DefaultPorts = append(BasePorts, DefaultDNSPort)
PortsWithAlternateDNS = append(BasePorts, AlternateDNSPort)
SocatPidFile = filepath.Join(homedir.HomeDir(), cliconfig.OpenShiftConfigHomeDir, "socat-8443.pid")
)
// Helper contains methods and utilities to help with OpenShift startup
type Helper struct {
hostHelper *host.HostHelper
dockerHelper *dockerhelper.Helper
execHelper *dockerexec.ExecHelper
runHelper *run.RunHelper
client *docker.Client
publicHost string
image string
containerName string
routingSuffix string
}
示例7: defaultClientConfig
// ClientConfig returns a complete client config
ClientConfig() (*restConfig, error)
}
// defaultClientConfig is a modified copy of openshift/origin/pkg/cmd/util/clientcmd.DefaultClientConfig.
func defaultClientConfig() clientConfig {
loadingRules := newOpenShiftClientConfigLoadingRules()
// REMOVED: Allowing command-line overriding of loadingRules
// REMOVED: clientcmd.ConfigOverrides
clientConfig := newNonInteractiveDeferredLoadingClientConfig(loadingRules)
return clientConfig
}
var recommendedHomeFile = path.Join(homedir.HomeDir(), ".kube/config")
// newOpenShiftClientConfigLoadingRules is a modified copy of openshift/origin/pkg/cmd/cli/config.NewOpenShiftClientConfigLoadingRules.
// NewOpenShiftClientConfigLoadingRules returns file priority loading rules for OpenShift.
// 1. --config value
// 2. if KUBECONFIG env var has a value, use it. Otherwise, ~/.kube/config file
func newOpenShiftClientConfigLoadingRules() *clientConfigLoadingRules {
chain := []string{}
envVarFile := os.Getenv("KUBECONFIG")
if len(envVarFile) != 0 {
chain = append(chain, filepath.SplitList(envVarFile)...)
} else {
chain = append(chain, recommendedHomeFile)
}
示例8: MakeMiniPath
import (
"path/filepath"
"github.com/jimmidyson/minishift/pkg/version"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/util/homedir"
)
// MachineName is the name to use for the VM.
const MachineName = "minishift"
// APIServerPort is the port that the API server should listen on.
const APIServerPort = 8443
// Fix for windows
var Minipath = filepath.Join(homedir.HomeDir(), ".minishift")
// TODO: Fix for windows
// KubeconfigPath is the path to the Kubernetes client config
var KubeconfigPath = clientcmd.RecommendedHomeFile
// MinikubeContext is the kubeconfig context name used for minishift
const MinikubeContext = "minishift"
// MiniShiftEnvPrefix is the prefix for the environmental variables
const MiniShiftEnvPrefix = "MINISHIFT"
// MakeMiniPath is a utility to calculate a relative path to our directory.
func MakeMiniPath(fileName ...string) string {
args := []string{Minipath}
args = append(args, fileName...)
示例9: MakeMiniPath
import (
"path/filepath"
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
"k8s.io/kubernetes/pkg/util/homedir"
"k8s.io/kubernetes/pkg/version"
)
// MachineName is the name to use for the VM.
const MachineName = "minikube"
// APIServerPort is the port that the API server should listen on.
const APIServerPort = 8443
// Minipath is the path to the user's minikube dir
var Minipath = filepath.Join(homedir.HomeDir(), ".minikube")
// KubeconfigPath is the path to the Kubernetes client config
var KubeconfigPath = clientcmd.RecommendedHomeFile
// MinikubeContext is the kubeconfig context name used for minikube
const MinikubeContext = "minikube"
// MinikubeEnvPrefix is the prefix for the environmental variables
const MinikubeEnvPrefix = "MINIKUBE"
// MakeMiniPath is a utility to calculate a relative path to our directory.
func MakeMiniPath(fileName ...string) string {
args := []string{Minipath}
args = append(args, fileName...)
return filepath.Join(args...)
示例10: main
func main() {
cmds := &cobra.Command{
Use: "gofabric8",
Short: "gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment",
Long: `gofabric8 is used to validate & deploy fabric8 components on to your Kubernetes or OpenShift environment
Find more information at http://fabric8.io.`,
Run: runHelp,
}
cmds.PersistentFlags().String("fabric8-version", "latest", "fabric8 version")
cmds.PersistentFlags().BoolP("yes", "y", false, "assume yes")
cmds.PersistentFlags().BoolP(batchFlag, "b", false, "Run in batch mode to avoid prompts")
f := cmdutil.NewFactory(nil)
f.BindFlags(cmds.PersistentFlags())
updated := false
oldHandler := cmds.PersistentPreRun
cmds.PersistentPreRun = func(cmd *cobra.Command, args []string) {
if !updated {
updated = true
flag := cmds.Flags().Lookup(batchFlag)
batch := false
if flag != nil {
batch = flag.Value.String() == "true"
}
if !batch {
home := homedir.HomeDir()
if home == "" {
util.Fatalf("No user home environment variable found for OS %s", runtime.GOOS)
}
writeFileLocation := home + hiddenFolder
err := os.MkdirAll(writeFileLocation, 0700)
if err != nil {
util.Errorf("Unable to create directory to store update file %s %v\n", writeFileLocation, err)
}
localVersion, err := version.GetSemverVersion()
if err != nil {
util.Errorf("Unable to get local version %v", err)
}
viper.SetDefault(config.WantUpdateNotification, true)
viper.SetDefault(config.ReminderWaitPeriodInHours, 24)
update.MaybeUpdate(os.Stdout, githubOrg, githubRepo, binaryName, writeFileLocation+lastUpdateCheck, localVersion)
}
}
if oldHandler != nil {
oldHandler(cmd, args)
}
}
cmds.AddCommand(commands.NewCmdConsole(f))
cmds.AddCommand(commands.NewCmdDeploy(f))
cmds.AddCommand(commands.NewCmdDockerEnv(f))
cmds.AddCommand(commands.NewCmdIngress(f))
cmds.AddCommand(commands.NewCmdInstall(f))
cmds.AddCommand(commands.NewCmdPull(f))
cmds.AddCommand(commands.NewCmdRoutes(f))
cmds.AddCommand(commands.NewCmdRun(f))
cmds.AddCommand(commands.NewCmdSecrets(f))
cmds.AddCommand(commands.NewCmdService(f))
cmds.AddCommand(commands.NewCmdStart(f))
cmds.AddCommand(commands.NewCmdValidate(f))
cmds.AddCommand(commands.NewCmdVersion())
cmds.AddCommand(commands.NewCmdVolumes(f))
cmds.Execute()
}
示例11: NewFactory
// NewFactory creates an object that holds common methods across all OpenShift commands
func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
restMapper := registered.RESTMapper()
clients := &clientCache{
clients: make(map[string]*client.Client),
configs: make(map[string]*restclient.Config),
loader: clientConfig,
}
w := &Factory{
Factory: cmdutil.NewFactory(clientConfig),
OpenShiftClientConfig: clientConfig,
clients: clients,
}
w.Object = func(bool) (meta.RESTMapper, runtime.ObjectTyper) {
defaultMapper := ShortcutExpander{RESTMapper: kubectl.ShortcutExpander{RESTMapper: restMapper}}
defaultTyper := api.Scheme
// Output using whatever version was negotiated in the client cache. The
// version we decode with may not be the same as what the server requires.
cfg, err := clients.ClientConfigForVersion(nil)
if err != nil {
return defaultMapper, defaultTyper
}
cmdApiVersion := unversioned.GroupVersion{}
if cfg.GroupVersion != nil {
cmdApiVersion = *cfg.GroupVersion
}
// at this point we've negotiated and can get the client
oclient, err := clients.ClientForVersion(nil)
if err != nil {
return defaultMapper, defaultTyper
}
cacheDir := computeDiscoverCacheDir(filepath.Join(homedir.HomeDir(), ".kube"), cfg.Host)
cachedDiscoverClient := NewCachedDiscoveryClient(client.NewDiscoveryClient(oclient.RESTClient), cacheDir, time.Duration(10*time.Minute))
mapper := restmapper.NewDiscoveryRESTMapper(cachedDiscoverClient)
mapper = NewShortcutExpander(cachedDiscoverClient, kubectl.ShortcutExpander{RESTMapper: mapper})
return kubectl.OutputVersionMapper{RESTMapper: mapper, OutputVersions: []unversioned.GroupVersion{cmdApiVersion}}, api.Scheme
}
kClientForMapping := w.Factory.ClientForMapping
w.ClientForMapping = func(mapping *meta.RESTMapping) (resource.RESTClient, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
mappingVersion := mapping.GroupVersionKind.GroupVersion()
client, err := clients.ClientForVersion(&mappingVersion)
if err != nil {
return nil, err
}
return client.RESTClient, nil
}
return kClientForMapping(mapping)
}
// Save original Describer function
kDescriberFunc := w.Factory.Describer
w.Describer = func(mapping *meta.RESTMapping) (kubectl.Describer, error) {
if latest.OriginKind(mapping.GroupVersionKind) {
oClient, kClient, err := w.Clients()
if err != nil {
return nil, fmt.Errorf("unable to create client %s: %v", mapping.GroupVersionKind.Kind, err)
}
mappingVersion := mapping.GroupVersionKind.GroupVersion()
cfg, err := clients.ClientConfigForVersion(&mappingVersion)
if err != nil {
return nil, fmt.Errorf("unable to load a client %s: %v", mapping.GroupVersionKind.Kind, err)
}
describer, ok := describe.DescriberFor(mapping.GroupVersionKind.GroupKind(), oClient, kClient, cfg.Host)
if !ok {
return nil, fmt.Errorf("no description has been implemented for %q", mapping.GroupVersionKind.Kind)
}
return describer, nil
}
return kDescriberFunc(mapping)
}
kScalerFunc := w.Factory.Scaler
w.Scaler = func(mapping *meta.RESTMapping) (kubectl.Scaler, error) {
oc, kc, err := w.Clients()
if err != nil {
return nil, err
}
if mapping.GroupVersionKind.GroupKind() == deployapi.Kind("DeploymentConfig") {
return deployscaler.NewDeploymentConfigScaler(oc, kc), nil
}
return kScalerFunc(mapping)
}
kReaperFunc := w.Factory.Reaper
w.Reaper = func(mapping *meta.RESTMapping) (kubectl.Reaper, error) {
oc, kc, err := w.Clients()
if err != nil {
return nil, err
//.........这里部分代码省略.........