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,53 +71,56 @@ type ConvertOptions struct {
|
||||
IsDeploymentConfigFlag bool
|
||||
IsNamespaceFlag bool
|
||||
|
||||
Server string
|
||||
|
||||
YAMLIndent int
|
||||
}
|
||||
|
||||
// ServiceConfig holds the basic struct of a container
|
||||
type ServiceConfig struct {
|
||||
ContainerName string
|
||||
Image string `compose:"image"`
|
||||
Environment []EnvVar `compose:"environment"`
|
||||
EnvFile []string `compose:"env_file"`
|
||||
Port []Ports `compose:"ports"`
|
||||
Command []string `compose:"command"`
|
||||
WorkingDir string `compose:""`
|
||||
DomainName string `compose:"domainname"`
|
||||
HostName string `compose:"hostname"`
|
||||
Args []string `compose:"args"`
|
||||
VolList []string `compose:"volumes"`
|
||||
Network []string `compose:"network"`
|
||||
Labels map[string]string `compose:"labels"`
|
||||
Annotations map[string]string `compose:""`
|
||||
CPUSet string `compose:"cpuset"`
|
||||
CPUShares int64 `compose:"cpu_shares"`
|
||||
CPUQuota int64 `compose:"cpu_quota"`
|
||||
CPULimit int64 `compose:""`
|
||||
CPUReservation int64 `compose:""`
|
||||
CapAdd []string `compose:"cap_add"`
|
||||
CapDrop []string `compose:"cap_drop"`
|
||||
Expose []string `compose:"expose"`
|
||||
ImagePullPolicy string `compose:"kompose.image-pull-policy"`
|
||||
Pid string `compose:"pid"`
|
||||
Privileged bool `compose:"privileged"`
|
||||
Restart string `compose:"restart"`
|
||||
User string `compose:"user"`
|
||||
VolumesFrom []string `compose:"volumes_from"`
|
||||
ServiceType string `compose:"kompose.service.type"`
|
||||
NodePortPort int32 `compose:"kompose.service.nodeport.port"`
|
||||
StopGracePeriod string `compose:"stop_grace_period"`
|
||||
Build string `compose:"build"`
|
||||
BuildArgs map[string]*string `compose:"build-args"`
|
||||
ExposeService string `compose:"kompose.service.expose"`
|
||||
BuildLabels map[string]string `compose:"build-labels"`
|
||||
ExposeServiceTLS string `compose:"kompose.service.expose.tls-secret"`
|
||||
ImagePullSecret string `compose:"kompose.image-pull-secret"`
|
||||
Stdin bool `compose:"stdin_open"`
|
||||
Tty bool `compose:"tty"`
|
||||
MemLimit yaml.MemStringorInt `compose:"mem_limit"`
|
||||
MemReservation yaml.MemStringorInt `compose:""`
|
||||
DeployMode string `compose:""`
|
||||
ContainerName string
|
||||
Image string `compose:"image"`
|
||||
Environment []EnvVar `compose:"environment"`
|
||||
EnvFile []string `compose:"env_file"`
|
||||
Port []Ports `compose:"ports"`
|
||||
Command []string `compose:"command"`
|
||||
WorkingDir string `compose:""`
|
||||
DomainName string `compose:"domainname"`
|
||||
HostName string `compose:"hostname"`
|
||||
Args []string `compose:"args"`
|
||||
VolList []string `compose:"volumes"`
|
||||
Network []string `compose:"network"`
|
||||
Labels map[string]string `compose:"labels"`
|
||||
Annotations map[string]string `compose:""`
|
||||
CPUSet string `compose:"cpuset"`
|
||||
CPUShares int64 `compose:"cpu_shares"`
|
||||
CPUQuota int64 `compose:"cpu_quota"`
|
||||
CPULimit int64 `compose:""`
|
||||
CPUReservation int64 `compose:""`
|
||||
CapAdd []string `compose:"cap_add"`
|
||||
CapDrop []string `compose:"cap_drop"`
|
||||
Expose []string `compose:"expose"`
|
||||
ImagePullPolicy string `compose:"kompose.image-pull-policy"`
|
||||
Pid string `compose:"pid"`
|
||||
Privileged bool `compose:"privileged"`
|
||||
Restart string `compose:"restart"`
|
||||
User string `compose:"user"`
|
||||
VolumesFrom []string `compose:"volumes_from"`
|
||||
ServiceType string `compose:"kompose.service.type"`
|
||||
NodePortPort int32 `compose:"kompose.service.nodeport.port"`
|
||||
StopGracePeriod string `compose:"stop_grace_period"`
|
||||
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"`
|
||||
Stdin bool `compose:"stdin_open"`
|
||||
Tty bool `compose:"tty"`
|
||||
MemLimit yaml.MemStringorInt `compose:"mem_limit"`
|
||||
MemReservation yaml.MemStringorInt `compose:""`
|
||||
DeployMode string `compose:""`
|
||||
// DeployLabels mapping to kubernetes labels
|
||||
DeployLabels map[string]string `compose:""`
|
||||
DeployUpdateConfig dockerCliTypes.UpdateConfig `compose:""`
|
||||
|
||||
@ -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