Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding --controller flag in up & down #868

Merged
merged 1 commit into from
Nov 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/down.go
Original file line number Diff line number Diff line change
@@ -17,15 +17,18 @@ limitations under the License.
package cmd

import (
"strings"

"github.com/kubernetes/kompose/pkg/app"
"github.com/kubernetes/kompose/pkg/kobject"
"github.com/spf13/cobra"
)

// TODO: comment
var (
DownNamespace string
DownOpt kobject.ConvertOptions
DownNamespace string
DownController string
DownOpt kobject.ConvertOptions
)

var downCmd = &cobra.Command{
@@ -39,6 +42,7 @@ var downCmd = &cobra.Command{
InputFiles: GlobalFiles,
Provider: GlobalProvider,
Namespace: DownNamespace,
Controller: strings.ToLower(DownController),
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
}

@@ -52,5 +56,6 @@ var downCmd = &cobra.Command{

func init() {
downCmd.Flags().StringVar(&DownNamespace, "namespace", "default", " Specify Namespace to deploy your application")
downCmd.Flags().StringVar(&DownController, "controller", "", `Set the output controller ("deployment"|"daemonSet"|"replicationController")`)
RootCmd.AddCommand(downCmd)
}
4 changes: 4 additions & 0 deletions cmd/up.go
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import (
"github.com/kubernetes/kompose/pkg/app"
"github.com/kubernetes/kompose/pkg/kobject"
"github.com/spf13/cobra"
"strings"
)

// TODO: comment
@@ -35,6 +36,7 @@ var (
UpBuild string
UpBuildBranch string
UpBuildRepo string
UpController string
)

var upCmd = &cobra.Command{
@@ -60,6 +62,7 @@ var upCmd = &cobra.Command{
InsecureRepository: UpInsecureRepo,
BuildBranch: UpBuildBranch,
BuildRepo: UpBuildRepo,
Controller: strings.ToLower(UpController),
IsNamespaceFlag: cmd.Flags().Lookup("namespace").Changed,
}

@@ -79,6 +82,7 @@ func init() {
upCmd.Flags().StringVar(&UpBuild, "build", "local", `Set the type of build ("local"|"build-config" (OpenShift only)|"none")`)
upCmd.Flags().StringVar(&UpBuildRepo, "build-repo", "", "Specify source repository for buildconfig (default remote origin)")
upCmd.Flags().StringVar(&UpBuildBranch, "build-branch", "", "Specify repository branch to use for buildconfig (default master)")
upCmd.Flags().StringVar(&UpController, "controller", "", `Set the output controller ("deployment"|"daemonSet"|"replicationController")`)
upCmd.Flags().MarkHidden("insecure-repository")
upCmd.Flags().MarkHidden("build-repo")
upCmd.Flags().MarkHidden("build-branch")
65 changes: 65 additions & 0 deletions pkg/transformer/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
@@ -805,6 +805,21 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
return err
}
log.Infof("Successfully created Deployment: %s", t.Name)

case *extensions.DaemonSet:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not too sure why this code is being added? Can you describe this at least within the commit description?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure I will mention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdrage , updated commit message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update GitHub description too...

_, err := client.DaemonSets(namespace).Create(t)
if err != nil {
return err
}
log.Infof("Successfully created DaemonSet: %s", t.Name)

case *api.ReplicationController:
_, err := client.ReplicationControllers(namespace).Create(t)
if err != nil {
return err
}
log.Infof("Successfully created ReplicationController: %s", t.Name)

case *api.Service:
_, err := client.Services(namespace).Create(t)
if err != nil {
@@ -901,6 +916,56 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
}
}

case *extensions.DaemonSet:
//delete deployment
daemonset, err := client.DaemonSets(namespace).List(options)
if err != nil {
errorList = append(errorList, err)
break
}
for _, l := range daemonset.Items {
if reflect.DeepEqual(l.Labels, komposeLabel) {
rpDaemonset, err := kubectl.ReaperFor(extensions.Kind("DaemonSet"), client)
if err != nil {
errorList = append(errorList, err)
break
}
//FIXME: gracePeriod is nil
err = rpDaemonset.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
if err != nil {
errorList = append(errorList, err)
break
}
log.Infof("Successfully deleted DaemonSet: %s", t.Name)

}
}

case *api.ReplicationController:
//delete deployment
replicationController, err := client.ReplicationControllers(namespace).List(options)
if err != nil {
errorList = append(errorList, err)
break
}
for _, l := range replicationController.Items {
if reflect.DeepEqual(l.Labels, komposeLabel) {
rpReplicationController, err := kubectl.ReaperFor(api.Kind("ReplicationController"), client)
if err != nil {
errorList = append(errorList, err)
break
}
//FIXME: gracePeriod is nil
err = rpReplicationController.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
if err != nil {
errorList = append(errorList, err)
break
}
log.Infof("Successfully deleted ReplicationController: %s", t.Name)

}
}

case *api.Service:
//delete svc
svc, err := client.Services(namespace).List(options)
13 changes: 13 additions & 0 deletions script/test_k8s/kubernetes.sh
Original file line number Diff line number Diff line change
@@ -103,6 +103,19 @@ test_k8s() {
sleep 2 # Sleep for k8s to catch up to deployment
echo -e "\n${RED}kompose down -f $f ${NC}\n"
./kompose down -f $f
echo -e "\nTesting controller=daemonset key\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should find an alternative way to write these integration tests (perhaps in a separate function? and only running the httpd.yaml test?) or even a separate file...

It's a bit messy at the moment and we really need to refactor everything (using e2e_test.go similar to our other project we're working on.

Do you mind opening an issue explaining that we should refactor our integration tests to use a Go file / make this better? As well as add a comment (and spacing above this line) with a # TODO: need to reorganize / refactor
Otherwise, this LGTM (for now).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding issue as well.
Ready to merge ?

echo -e "\n${RED}kompose up -f $f --controller=daemonset ${NC}\n"
./kompose up -f $f --controller=daemonset
sleep 2 # Sleep for k8s to catch up to deployment
echo -e "\n${RED}kompose down -f $f --controller=daemonset ${NC}\n"
./kompose down -f $f --controller=daemonset
echo -e "\nTesting controller=replicationcontroller key\n"
echo -e "\n${RED}kompose up -f $f --controller=replicationcontroller ${NC}\n"
./kompose up -f $f --controller=replicationcontroller
sleep 2 # Sleep for k8s to catch up to deployment
echo -e "\n${RED}kompose down -f $f --controller=replicationcontroller ${NC}\n"
./kompose down -f $f --controller=replicationcontroller

done
}