Skip to content

Commit

Permalink
added support for OpenShift down
Browse files Browse the repository at this point in the history
  • Loading branch information
procrypt committed Nov 21, 2016
1 parent 83c7a82 commit 393ff5c
Showing 1 changed file with 78 additions and 2 deletions.
80 changes: 78 additions & 2 deletions pkg/transformer/openshift/openshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package openshift

import (
"errors"
"fmt"
"strings"

Expand All @@ -39,6 +38,9 @@ import (

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

type OpenShift struct {
Expand All @@ -48,6 +50,10 @@ type OpenShift struct {
kubernetes.Kubernetes
}

// timeout is how long we'll wait for the termination of OpenShift resource to be successful
// used when undeploying resources from OpenShift
const TIMEOUT = 300

// getImageTag get tag name from image name
// if no tag is specified return 'latest'
func getImageTag(image string) string {
Expand Down Expand Up @@ -235,5 +241,75 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
}

func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
return errors.New("Not Implemented")
//Convert komposeObject
objects := o.Transform(komposeObject, opt)

// initialize OpenShift Client
loadingRules := ocliconfig.NewOpenShiftClientConfigLoadingRules()
overrides := &clientcmd.ConfigOverrides{}
oclientConfig, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides).ClientConfig()
if err != nil {
return err
}
oclient := oclient.NewOrDie(oclientConfig)


// initialize Kubernetes client
kfactory := kcmdutil.NewFactory(nil)
kclientConfig, err := kfactory.ClientConfig()
if err != nil {
return err
}
kclient := kclient.NewOrDie(kclientConfig)

// get namespace from config
namespace, _, err := kfactory.DefaultNamespace()
if err != nil {
return err
}

for _, v := range objects {
switch t := v.(type) {
case *imageapi.ImageStream:
//delete imageStream
err = oclient.ImageStreams(namespace).Delete(t.Name)
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)
if err != nil {
return err
} else {
logrus.Infof("Successfully deleted DeploymentConfig: %s", t.Name)
}
case *api.Service:
//delete svc
rpService, err := kubectl.ReaperFor(api.Kind("Service"), kclient)
if err != nil {
return err
}
//FIXME: gracePeriod is nil
err = rpService.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
if err != nil {
return err
} else {
logrus.Infof("Successfully deleted service: %s", t.Name)
}
case *api.PersistentVolumeClaim:
// delete pvc
err = kclient.PersistentVolumeClaims(namespace).Delete(t.Name)
if err != nil {
return err
} else {
logrus.Infof("Successfully deleted PersistentVolumeClaim: %s", t.Name)
}
}
}
return nil
}

0 comments on commit 393ff5c

Please sign in to comment.