forked from LaconicNetwork/kompose
Add flag to allow use define api server url (#1243)
This commit is contained in:
parent
dd3f6a28e9
commit
78908c94e5
@ -40,6 +40,9 @@ var (
|
||||
UpController string
|
||||
// UpPushImage decides if we should push the docker image
|
||||
UpPushImage bool
|
||||
|
||||
// UpServer allow use to choose different kubernetes server url
|
||||
UpServer string
|
||||
)
|
||||
|
||||
var upCmd = &cobra.Command{
|
||||
@ -69,6 +72,7 @@ var upCmd = &cobra.Command{
|
||||
BuildRepo: UpBuildRepo,
|
||||
Controller: strings.ToLower(UpController),
|
||||
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
||||
Server: UpServer,
|
||||
}
|
||||
|
||||
// Validate before doing anything else.
|
||||
@ -90,6 +94,7 @@ func init() {
|
||||
upCmd.Flags().BoolVar(&UpPushImage, "push-image", true, "If we should push the docker image we built")
|
||||
upCmd.Flags().BoolVar(&StoreManifest, "store-manifest", false, "Store the generated manifest (default false)")
|
||||
upCmd.Flags().StringVar(&UpController, "controller", "", `Set the output controller ("deployment"|"daemonSet"|"replicationController")`)
|
||||
upCmd.Flags().StringVar(&UpServer, "server", "", "kubernetes apiserver url (default https://127.0.0.1:6443)")
|
||||
upCmd.Flags().MarkHidden("insecure-repository")
|
||||
upCmd.Flags().MarkHidden("build-repo")
|
||||
upCmd.Flags().MarkHidden("build-branch")
|
||||
|
||||
@ -131,6 +131,7 @@ po/redis-slave-2504961300-nve7b 1/1 Running 0 4m
|
||||
```
|
||||
Note:
|
||||
- You must have a running Kubernetes cluster with a pre-configured kubectl context.
|
||||
- If you kubernetes api server url is different than `https://127.0.0.1:6443`, you can use the `--server` flag to customize it.
|
||||
- Only deployments and services are generated and deployed to Kubernetes. If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
|
||||
|
||||
### OpenShift
|
||||
|
||||
@ -71,6 +71,8 @@ type ConvertOptions struct {
|
||||
IsDeploymentConfigFlag bool
|
||||
IsNamespaceFlag bool
|
||||
|
||||
Server string
|
||||
|
||||
YAMLIndent int
|
||||
}
|
||||
|
||||
@ -110,6 +112,7 @@ type ServiceConfig struct {
|
||||
Build string `compose:"build"`
|
||||
BuildArgs map[string]*string `compose:"build-args"`
|
||||
ExposeService string `compose:"kompose.service.expose"`
|
||||
ExposeServicePath string `compose:"kompose.service.expose.path"`
|
||||
BuildLabels map[string]string `compose:"build-labels"`
|
||||
ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"`
|
||||
ImagePullSecret string `compose:"kompose.image-pull-secret"`
|
||||
|
||||
@ -1296,7 +1296,7 @@ func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*a
|
||||
|
||||
// DefaultClientConfig get default client config.
|
||||
// This function is copied from library , we just overrides the apiserver url
|
||||
func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
|
||||
func (k *Kubernetes) DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
|
||||
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||
// use the standard defaults for this client command
|
||||
// DEPRECATED: remove and replace with something more accurate
|
||||
@ -1306,6 +1306,9 @@ func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
|
||||
|
||||
clusterDefaults := clientcmd.ClusterDefaults
|
||||
clusterDefaults.Server = "https://127.0.0.1:6443"
|
||||
if k.Opt.Server != "" {
|
||||
clusterDefaults.Server = k.Opt.Server
|
||||
}
|
||||
|
||||
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clusterDefaults}
|
||||
|
||||
@ -1325,7 +1328,7 @@ func (k *Kubernetes) GetKubernetesClient() (*client.Client, string, error) {
|
||||
// generate a new client config
|
||||
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
|
||||
flags.SetNormalizeFunc(utilflag.WarnWordSepNormalizeFunc) // Warn for "_" flags
|
||||
oc := DefaultClientConfig(flags)
|
||||
oc := k.DefaultClientConfig(flags)
|
||||
|
||||
// initialize Kubernetes client
|
||||
factory := cmdutil.NewFactory(oc)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user