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

added support for OpenShift down #280

Merged
merged 1 commit into from
Dec 15, 2016
Merged

Conversation

procrypt
Copy link
Contributor

}
case *deployapi.DeploymentConfig:
// delete deploymentConfig
err = oclient.DeploymentConfigs(namespace).Delete(t.Name)
Copy link
Member

Choose a reason for hiding this comment

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

Using reaper function Stop would be better, than just deleting it right away.

I tried something like this

diff --git a/pkg/transformer/openshift/openshift.go b/pkg/transformer/openshift/openshift.go
index 8a81fef..992c364 100644
--- a/pkg/transformer/openshift/openshift.go
+++ b/pkg/transformer/openshift/openshift.go
@@ -35,11 +35,13 @@ import (

    oclient "github.com/openshift/origin/pkg/client"
    ocliconfig "github.com/openshift/origin/pkg/cmd/cli/config"
+   deploymentconfigreaper "github.com/openshift/origin/pkg/deploy/cmd"
+
+   "time"

    deployapi "github.com/openshift/origin/pkg/deploy/api"
    imageapi "github.com/openshift/origin/pkg/image/api"
    "k8s.io/kubernetes/pkg/kubectl"
-   "time"
 )

 type OpenShift struct {
@@ -252,7 +254,6 @@ func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.Co
    }
    oclient := oclient.NewOrDie(oclientConfig)

-
    // initialize Kubernetes client
    kfactory := kcmdutil.NewFactory(nil)
    kclientConfig, err := kfactory.ClientConfig()
@@ -272,14 +273,16 @@ func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.Co
        case *imageapi.ImageStream:
            //delete imageStream
            err = oclient.ImageStreams(namespace).Delete(t.Name)
-           if  err != nil {
+           if err != nil {
                return err
            } else {
                logrus.Infof("Successfully deleted ImageStream: %s", t.Name)
            }
        case *deployapi.DeploymentConfig:
            // delete deploymentConfig
-           err = oclient.DeploymentConfigs(namespace).Delete(t.Name)
+           dcreaper := deploymentconfigreaper.NewDeploymentConfigReaper(oclient, kclient)
+           err := dcreaper.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
+           //err = oclient.DeploymentConfigs(namespace).Delete(t.Name)
            if err != nil {
                return err
            } else {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surajssd I'll Update the PR.

@procrypt
Copy link
Contributor Author

@surajssd I have updated the PR.

@surajssd
Copy link
Member

We need tests for this PR to go in.

//Convert komposeObject
objects := o.Transform(komposeObject, opt)

// initialize OpenShift Client
Copy link
Member

Choose a reason for hiding this comment

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

Same code for initializing openshift client is used in Deploy function. It might be better to move this to separate function (for example (o *OpenShift) getOpenShiftClient (*Client, error) ) and make Deploy and Undeploy call it.

Same thing for Kubernetes client.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kadel I'll update the PR.

@procrypt
Copy link
Contributor Author

@surajssd Working on tests.

@procrypt
Copy link
Contributor Author

@kadel Updated the PR

@procrypt procrypt closed this Nov 28, 2016
@procrypt procrypt reopened this Nov 28, 2016
@procrypt
Copy link
Contributor Author

@kadel Updated the PR.
Please review :)

@procrypt
Copy link
Contributor Author

procrypt commented Dec 2, 2016

@kadel I think it will be a heavy job, to bring up the OpenShift cluster for unit testing of the code. What we can do is, open a separate issue for the testing part and not block this PR for unit tests.

Thoughts ?

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

OK, I guess this will be great candidate for future functional tests. We can figure add that in separate PR once we have idea how we will do that.

Just on last thing, it would be great to add few comments to code. (see my comments)

And it needs rebase ;-)

Otherwise LGTM

@@ -373,6 +373,23 @@ func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*a
}
}

func (o *Kubernetes) GetKubernetesClient() (*client.Client, string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add comment to this function explaining what it does, and what are the return values

fmt.Println("We are going to create OpenShift DeploymentConfigs, Services and PersistentVolumeClaims for your Dockerized application. \n" +
"If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. \n")

func (o *OpenShift) getOpenShiftClient() (*oclient.Client, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add comment to this function explaining what it does, and what are the return values?

@procrypt
Copy link
Contributor Author

procrypt commented Dec 2, 2016

@kadel added comments.

@kadel
Copy link
Member

kadel commented Dec 5, 2016

@procrypt gofmt 😉

Copy link
Member

@kadel kadel left a comment

Choose a reason for hiding this comment

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

LGTM.
But it would be great to have second pair of eyes to check it. @surajssd

if err != nil {
return err
}
kclient, namespace, _ := o.Kubernetes.GetKubernetesClient()
Copy link
Member

Choose a reason for hiding this comment

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

why are you ignoring error here?

Copy link
Member

Choose a reason for hiding this comment

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

Also o.GetKubernetesClient() should work, it will call the original function!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surajssd I didn't notice that, thanks for the trace 👍
and yeah o.GetKubernetesClient(), it works, I have updated the PR.

return err
}
kclient, namespace, _ := o.Kubernetes.GetKubernetesClient()
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

since error is ignored above the value err has is from line oclient, err := o.getOpenShiftClient()


// get namespace from config
namespace, _, err := kfactory.DefaultNamespace()
kclient, namespace, _ := o.Kubernetes.GetKubernetesClient()
Copy link
Member

Choose a reason for hiding this comment

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

see comments below on similar issue!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@surajssd PR updated

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.03%) to 34.975% when pulling 27dc5dc on procrypt:down into 04a3131 on kubernetes-incubator:master.

@kadel
Copy link
Member

kadel commented Dec 12, 2016

@surajssd Good catch. When you resolve those issues with @procrypt. Feel free to merge it.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 33.656% when pulling 6ad54a3 on procrypt:down into 65e19e3 on kubernetes-incubator:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 33.656% when pulling 6ad54a3 on procrypt:down into 65e19e3 on kubernetes-incubator:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.3%) to 33.656% when pulling 6ad54a3 on procrypt:down into 65e19e3 on kubernetes-incubator:master.

@surajssd
Copy link
Member

@procrypt thanks merging!

@surajssd surajssd merged commit 8676ae8 into kubernetes:master Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants