Skip to content

Commit

Permalink
Added support for different namespaces
Browse files Browse the repository at this point in the history
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."
  • Loading branch information
procrypt committed Mar 28, 2017
1 parent 99f7010 commit 364350a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/down.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
var (
DownReplicas int
DownEmptyVols bool
DownNamespace string
DownOpt kobject.ConvertOptions
)

Expand All @@ -43,6 +44,7 @@ var downCmd = &cobra.Command{
InputFiles: GlobalFiles,
Provider: strings.ToLower(GlobalProvider),
EmptyVols: DownEmptyVols,
Namespace: DownNamespace,
}

// Validate before doing anything else.
Expand All @@ -56,5 +58,6 @@ var downCmd = &cobra.Command{
func init() {
downCmd.Flags().BoolVar(&DownEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
downCmd.Flags().IntVar(&DownReplicas, "replicas", 1, "Specify the number of repliaces in the generate resource spec")
downCmd.Flags().StringVar(&DownNamespace, "namespace", "", " Specify Namespace to deploy your application")
RootCmd.AddCommand(downCmd)
}
3 changes: 3 additions & 0 deletions cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
var (
UpReplicas int
UpEmptyVols bool
UpNamespace string
UpOpt kobject.ConvertOptions
)

Expand All @@ -43,6 +44,7 @@ var upCmd = &cobra.Command{
InputFiles: GlobalFiles,
Provider: strings.ToLower(GlobalProvider),
EmptyVols: UpEmptyVols,
Namespace: UpNamespace,
}

// Validate before doing anything else.
Expand All @@ -56,5 +58,6 @@ var upCmd = &cobra.Command{
func init() {
upCmd.Flags().BoolVar(&UpEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
upCmd.Flags().IntVar(&UpReplicas, "replicas", 1, "Specify the number of repliaces in the generate resource spec")
upCmd.Flags().StringVar(&UpNamespace, "namespace", "", " Specify Namespace to deploy your application")
RootCmd.AddCommand(upCmd)
}
1 change: 1 addition & 0 deletions pkg/kobject/kobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ConvertOptions struct {
InputFiles []string
OutFile string
Provider string
Namespace string
IsDeploymentFlag bool
IsDaemonSetFlag bool
IsReplicationControllerFlag bool
Expand Down
15 changes: 13 additions & 2 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,15 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
fmt.Println("We are going to create Kubernetes Deployments, Services" + pvcStr + "for your Dockerized application. \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 := opt.Namespace
if len(namespace) == 0 {
namespace = ns
}
if err != nil {
return err
}
log.Infof("Deploying application in %q namespace\n", namespace)

for _, v := range objects {
switch t := v.(type) {
Expand Down Expand Up @@ -699,10 +704,16 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
return errors.Wrap(err, "k.Transform failed")
}

client, namespace, err := k.GetKubernetesClient()
client, ns, err := k.GetKubernetesClient()
namespace := opt.Namespace
if len(namespace) == 0 {
namespace = ns
}

if err != nil {
return err
}
log.Infof("Deleting application from %q namespace\n", namespace)

for _, v := range objects {
label := labels.SelectorFromSet(labels.Set(map[string]string{transformer.Selector: v.(meta.Object).GetName()}))
Expand Down

0 comments on commit 364350a

Please sign in to comment.