-
Notifications
You must be signed in to change notification settings - Fork 771
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
Conversation
} | ||
case *deployapi.DeploymentConfig: | ||
// delete deploymentConfig | ||
err = oclient.DeploymentConfigs(namespace).Delete(t.Name) |
There was a problem hiding this comment.
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 {
There was a problem hiding this comment.
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.
@surajssd I have updated the PR. |
We need tests for this PR to go in. |
//Convert komposeObject | ||
objects := o.Transform(komposeObject, opt) | ||
|
||
// initialize OpenShift Client |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@surajssd Working on tests. |
@kadel Updated the PR |
@kadel Updated the PR. |
@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 ? |
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
@kadel added comments. |
b444cfe
to
73da23b
Compare
@procrypt gofmt 😉 |
There was a problem hiding this 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() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@surajssd PR updated
b4e7366
to
6ad54a3
Compare
@procrypt thanks merging! |
Fix #208
cc @kadel @surajssd @sebgoa @ngtuna