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
|
UpController string
|
||||||
// UpPushImage decides if we should push the docker image
|
// UpPushImage decides if we should push the docker image
|
||||||
UpPushImage bool
|
UpPushImage bool
|
||||||
|
|
||||||
|
// UpServer allow use to choose different kubernetes server url
|
||||||
|
UpServer string
|
||||||
)
|
)
|
||||||
|
|
||||||
var upCmd = &cobra.Command{
|
var upCmd = &cobra.Command{
|
||||||
@ -69,6 +72,7 @@ var upCmd = &cobra.Command{
|
|||||||
BuildRepo: UpBuildRepo,
|
BuildRepo: UpBuildRepo,
|
||||||
Controller: strings.ToLower(UpController),
|
Controller: strings.ToLower(UpController),
|
||||||
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
||||||
|
Server: UpServer,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate before doing anything else.
|
// 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(&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().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(&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("insecure-repository")
|
||||||
upCmd.Flags().MarkHidden("build-repo")
|
upCmd.Flags().MarkHidden("build-repo")
|
||||||
upCmd.Flags().MarkHidden("build-branch")
|
upCmd.Flags().MarkHidden("build-branch")
|
||||||
|
|||||||
@ -131,6 +131,7 @@ po/redis-slave-2504961300-nve7b 1/1 Running 0 4m
|
|||||||
```
|
```
|
||||||
Note:
|
Note:
|
||||||
- You must have a running Kubernetes cluster with a pre-configured kubectl context.
|
- 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.
|
- 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
|
### OpenShift
|
||||||
|
|||||||
@ -71,53 +71,56 @@ type ConvertOptions struct {
|
|||||||
IsDeploymentConfigFlag bool
|
IsDeploymentConfigFlag bool
|
||||||
IsNamespaceFlag bool
|
IsNamespaceFlag bool
|
||||||
|
|
||||||
|
Server string
|
||||||
|
|
||||||
YAMLIndent int
|
YAMLIndent int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceConfig holds the basic struct of a container
|
// ServiceConfig holds the basic struct of a container
|
||||||
type ServiceConfig struct {
|
type ServiceConfig struct {
|
||||||
ContainerName string
|
ContainerName string
|
||||||
Image string `compose:"image"`
|
Image string `compose:"image"`
|
||||||
Environment []EnvVar `compose:"environment"`
|
Environment []EnvVar `compose:"environment"`
|
||||||
EnvFile []string `compose:"env_file"`
|
EnvFile []string `compose:"env_file"`
|
||||||
Port []Ports `compose:"ports"`
|
Port []Ports `compose:"ports"`
|
||||||
Command []string `compose:"command"`
|
Command []string `compose:"command"`
|
||||||
WorkingDir string `compose:""`
|
WorkingDir string `compose:""`
|
||||||
DomainName string `compose:"domainname"`
|
DomainName string `compose:"domainname"`
|
||||||
HostName string `compose:"hostname"`
|
HostName string `compose:"hostname"`
|
||||||
Args []string `compose:"args"`
|
Args []string `compose:"args"`
|
||||||
VolList []string `compose:"volumes"`
|
VolList []string `compose:"volumes"`
|
||||||
Network []string `compose:"network"`
|
Network []string `compose:"network"`
|
||||||
Labels map[string]string `compose:"labels"`
|
Labels map[string]string `compose:"labels"`
|
||||||
Annotations map[string]string `compose:""`
|
Annotations map[string]string `compose:""`
|
||||||
CPUSet string `compose:"cpuset"`
|
CPUSet string `compose:"cpuset"`
|
||||||
CPUShares int64 `compose:"cpu_shares"`
|
CPUShares int64 `compose:"cpu_shares"`
|
||||||
CPUQuota int64 `compose:"cpu_quota"`
|
CPUQuota int64 `compose:"cpu_quota"`
|
||||||
CPULimit int64 `compose:""`
|
CPULimit int64 `compose:""`
|
||||||
CPUReservation int64 `compose:""`
|
CPUReservation int64 `compose:""`
|
||||||
CapAdd []string `compose:"cap_add"`
|
CapAdd []string `compose:"cap_add"`
|
||||||
CapDrop []string `compose:"cap_drop"`
|
CapDrop []string `compose:"cap_drop"`
|
||||||
Expose []string `compose:"expose"`
|
Expose []string `compose:"expose"`
|
||||||
ImagePullPolicy string `compose:"kompose.image-pull-policy"`
|
ImagePullPolicy string `compose:"kompose.image-pull-policy"`
|
||||||
Pid string `compose:"pid"`
|
Pid string `compose:"pid"`
|
||||||
Privileged bool `compose:"privileged"`
|
Privileged bool `compose:"privileged"`
|
||||||
Restart string `compose:"restart"`
|
Restart string `compose:"restart"`
|
||||||
User string `compose:"user"`
|
User string `compose:"user"`
|
||||||
VolumesFrom []string `compose:"volumes_from"`
|
VolumesFrom []string `compose:"volumes_from"`
|
||||||
ServiceType string `compose:"kompose.service.type"`
|
ServiceType string `compose:"kompose.service.type"`
|
||||||
NodePortPort int32 `compose:"kompose.service.nodeport.port"`
|
NodePortPort int32 `compose:"kompose.service.nodeport.port"`
|
||||||
StopGracePeriod string `compose:"stop_grace_period"`
|
StopGracePeriod string `compose:"stop_grace_period"`
|
||||||
Build string `compose:"build"`
|
Build string `compose:"build"`
|
||||||
BuildArgs map[string]*string `compose:"build-args"`
|
BuildArgs map[string]*string `compose:"build-args"`
|
||||||
ExposeService string `compose:"kompose.service.expose"`
|
ExposeService string `compose:"kompose.service.expose"`
|
||||||
BuildLabels map[string]string `compose:"build-labels"`
|
ExposeServicePath string `compose:"kompose.service.expose.path"`
|
||||||
ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"`
|
BuildLabels map[string]string `compose:"build-labels"`
|
||||||
ImagePullSecret string `compose:"kompose.image-pull-secret"`
|
ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"`
|
||||||
Stdin bool `compose:"stdin_open"`
|
ImagePullSecret string `compose:"kompose.image-pull-secret"`
|
||||||
Tty bool `compose:"tty"`
|
Stdin bool `compose:"stdin_open"`
|
||||||
MemLimit yaml.MemStringorInt `compose:"mem_limit"`
|
Tty bool `compose:"tty"`
|
||||||
MemReservation yaml.MemStringorInt `compose:""`
|
MemLimit yaml.MemStringorInt `compose:"mem_limit"`
|
||||||
DeployMode string `compose:""`
|
MemReservation yaml.MemStringorInt `compose:""`
|
||||||
|
DeployMode string `compose:""`
|
||||||
// DeployLabels mapping to kubernetes labels
|
// DeployLabels mapping to kubernetes labels
|
||||||
DeployLabels map[string]string `compose:""`
|
DeployLabels map[string]string `compose:""`
|
||||||
DeployUpdateConfig dockerCliTypes.UpdateConfig `compose:""`
|
DeployUpdateConfig dockerCliTypes.UpdateConfig `compose:""`
|
||||||
|
|||||||
@ -1296,7 +1296,7 @@ func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*a
|
|||||||
|
|
||||||
// DefaultClientConfig get default client config.
|
// DefaultClientConfig get default client config.
|
||||||
// This function is copied from library , we just overrides the apiserver url
|
// 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()
|
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
|
||||||
// use the standard defaults for this client command
|
// use the standard defaults for this client command
|
||||||
// DEPRECATED: remove and replace with something more accurate
|
// DEPRECATED: remove and replace with something more accurate
|
||||||
@ -1306,6 +1306,9 @@ func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
|
|||||||
|
|
||||||
clusterDefaults := clientcmd.ClusterDefaults
|
clusterDefaults := clientcmd.ClusterDefaults
|
||||||
clusterDefaults.Server = "https://127.0.0.1:6443"
|
clusterDefaults.Server = "https://127.0.0.1:6443"
|
||||||
|
if k.Opt.Server != "" {
|
||||||
|
clusterDefaults.Server = k.Opt.Server
|
||||||
|
}
|
||||||
|
|
||||||
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clusterDefaults}
|
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clusterDefaults}
|
||||||
|
|
||||||
@ -1325,7 +1328,7 @@ func (k *Kubernetes) GetKubernetesClient() (*client.Client, string, error) {
|
|||||||
// generate a new client config
|
// generate a new client config
|
||||||
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
|
flags := pflag.NewFlagSet("", pflag.ContinueOnError)
|
||||||
flags.SetNormalizeFunc(utilflag.WarnWordSepNormalizeFunc) // Warn for "_" flags
|
flags.SetNormalizeFunc(utilflag.WarnWordSepNormalizeFunc) // Warn for "_" flags
|
||||||
oc := DefaultClientConfig(flags)
|
oc := k.DefaultClientConfig(flags)
|
||||||
|
|
||||||
// initialize Kubernetes client
|
// initialize Kubernetes client
|
||||||
factory := cmdutil.NewFactory(oc)
|
factory := cmdutil.NewFactory(oc)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user