forked from LaconicNetwork/kompose
Added support for different namespaces
Now we can deploy application in different namespaces using the "--namespace=<value>" flag with kompose up and kompose down. The --namepace flag will deploy the application in that particular "namespace" if exist."
This commit is contained in:
parent
cba4c569a3
commit
f41985a00e
10
cmd/down.go
10
cmd/down.go
@ -26,7 +26,8 @@ import (
|
||||
|
||||
// TODO: comment
|
||||
var (
|
||||
DownOpt kobject.ConvertOptions
|
||||
DownNamespace string
|
||||
DownOpt kobject.ConvertOptions
|
||||
)
|
||||
|
||||
var downCmd = &cobra.Command{
|
||||
@ -37,8 +38,10 @@ var downCmd = &cobra.Command{
|
||||
|
||||
// Create the Convert options.
|
||||
DownOpt = kobject.ConvertOptions{
|
||||
InputFiles: GlobalFiles,
|
||||
Provider: strings.ToLower(GlobalProvider),
|
||||
InputFiles: GlobalFiles,
|
||||
Provider: strings.ToLower(GlobalProvider),
|
||||
Namespace: DownNamespace,
|
||||
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
||||
}
|
||||
|
||||
// Validate before doing anything else.
|
||||
@ -50,5 +53,6 @@ var downCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
downCmd.Flags().StringVar(&DownNamespace, "namespace", "default", " Specify Namespace to deploy your application")
|
||||
RootCmd.AddCommand(downCmd)
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ var (
|
||||
UpReplicas int
|
||||
UpEmptyVols bool
|
||||
UpInsecureRepo bool
|
||||
UpNamespace string
|
||||
UpOpt kobject.ConvertOptions
|
||||
)
|
||||
|
||||
@ -44,7 +45,9 @@ var upCmd = &cobra.Command{
|
||||
InputFiles: GlobalFiles,
|
||||
Provider: strings.ToLower(GlobalProvider),
|
||||
EmptyVols: UpEmptyVols,
|
||||
Namespace: UpNamespace,
|
||||
InsecureRepository: UpInsecureRepo,
|
||||
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
||||
}
|
||||
|
||||
// Validate before doing anything else.
|
||||
@ -59,5 +62,6 @@ func init() {
|
||||
upCmd.Flags().BoolVar(&UpEmptyVols, "emptyvols", false, "Use empty volumes. Do not generate PersistentVolumeClaim")
|
||||
upCmd.Flags().IntVar(&UpReplicas, "replicas", 1, "Specify the number of replicas generated")
|
||||
upCmd.Flags().BoolVar(&UpInsecureRepo, "insecure-repository", false, "Use an insecure Docker repository for OpenShift ImageStream")
|
||||
upCmd.Flags().StringVar(&UpNamespace, "namespace", "default", "Specify Namespace to deploy your application")
|
||||
RootCmd.AddCommand(upCmd)
|
||||
}
|
||||
|
||||
@ -48,10 +48,12 @@ type ConvertOptions struct {
|
||||
InputFiles []string
|
||||
OutFile string
|
||||
Provider string
|
||||
Namespace string
|
||||
IsDeploymentFlag bool
|
||||
IsDaemonSetFlag bool
|
||||
IsReplicationControllerFlag bool
|
||||
IsDeploymentConfigFlag bool
|
||||
IsNamespaceFlag bool
|
||||
}
|
||||
|
||||
// ServiceConfig holds the basic struct of a container
|
||||
|
||||
@ -640,11 +640,17 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
|
||||
log.Info("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. " +
|
||||
"If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead. \n")
|
||||
|
||||
client, namespace, err := k.GetKubernetesClient()
|
||||
client, ns, err := k.GetKubernetesClient()
|
||||
namespace := ns
|
||||
if opt.IsNamespaceFlag {
|
||||
namespace = opt.Namespace
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Infof("Deploying application in %q namespace", namespace)
|
||||
|
||||
for _, v := range objects {
|
||||
switch t := v.(type) {
|
||||
case *extensions.Deployment:
|
||||
@ -700,12 +706,19 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
return errorList
|
||||
}
|
||||
|
||||
client, namespace, err := k.GetKubernetesClient()
|
||||
client, ns, err := k.GetKubernetesClient()
|
||||
namespace := ns
|
||||
if opt.IsNamespaceFlag {
|
||||
namespace = opt.Namespace
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
errorList = append(errorList, err)
|
||||
return errorList
|
||||
}
|
||||
|
||||
log.Infof("Deleting application in %q namespace", namespace)
|
||||
|
||||
for _, v := range objects {
|
||||
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
|
||||
options := api.ListOptions{LabelSelector: label}
|
||||
|
||||
@ -446,17 +446,23 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
|
||||
if !opt.EmptyVols {
|
||||
pvcStr = " and PersistentVolumeClaims "
|
||||
}
|
||||
fmt.Println("We are going to create OpenShift DeploymentConfigs, Services" + pvcStr + "for your Dockerized application. \n" +
|
||||
log.Info("We are going to create OpenShift DeploymentConfigs, Services" + pvcStr + "for your Dockerized application. \n" +
|
||||
"If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. \n")
|
||||
|
||||
oclient, err := o.getOpenShiftClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
kclient, namespace, err := o.GetKubernetesClient()
|
||||
kclient, ns, err := o.GetKubernetesClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
namespace := ns
|
||||
if opt.IsNamespaceFlag {
|
||||
namespace = opt.Namespace
|
||||
}
|
||||
|
||||
log.Infof("Deploying application in %q namespace", namespace)
|
||||
|
||||
for _, v := range objects {
|
||||
switch t := v.(type) {
|
||||
@ -530,11 +536,17 @@ func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.Co
|
||||
errorList = append(errorList, err)
|
||||
return errorList
|
||||
}
|
||||
kclient, namespace, err := o.GetKubernetesClient()
|
||||
kclient, ns, err := o.GetKubernetesClient()
|
||||
if err != nil {
|
||||
errorList = append(errorList, err)
|
||||
return errorList
|
||||
}
|
||||
namespace := ns
|
||||
if opt.IsNamespaceFlag {
|
||||
namespace = opt.Namespace
|
||||
}
|
||||
|
||||
log.Infof("Deleting application in %q namespace", namespace)
|
||||
|
||||
for _, v := range objects {
|
||||
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user