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
|
// TODO: comment
|
||||||
var (
|
var (
|
||||||
DownOpt kobject.ConvertOptions
|
DownNamespace string
|
||||||
|
DownOpt kobject.ConvertOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
var downCmd = &cobra.Command{
|
var downCmd = &cobra.Command{
|
||||||
@ -37,8 +38,10 @@ var downCmd = &cobra.Command{
|
|||||||
|
|
||||||
// Create the Convert options.
|
// Create the Convert options.
|
||||||
DownOpt = kobject.ConvertOptions{
|
DownOpt = kobject.ConvertOptions{
|
||||||
InputFiles: GlobalFiles,
|
InputFiles: GlobalFiles,
|
||||||
Provider: strings.ToLower(GlobalProvider),
|
Provider: strings.ToLower(GlobalProvider),
|
||||||
|
Namespace: DownNamespace,
|
||||||
|
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate before doing anything else.
|
// Validate before doing anything else.
|
||||||
@ -50,5 +53,6 @@ var downCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
downCmd.Flags().StringVar(&DownNamespace, "namespace", "default", " Specify Namespace to deploy your application")
|
||||||
RootCmd.AddCommand(downCmd)
|
RootCmd.AddCommand(downCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ var (
|
|||||||
UpReplicas int
|
UpReplicas int
|
||||||
UpEmptyVols bool
|
UpEmptyVols bool
|
||||||
UpInsecureRepo bool
|
UpInsecureRepo bool
|
||||||
|
UpNamespace string
|
||||||
UpOpt kobject.ConvertOptions
|
UpOpt kobject.ConvertOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -44,7 +45,9 @@ var upCmd = &cobra.Command{
|
|||||||
InputFiles: GlobalFiles,
|
InputFiles: GlobalFiles,
|
||||||
Provider: strings.ToLower(GlobalProvider),
|
Provider: strings.ToLower(GlobalProvider),
|
||||||
EmptyVols: UpEmptyVols,
|
EmptyVols: UpEmptyVols,
|
||||||
|
Namespace: UpNamespace,
|
||||||
InsecureRepository: UpInsecureRepo,
|
InsecureRepository: UpInsecureRepo,
|
||||||
|
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate before doing anything else.
|
// 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().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().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().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)
|
RootCmd.AddCommand(upCmd)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,10 +48,12 @@ type ConvertOptions struct {
|
|||||||
InputFiles []string
|
InputFiles []string
|
||||||
OutFile string
|
OutFile string
|
||||||
Provider string
|
Provider string
|
||||||
|
Namespace string
|
||||||
IsDeploymentFlag bool
|
IsDeploymentFlag bool
|
||||||
IsDaemonSetFlag bool
|
IsDaemonSetFlag bool
|
||||||
IsReplicationControllerFlag bool
|
IsReplicationControllerFlag bool
|
||||||
IsDeploymentConfigFlag bool
|
IsDeploymentConfigFlag bool
|
||||||
|
IsNamespaceFlag bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceConfig holds the basic struct of a container
|
// 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. " +
|
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")
|
"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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Deploying application in %q namespace", namespace)
|
||||||
|
|
||||||
for _, v := range objects {
|
for _, v := range objects {
|
||||||
switch t := v.(type) {
|
switch t := v.(type) {
|
||||||
case *extensions.Deployment:
|
case *extensions.Deployment:
|
||||||
@ -700,12 +706,19 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
return errorList
|
return errorList
|
||||||
}
|
}
|
||||||
|
|
||||||
client, namespace, err := k.GetKubernetesClient()
|
client, ns, err := k.GetKubernetesClient()
|
||||||
|
namespace := ns
|
||||||
|
if opt.IsNamespaceFlag {
|
||||||
|
namespace = opt.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorList = append(errorList, err)
|
errorList = append(errorList, err)
|
||||||
return errorList
|
return errorList
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Infof("Deleting application in %q namespace", namespace)
|
||||||
|
|
||||||
for _, v := range objects {
|
for _, v := range objects {
|
||||||
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
|
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
|
||||||
options := api.ListOptions{LabelSelector: label}
|
options := api.ListOptions{LabelSelector: label}
|
||||||
|
|||||||
@ -446,17 +446,23 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
|
|||||||
if !opt.EmptyVols {
|
if !opt.EmptyVols {
|
||||||
pvcStr = " and PersistentVolumeClaims "
|
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")
|
"If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. \n")
|
||||||
|
|
||||||
oclient, err := o.getOpenShiftClient()
|
oclient, err := o.getOpenShiftClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
kclient, namespace, err := o.GetKubernetesClient()
|
kclient, ns, err := o.GetKubernetesClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
namespace := ns
|
||||||
|
if opt.IsNamespaceFlag {
|
||||||
|
namespace = opt.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Deploying application in %q namespace", namespace)
|
||||||
|
|
||||||
for _, v := range objects {
|
for _, v := range objects {
|
||||||
switch t := v.(type) {
|
switch t := v.(type) {
|
||||||
@ -530,11 +536,17 @@ func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.Co
|
|||||||
errorList = append(errorList, err)
|
errorList = append(errorList, err)
|
||||||
return errorList
|
return errorList
|
||||||
}
|
}
|
||||||
kclient, namespace, err := o.GetKubernetesClient()
|
kclient, ns, err := o.GetKubernetesClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorList = append(errorList, err)
|
errorList = append(errorList, err)
|
||||||
return errorList
|
return errorList
|
||||||
}
|
}
|
||||||
|
namespace := ns
|
||||||
|
if opt.IsNamespaceFlag {
|
||||||
|
namespace = opt.Namespace
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Deleting application in %q namespace", namespace)
|
||||||
|
|
||||||
for _, v := range objects {
|
for _, v := range objects {
|
||||||
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
|
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user