forked from LaconicNetwork/kompose
fix golint errors
This commit is contained in:
parent
502157a078
commit
4f176b847e
@ -25,16 +25,28 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: comment
|
||||||
var (
|
var (
|
||||||
ConvertSource, ConvertOut, ConvertBuildRepo, ConvertBuildBranch string
|
ConvertSource string
|
||||||
ConvertChart, ConvertDeployment, ConvertDaemonSet bool
|
ConvertOut string
|
||||||
ConvertReplicationController, ConvertYaml, ConvertStdout, ConvertJson bool
|
ConvertBuildRepo string
|
||||||
ConvertEmptyVols, ConvertDeploymentConfig, ConvertBuildConfig bool
|
ConvertBuildBranch string
|
||||||
ConvertReplicas int
|
ConvertChart bool
|
||||||
ConvertOpt kobject.ConvertOptions
|
ConvertDeployment bool
|
||||||
|
ConvertDaemonSet bool
|
||||||
|
ConvertReplicationController bool
|
||||||
|
ConvertYaml bool
|
||||||
|
ConvertJSON bool
|
||||||
|
ConvertStdout bool
|
||||||
|
ConvertEmptyVols bool
|
||||||
|
ConvertDeploymentConfig bool
|
||||||
|
ConvertBuildConfig bool
|
||||||
|
ConvertReplicas int
|
||||||
|
ConvertOpt kobject.ConvertOptions
|
||||||
)
|
)
|
||||||
|
|
||||||
var ConvertProvider string = GlobalProvider
|
// ConvertProvider TODO: comment
|
||||||
|
var ConvertProvider = GlobalProvider
|
||||||
|
|
||||||
var convertCmd = &cobra.Command{
|
var convertCmd = &cobra.Command{
|
||||||
Use: "convert [file]",
|
Use: "convert [file]",
|
||||||
@ -46,7 +58,7 @@ var convertCmd = &cobra.Command{
|
|||||||
ToStdout: ConvertStdout,
|
ToStdout: ConvertStdout,
|
||||||
CreateChart: ConvertChart,
|
CreateChart: ConvertChart,
|
||||||
GenerateYaml: ConvertYaml,
|
GenerateYaml: ConvertYaml,
|
||||||
GenerateJson: ConvertJson,
|
GenerateJSON: ConvertJSON,
|
||||||
Replicas: ConvertReplicas,
|
Replicas: ConvertReplicas,
|
||||||
InputFiles: GlobalFiles,
|
InputFiles: GlobalFiles,
|
||||||
OutFile: ConvertOut,
|
OutFile: ConvertOut,
|
||||||
@ -96,7 +108,7 @@ func init() {
|
|||||||
convertCmd.Flags().BoolVarP(&ConvertYaml, "yaml", "y", false, "Generate resource files into YAML format")
|
convertCmd.Flags().BoolVarP(&ConvertYaml, "yaml", "y", false, "Generate resource files into YAML format")
|
||||||
convertCmd.Flags().MarkDeprecated("yaml", "YAML is the default format now.")
|
convertCmd.Flags().MarkDeprecated("yaml", "YAML is the default format now.")
|
||||||
convertCmd.Flags().MarkShorthandDeprecated("y", "YAML is the default format now.")
|
convertCmd.Flags().MarkShorthandDeprecated("y", "YAML is the default format now.")
|
||||||
convertCmd.Flags().BoolVarP(&ConvertJson, "json", "j", false, "Generate resource files into JSON format")
|
convertCmd.Flags().BoolVarP(&ConvertJSON, "json", "j", false, "Generate resource files into JSON format")
|
||||||
convertCmd.Flags().BoolVar(&ConvertStdout, "stdout", false, "Print converted objects to stdout")
|
convertCmd.Flags().BoolVar(&ConvertStdout, "stdout", false, "Print converted objects to stdout")
|
||||||
convertCmd.Flags().BoolVar(&ConvertEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
|
convertCmd.Flags().BoolVar(&ConvertEmptyVols, "emptyvols", false, "Use Empty Volumes. Do not generate PVCs")
|
||||||
convertCmd.Flags().StringVarP(&ConvertOut, "out", "o", "", "Specify a file name to save objects to")
|
convertCmd.Flags().StringVarP(&ConvertOut, "out", "o", "", "Specify a file name to save objects to")
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: comment
|
||||||
var (
|
var (
|
||||||
DownReplicas int
|
DownReplicas int
|
||||||
DownEmptyVols bool
|
DownEmptyVols bool
|
||||||
|
|||||||
12
cmd/root.go
12
cmd/root.go
@ -39,12 +39,17 @@ func (errorOnWarningHook) Fire(entry *logrus.Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: comment
|
||||||
var (
|
var (
|
||||||
GlobalBundle, GlobalProvider string
|
GlobalBundle string
|
||||||
GlobalVerbose, GlobalSuppressWarnings, GlobalErrorOnWarning bool
|
GlobalProvider string
|
||||||
GlobalFiles []string
|
GlobalVerbose bool
|
||||||
|
GlobalSuppressWarnings bool
|
||||||
|
GlobalErrorOnWarning bool
|
||||||
|
GlobalFiles []string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// RootCmd root level flags and commands
|
||||||
var RootCmd = &cobra.Command{
|
var RootCmd = &cobra.Command{
|
||||||
Use: "kompose",
|
Use: "kompose",
|
||||||
Short: "A tool helping Docker Compose users move to Kubernetes",
|
Short: "A tool helping Docker Compose users move to Kubernetes",
|
||||||
@ -76,6 +81,7 @@ var RootCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute TODO: comment
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if err := RootCmd.Execute(); err != nil {
|
if err := RootCmd.Execute(); err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|||||||
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: comment
|
||||||
var (
|
var (
|
||||||
UpReplicas int
|
UpReplicas int
|
||||||
UpEmptyVols bool
|
UpEmptyVols bool
|
||||||
|
|||||||
@ -23,7 +23,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
VERSION = "0.1.2"
|
// VERSION is version number that wil be displayed when running ./kompose version
|
||||||
|
VERSION = "0.1.2"
|
||||||
|
// GITCOMMIT is hash of the commit that wil be displayed when running ./kompose version
|
||||||
GITCOMMIT = "HEAD"
|
GITCOMMIT = "HEAD"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -41,12 +41,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// DefaultComposeFile name of the file that kompose will use if no file is explicitly set
|
||||||
DefaultComposeFile = "docker-compose.yml"
|
DefaultComposeFile = "docker-compose.yml"
|
||||||
DefaultProvider = "kubernetes"
|
// DefaultProvider - provider that will be used if there is no provider was explicitly set
|
||||||
|
DefaultProvider = "kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
var inputFormat = "compose"
|
var inputFormat = "compose"
|
||||||
|
|
||||||
|
// ValidateFlags validates all command line flags
|
||||||
func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobject.ConvertOptions) {
|
func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobject.ConvertOptions) {
|
||||||
|
|
||||||
// Check to see if the "file" has changed from the default flag value
|
// Check to see if the "file" has changed from the default flag value
|
||||||
@ -125,7 +128,7 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
|
|||||||
logrus.Fatal("Unknown Argument(s): ", strings.Join(args, ","))
|
logrus.Fatal("Unknown Argument(s): ", strings.Join(args, ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.GenerateJson && opt.GenerateYaml {
|
if opt.GenerateJSON && opt.GenerateYaml {
|
||||||
logrus.Fatalf("YAML and JSON format cannot be provided at the same time")
|
logrus.Fatalf("YAML and JSON format cannot be provided at the same time")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,7 @@ type KomposeObject struct {
|
|||||||
LoadedFrom string
|
LoadedFrom string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConvertOptions holds all options that controls transformation process
|
||||||
type ConvertOptions struct {
|
type ConvertOptions struct {
|
||||||
ToStdout bool
|
ToStdout bool
|
||||||
CreateD bool
|
CreateD bool
|
||||||
@ -37,7 +38,7 @@ type ConvertOptions struct {
|
|||||||
BuildBranch string
|
BuildBranch string
|
||||||
CreateChart bool
|
CreateChart bool
|
||||||
GenerateYaml bool
|
GenerateYaml bool
|
||||||
GenerateJson bool
|
GenerateJSON bool
|
||||||
EmptyVols bool
|
EmptyVols bool
|
||||||
Replicas int
|
Replicas int
|
||||||
InputFiles []string
|
InputFiles []string
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Bundle is docker bundle file loader, implements Loader interface
|
||||||
type Bundle struct {
|
type Bundle struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +173,7 @@ func loadPorts(service Service) ([]kobject.Ports, string) {
|
|||||||
return ports, ""
|
return ports, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// load dab file into KomposeObject
|
// LoadFile loads dab file into KomposeObject
|
||||||
func (b *Bundle) LoadFile(files []string) kobject.KomposeObject {
|
func (b *Bundle) LoadFile(files []string) kobject.KomposeObject {
|
||||||
komposeObject := kobject.KomposeObject{
|
komposeObject := kobject.KomposeObject{
|
||||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||||
@ -244,7 +245,7 @@ func loadFile(reader io.Reader) (*Bundlefile, error) {
|
|||||||
jsonErr.Error())
|
jsonErr.Error())
|
||||||
case *json.UnmarshalTypeError:
|
case *json.UnmarshalTypeError:
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"Unexpected type at byte %v. Expected %s but received %s.",
|
"unexpected type at byte %v. expected %s but received %s",
|
||||||
jsonErr.Offset,
|
jsonErr.Offset,
|
||||||
jsonErr.Type,
|
jsonErr.Type,
|
||||||
jsonErr.Value)
|
jsonErr.Value)
|
||||||
|
|||||||
@ -34,6 +34,7 @@ import (
|
|||||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Compose is docker compose file loader, implements Loader interface
|
||||||
type Compose struct {
|
type Compose struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,7 +221,7 @@ func loadPorts(composePorts []string) ([]kobject.Ports, error) {
|
|||||||
return ports, nil
|
return ports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// load compose file into KomposeObject
|
// LoadFile loads compose file into KomposeObject
|
||||||
func (c *Compose) LoadFile(files []string) kobject.KomposeObject {
|
func (c *Compose) LoadFile(files []string) kobject.KomposeObject {
|
||||||
komposeObject := kobject.KomposeObject{
|
komposeObject := kobject.KomposeObject{
|
||||||
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
ServiceConfigs: make(map[string]kobject.ServiceConfig),
|
||||||
|
|||||||
@ -17,7 +17,6 @@ limitations under the License.
|
|||||||
package loader
|
package loader
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
@ -25,6 +24,7 @@ import (
|
|||||||
"github.com/kubernetes-incubator/kompose/pkg/loader/compose"
|
"github.com/kubernetes-incubator/kompose/pkg/loader/compose"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Loader interface defines loader that loads files and converts it to kobject representation
|
||||||
type Loader interface {
|
type Loader interface {
|
||||||
LoadFile(files []string) kobject.KomposeObject
|
LoadFile(files []string) kobject.KomposeObject
|
||||||
///Name() string
|
///Name() string
|
||||||
@ -40,7 +40,7 @@ func GetLoader(format string) (Loader, error) {
|
|||||||
case "compose":
|
case "compose":
|
||||||
l = new(compose.Compose)
|
l = new(compose.Compose)
|
||||||
default:
|
default:
|
||||||
return nil, errors.New(fmt.Sprintf("Input file format %s is not supported", format))
|
return nil, fmt.Errorf("Input file format %s is not supported", format)
|
||||||
}
|
}
|
||||||
|
|
||||||
return l, nil
|
return l, nil
|
||||||
|
|||||||
@ -8,10 +8,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// NewCommand TODO: comment
|
||||||
func NewCommand(cmd string) *exec.Cmd {
|
func NewCommand(cmd string) *exec.Cmd {
|
||||||
return exec.Command("sh", "-c", cmd)
|
return exec.Command("sh", "-c", cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLocalDirectory TODO: comment
|
||||||
func CreateLocalDirectory(t *testing.T) string {
|
func CreateLocalDirectory(t *testing.T) string {
|
||||||
dir, err := ioutil.TempDir(os.TempDir(), "kompose-test-")
|
dir, err := ioutil.TempDir(os.TempDir(), "kompose-test-")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -20,6 +22,7 @@ func CreateLocalDirectory(t *testing.T) string {
|
|||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateLocalGitDirectory TODO: comment
|
||||||
func CreateLocalGitDirectory(t *testing.T) string {
|
func CreateLocalGitDirectory(t *testing.T) string {
|
||||||
dir := CreateLocalDirectory(t)
|
dir := CreateLocalDirectory(t)
|
||||||
cmd := NewCommand(
|
cmd := NewCommand(
|
||||||
@ -35,8 +38,9 @@ func CreateLocalGitDirectory(t *testing.T) string {
|
|||||||
return dir
|
return dir
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetGitRemote(t *testing.T, dir string, remote string, remoteUrl string) {
|
// SetGitRemote TODO: comment
|
||||||
cmd := NewCommand(fmt.Sprintf("git remote add %s %s", remote, remoteUrl))
|
func SetGitRemote(t *testing.T, dir string, remote string, remoteURL string) {
|
||||||
|
cmd := NewCommand(fmt.Sprintf("git remote add %s %s", remote, remoteURL))
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
_, err := cmd.Output()
|
_, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -45,6 +49,7 @@ func SetGitRemote(t *testing.T, dir string, remote string, remoteUrl string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateGitRemoteBranch TODO: comment
|
||||||
func CreateGitRemoteBranch(t *testing.T, dir string, branch string, remote string) {
|
func CreateGitRemoteBranch(t *testing.T, dir string, branch string, remote string) {
|
||||||
cmd := NewCommand(
|
cmd := NewCommand(
|
||||||
fmt.Sprintf(`git checkout -b %s &&
|
fmt.Sprintf(`git checkout -b %s &&
|
||||||
@ -60,6 +65,7 @@ func CreateGitRemoteBranch(t *testing.T, dir string, branch string, remote strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateSubdir TODO: comment
|
||||||
func CreateSubdir(t *testing.T, dir string, subdir string) {
|
func CreateSubdir(t *testing.T, dir string, subdir string) {
|
||||||
cmd := NewCommand(fmt.Sprintf("mkdir -p %s", subdir))
|
cmd := NewCommand(fmt.Sprintf("mkdir -p %s", subdir))
|
||||||
cmd.Dir = dir
|
cmd.Dir = dir
|
||||||
|
|||||||
@ -186,11 +186,11 @@ func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data, err := marshal(convertedList, opt.GenerateJson)
|
data, err := marshal(convertedList, opt.GenerateJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Error in marshalling the List: %v", err)
|
return fmt.Errorf("Error in marshalling the List: %v", err)
|
||||||
}
|
}
|
||||||
files = append(files, transformer.Print("", dirName, "", data, opt.ToStdout, opt.GenerateJson, f))
|
files = append(files, transformer.Print("", dirName, "", data, opt.ToStdout, opt.GenerateJSON, f))
|
||||||
} else {
|
} else {
|
||||||
var file string
|
var file string
|
||||||
// create a separate file for each provider
|
// create a separate file for each provider
|
||||||
@ -199,33 +199,33 @@ func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
data, err := marshal(versionedObject, opt.GenerateJson)
|
data, err := marshal(versionedObject, opt.GenerateJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch t := v.(type) {
|
switch t := v.(type) {
|
||||||
case *api.ReplicationController:
|
case *api.ReplicationController:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *extensions.Deployment:
|
case *extensions.Deployment:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *extensions.DaemonSet:
|
case *extensions.DaemonSet:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *deployapi.DeploymentConfig:
|
case *deployapi.DeploymentConfig:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *buildapi.BuildConfig:
|
case *buildapi.BuildConfig:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *imageapi.ImageStream:
|
case *imageapi.ImageStream:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *api.Service:
|
case *api.Service:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *api.PersistentVolumeClaim:
|
case *api.PersistentVolumeClaim:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *api.Pod:
|
case *api.Pod:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *routeapi.Route:
|
case *routeapi.Route:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
case *extensions.Ingress:
|
case *extensions.Ingress:
|
||||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJson, f)
|
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateJSON, f)
|
||||||
|
|
||||||
}
|
}
|
||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
@ -270,16 +270,17 @@ func convertToVersion(obj runtime.Object, groupVersion unversioned.GroupVersion)
|
|||||||
return convertedObject, nil
|
return convertedObject, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PortsExist checks if service has ports defined
|
||||||
func (k *Kubernetes) PortsExist(name string, service kobject.ServiceConfig) bool {
|
func (k *Kubernetes) PortsExist(name string, service kobject.ServiceConfig) bool {
|
||||||
if len(service.Port) == 0 {
|
if len(service.Port) == 0 {
|
||||||
logrus.Warningf("[%s] Service cannot be created because of missing port.", name)
|
logrus.Warningf("[%s] Service cannot be created because of missing port.", name)
|
||||||
return false
|
return false
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
return true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create a k8s service
|
// CreateService creates a k8s service
|
||||||
func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig, objects []runtime.Object) *api.Service {
|
func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig, objects []runtime.Object) *api.Service {
|
||||||
svc := k.InitSvc(name, service)
|
svc := k.InitSvc(name, service)
|
||||||
|
|
||||||
@ -296,7 +297,7 @@ func (k *Kubernetes) CreateService(name string, service kobject.ServiceConfig, o
|
|||||||
return svc
|
return svc
|
||||||
}
|
}
|
||||||
|
|
||||||
// load configurations to k8s objects
|
// UpdateKubernetesObjects loads configurations to k8s objects
|
||||||
func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.ServiceConfig, objects *[]runtime.Object) {
|
func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.ServiceConfig, objects *[]runtime.Object) {
|
||||||
// Configure the environment variables.
|
// Configure the environment variables.
|
||||||
envs := k.ConfigEnvs(name, service)
|
envs := k.ConfigEnvs(name, service)
|
||||||
@ -376,7 +377,7 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// the objects that we get can be in any order this keeps services first
|
// SortServicesFirst - the objects that we get can be in any order this keeps services first
|
||||||
// according to best practice kubernetes services should be created first
|
// according to best practice kubernetes services should be created first
|
||||||
// http://kubernetes.io/docs/user-guide/config-best-practices/
|
// http://kubernetes.io/docs/user-guide/config-best-practices/
|
||||||
func (k *Kubernetes) SortServicesFirst(objs *[]runtime.Object) {
|
func (k *Kubernetes) SortServicesFirst(objs *[]runtime.Object) {
|
||||||
@ -408,8 +409,8 @@ func (k *Kubernetes) findDependentVolumes(svcname string, komposeObject kobject.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// VolumesFrom creates volums and volumeMounts for volumes_from
|
||||||
func (k *Kubernetes) VolumesFrom(objects *[]runtime.Object, komposeObject kobject.KomposeObject) {
|
func (k *Kubernetes) VolumesFrom(objects *[]runtime.Object, komposeObject kobject.KomposeObject) {
|
||||||
|
|
||||||
for _, obj := range *objects {
|
for _, obj := range *objects {
|
||||||
switch t := obj.(type) {
|
switch t := obj.(type) {
|
||||||
case *api.ReplicationController:
|
case *api.ReplicationController:
|
||||||
|
|||||||
@ -20,11 +20,12 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -57,11 +58,11 @@ func TestCreateService(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An example object generated via k8s runtime.Objects()
|
// An example object generated via k8s runtime.Objects()
|
||||||
kompose_object := kobject.KomposeObject{
|
komposeObject := kobject.KomposeObject{
|
||||||
ServiceConfigs: map[string]kobject.ServiceConfig{"app": service},
|
ServiceConfigs: map[string]kobject.ServiceConfig{"app": service},
|
||||||
}
|
}
|
||||||
k := Kubernetes{}
|
k := Kubernetes{}
|
||||||
objects := k.Transform(kompose_object, kobject.ConvertOptions{CreateD: true, Replicas: 3})
|
objects := k.Transform(komposeObject, kobject.ConvertOptions{CreateD: true, Replicas: 3})
|
||||||
|
|
||||||
// Test the creation of the service
|
// Test the creation of the service
|
||||||
svc := k.CreateService("foo", service, objects)
|
svc := k.CreateService("foo", service, objects)
|
||||||
|
|||||||
@ -31,12 +31,14 @@ import (
|
|||||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||||
|
|
||||||
// install kubernetes api
|
// install kubernetes api
|
||||||
"k8s.io/kubernetes/pkg/api"
|
|
||||||
_ "k8s.io/kubernetes/pkg/api/install"
|
_ "k8s.io/kubernetes/pkg/api/install"
|
||||||
|
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
|
||||||
|
|
||||||
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/resource"
|
"k8s.io/kubernetes/pkg/api/resource"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||||
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
|
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/kubectl"
|
"k8s.io/kubernetes/pkg/kubectl"
|
||||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||||
@ -46,12 +48,13 @@ import (
|
|||||||
//"k8s.io/kubernetes/pkg/controller/daemon"
|
//"k8s.io/kubernetes/pkg/controller/daemon"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Kubernetes implements Transformer interface and represents Kubernetes transformer
|
||||||
type Kubernetes struct {
|
type Kubernetes struct {
|
||||||
// the user provided options from the command line
|
// the user provided options from the command line
|
||||||
Opt kobject.ConvertOptions
|
Opt kobject.ConvertOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeout is how long we'll wait for the termination of kubernetes resource to be successful
|
// TIMEOUT is how long we'll wait for the termination of kubernetes resource to be successful
|
||||||
// used when undeploying resources from kubernetes
|
// used when undeploying resources from kubernetes
|
||||||
const TIMEOUT = 300
|
const TIMEOUT = 300
|
||||||
|
|
||||||
@ -64,7 +67,7 @@ var unsupportedKey = map[string]bool{
|
|||||||
"Build": false,
|
"Build": false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// checkUnsupportedKey checks if given komposeObject contains
|
// CheckUnsupportedKey checks if given komposeObject contains
|
||||||
// keys that are not supported by this tranfomer.
|
// keys that are not supported by this tranfomer.
|
||||||
// list of all unsupported keys are stored in unsupportedKey variable
|
// list of all unsupported keys are stored in unsupportedKey variable
|
||||||
// returns list of TODO: ....
|
// returns list of TODO: ....
|
||||||
@ -101,7 +104,7 @@ func (k *Kubernetes) CheckUnsupportedKey(komposeObject *kobject.KomposeObject, u
|
|||||||
return keysFound
|
return keysFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init RC object
|
// InitRC initializes Kubernetes ReplicationController object
|
||||||
func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas int) *api.ReplicationController {
|
func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas int) *api.ReplicationController {
|
||||||
rc := &api.ReplicationController{
|
rc := &api.ReplicationController{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
@ -131,7 +134,7 @@ func (k *Kubernetes) InitRC(name string, service kobject.ServiceConfig, replicas
|
|||||||
return rc
|
return rc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Svc object
|
// InitSvc initializes Kubernets Service object
|
||||||
func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Service {
|
func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Service {
|
||||||
svc := &api.Service{
|
svc := &api.Service{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
@ -149,7 +152,7 @@ func (k *Kubernetes) InitSvc(name string, service kobject.ServiceConfig) *api.Se
|
|||||||
return svc
|
return svc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init Deployment
|
// InitD initializes Kubernetes Deployment object
|
||||||
func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas int) *extensions.Deployment {
|
func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas int) *extensions.Deployment {
|
||||||
dc := &extensions.Deployment{
|
dc := &extensions.Deployment{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
@ -176,7 +179,7 @@ func (k *Kubernetes) InitD(name string, service kobject.ServiceConfig, replicas
|
|||||||
return dc
|
return dc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init DS object
|
// InitDS initializes Kubernetes DaemonSet object
|
||||||
func (k *Kubernetes) InitDS(name string, service kobject.ServiceConfig) *extensions.DaemonSet {
|
func (k *Kubernetes) InitDS(name string, service kobject.ServiceConfig) *extensions.DaemonSet {
|
||||||
ds := &extensions.DaemonSet{
|
ds := &extensions.DaemonSet{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
@ -241,7 +244,7 @@ func (k *Kubernetes) initIngress(name string, service kobject.ServiceConfig, por
|
|||||||
return ingress
|
return ingress
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize PersistentVolumeClaim
|
// CreatePVC initializes PersistentVolumeClaim
|
||||||
func (k *Kubernetes) CreatePVC(name string, mode string) *api.PersistentVolumeClaim {
|
func (k *Kubernetes) CreatePVC(name string, mode string) *api.PersistentVolumeClaim {
|
||||||
size, err := resource.ParseQuantity("100Mi")
|
size, err := resource.ParseQuantity("100Mi")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -273,7 +276,7 @@ func (k *Kubernetes) CreatePVC(name string, mode string) *api.PersistentVolumeCl
|
|||||||
return pvc
|
return pvc
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the container ports.
|
// ConfigPorts configures the container ports.
|
||||||
func (k *Kubernetes) ConfigPorts(name string, service kobject.ServiceConfig) []api.ContainerPort {
|
func (k *Kubernetes) ConfigPorts(name string, service kobject.ServiceConfig) []api.ContainerPort {
|
||||||
ports := []api.ContainerPort{}
|
ports := []api.ContainerPort{}
|
||||||
for _, port := range service.Port {
|
for _, port := range service.Port {
|
||||||
@ -286,7 +289,7 @@ func (k *Kubernetes) ConfigPorts(name string, service kobject.ServiceConfig) []a
|
|||||||
return ports
|
return ports
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the container service ports.
|
// ConfigServicePorts configure the container service ports.
|
||||||
func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConfig) []api.ServicePort {
|
func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConfig) []api.ServicePort {
|
||||||
servicePorts := []api.ServicePort{}
|
servicePorts := []api.ServicePort{}
|
||||||
for _, port := range service.Port {
|
for _, port := range service.Port {
|
||||||
@ -306,7 +309,7 @@ func (k *Kubernetes) ConfigServicePorts(name string, service kobject.ServiceConf
|
|||||||
return servicePorts
|
return servicePorts
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the container volumes.
|
// ConfigVolumes configure the container volumes.
|
||||||
func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume, []*api.PersistentVolumeClaim) {
|
func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) ([]api.VolumeMount, []api.Volume, []*api.PersistentVolumeClaim) {
|
||||||
volumeMounts := []api.VolumeMount{}
|
volumeMounts := []api.VolumeMount{}
|
||||||
volumes := []api.Volume{}
|
volumes := []api.Volume{}
|
||||||
@ -368,14 +371,14 @@ func (k *Kubernetes) ConfigVolumes(name string, service kobject.ServiceConfig) (
|
|||||||
return volumeMounts, volumes, PVCs
|
return volumeMounts, volumes, PVCs
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create an EmptyDir api.VolumeSource
|
// ConfigEmptyVolumeSource is helper function to create an EmptyDir api.VolumeSource
|
||||||
func (k *Kubernetes) ConfigEmptyVolumeSource() *api.VolumeSource {
|
func (k *Kubernetes) ConfigEmptyVolumeSource() *api.VolumeSource {
|
||||||
return &api.VolumeSource{
|
return &api.VolumeSource{
|
||||||
EmptyDir: &api.EmptyDirVolumeSource{},
|
EmptyDir: &api.EmptyDirVolumeSource{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create an api.VolumeSource with a PVC
|
// ConfigPVCVolumeSource is helper function to create an api.VolumeSource with a PVC
|
||||||
func (k *Kubernetes) ConfigPVCVolumeSource(name string, readonly bool) *api.VolumeSource {
|
func (k *Kubernetes) ConfigPVCVolumeSource(name string, readonly bool) *api.VolumeSource {
|
||||||
return &api.VolumeSource{
|
return &api.VolumeSource{
|
||||||
PersistentVolumeClaim: &api.PersistentVolumeClaimVolumeSource{
|
PersistentVolumeClaim: &api.PersistentVolumeClaimVolumeSource{
|
||||||
@ -385,7 +388,7 @@ func (k *Kubernetes) ConfigPVCVolumeSource(name string, readonly bool) *api.Volu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure the environment variables.
|
// ConfigEnvs configures the environment variables.
|
||||||
func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []api.EnvVar {
|
func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []api.EnvVar {
|
||||||
envs := []api.EnvVar{}
|
envs := []api.EnvVar{}
|
||||||
for _, v := range service.Environment {
|
for _, v := range service.Environment {
|
||||||
@ -398,7 +401,7 @@ func (k *Kubernetes) ConfigEnvs(name string, service kobject.ServiceConfig) []ap
|
|||||||
return envs
|
return envs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate a Kubernetes artifact for each input type service
|
// CreateKubernetesObjects generates a Kubernetes artifact for each input type service
|
||||||
func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object {
|
func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.ServiceConfig, opt kobject.ConvertOptions) []runtime.Object {
|
||||||
var objects []runtime.Object
|
var objects []runtime.Object
|
||||||
|
|
||||||
@ -415,6 +418,7 @@ func (k *Kubernetes) CreateKubernetesObjects(name string, service kobject.Servic
|
|||||||
return objects
|
return objects
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InitPod initializes Kubernetes Pod object
|
||||||
func (k *Kubernetes) InitPod(name string, service kobject.ServiceConfig) *api.Pod {
|
func (k *Kubernetes) InitPod(name string, service kobject.ServiceConfig) *api.Pod {
|
||||||
pod := api.Pod{
|
pod := api.Pod{
|
||||||
TypeMeta: unversioned.TypeMeta{
|
TypeMeta: unversioned.TypeMeta{
|
||||||
@ -450,7 +454,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
|
|
||||||
// Need to ensure the kubernetes objects are in a consistent order
|
// Need to ensure the kubernetes objects are in a consistent order
|
||||||
var sortedKeys []string
|
var sortedKeys []string
|
||||||
for name, _ := range komposeObject.ServiceConfigs {
|
for name := range komposeObject.ServiceConfigs {
|
||||||
sortedKeys = append(sortedKeys, name)
|
sortedKeys = append(sortedKeys, name)
|
||||||
}
|
}
|
||||||
sort.Strings(sortedKeys)
|
sort.Strings(sortedKeys)
|
||||||
@ -487,7 +491,7 @@ func (k *Kubernetes) Transform(komposeObject kobject.KomposeObject, opt kobject.
|
|||||||
return allobjects
|
return allobjects
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates the given object with the given pod template update function and ObjectMeta update function
|
// UpdateController updates the given object with the given pod template update function and ObjectMeta update function
|
||||||
func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*api.PodTemplateSpec), updateMeta func(meta *api.ObjectMeta)) {
|
func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*api.PodTemplateSpec), updateMeta func(meta *api.ObjectMeta)) {
|
||||||
switch t := obj.(type) {
|
switch t := obj.(type) {
|
||||||
case *api.ReplicationController:
|
case *api.ReplicationController:
|
||||||
@ -518,8 +522,8 @@ func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*a
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the k8s Client, returns k8s client and namespace
|
// GetKubernetesClient creates the k8s Client, returns k8s client and namespace
|
||||||
func (o *Kubernetes) GetKubernetesClient() (*client.Client, string, error) {
|
func (k *Kubernetes) GetKubernetesClient() (*client.Client, string, error) {
|
||||||
// initialize Kubernetes client
|
// initialize Kubernetes client
|
||||||
factory := cmdutil.NewFactory(nil)
|
factory := cmdutil.NewFactory(nil)
|
||||||
clientConfig, err := factory.ClientConfig()
|
clientConfig, err := factory.ClientConfig()
|
||||||
@ -536,7 +540,7 @@ func (o *Kubernetes) GetKubernetesClient() (*client.Client, string, error) {
|
|||||||
return client, namespace, nil
|
return client, namespace, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit deployment and svc to k8s endpoint
|
// Deploy submits deployment and svc to k8s endpoint
|
||||||
func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
||||||
//Convert komposeObject
|
//Convert komposeObject
|
||||||
objects := k.Transform(komposeObject, opt)
|
objects := k.Transform(komposeObject, opt)
|
||||||
@ -592,6 +596,7 @@ func (k *Kubernetes) Deploy(komposeObject kobject.KomposeObject, opt kobject.Con
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Undeploy deletes deployed objects from Kubernetes cluster
|
||||||
func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
||||||
//Convert komposeObject
|
//Convert komposeObject
|
||||||
objects := k.Transform(komposeObject, opt)
|
objects := k.Transform(komposeObject, opt)
|
||||||
@ -613,9 +618,9 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
err = rpDeployment.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
err = rpDeployment.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted Deployment: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted Deployment: %s", t.Name)
|
||||||
|
|
||||||
case *api.Service:
|
case *api.Service:
|
||||||
//delete svc
|
//delete svc
|
||||||
rpService, err := kubectl.ReaperFor(api.Kind("Service"), client)
|
rpService, err := kubectl.ReaperFor(api.Kind("Service"), client)
|
||||||
@ -626,17 +631,17 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
err = rpService.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
err = rpService.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted Service: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted Service: %s", t.Name)
|
||||||
|
|
||||||
case *api.PersistentVolumeClaim:
|
case *api.PersistentVolumeClaim:
|
||||||
// delete pvc
|
// delete pvc
|
||||||
err = client.PersistentVolumeClaims(namespace).Delete(t.Name)
|
err = client.PersistentVolumeClaims(namespace).Delete(t.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted PersistentVolumeClaim: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted PersistentVolumeClaim: %s", t.Name)
|
||||||
|
|
||||||
case *extensions.Ingress:
|
case *extensions.Ingress:
|
||||||
// delete ingress
|
// delete ingress
|
||||||
ingDeleteOptions := &api.DeleteOptions{
|
ingDeleteOptions := &api.DeleteOptions{
|
||||||
@ -648,9 +653,9 @@ func (k *Kubernetes) Undeploy(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
err = client.Ingress(namespace).Delete(t.Name, ingDeleteOptions)
|
err = client.Ingress(namespace).Delete(t.Name, ingDeleteOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted Ingress: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted Ingress: %s", t.Name)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -76,14 +76,14 @@ func equalStringSlice(s1, s2 []string) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalEnv(kEnvs []kobject.EnvVar, k8sEnvs []api.EnvVar) bool {
|
func equalEnv(kobjectEnvs []kobject.EnvVar, k8sEnvs []api.EnvVar) bool {
|
||||||
if len(kEnvs) != len(k8sEnvs) {
|
if len(kobjectEnvs) != len(k8sEnvs) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, kEnv := range kEnvs {
|
for _, env := range kobjectEnvs {
|
||||||
found := false
|
found := false
|
||||||
for _, k8sEnv := range k8sEnvs {
|
for _, k8sEnv := range k8sEnvs {
|
||||||
if kEnv.Name == k8sEnv.Name && kEnv.Value == k8sEnv.Value {
|
if env.Name == k8sEnv.Name && env.Value == k8sEnv.Value {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,16 +94,16 @@ func equalEnv(kEnvs []kobject.EnvVar, k8sEnvs []api.EnvVar) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func equalPorts(kPorts []kobject.Ports, k8sPorts []api.ContainerPort) bool {
|
func equalPorts(kobjectPorts []kobject.Ports, k8sPorts []api.ContainerPort) bool {
|
||||||
if len(kPorts) != len(k8sPorts) {
|
if len(kobjectPorts) != len(k8sPorts) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, kPort := range kPorts {
|
for _, port := range kobjectPorts {
|
||||||
found := false
|
found := false
|
||||||
for _, k8sPort := range k8sPorts {
|
for _, k8sPort := range k8sPorts {
|
||||||
// FIXME: HostPort should be copied to container port
|
// FIXME: HostPort should be copied to container port
|
||||||
//if kPort.HostPort == k8sPort.HostPort && kPort.Protocol == k8sPort.Protocol && kPort.ContainerPort == k8sPort.ContainerPort {
|
//if port.HostPort == k8sPort.HostPort && port.Protocol == k8sPort.Protocol && port.ContainerPort == k8sPort.ContainerPort {
|
||||||
if kPort.Protocol == k8sPort.Protocol && kPort.ContainerPort == k8sPort.ContainerPort {
|
if port.Protocol == k8sPort.Protocol && port.ContainerPort == k8sPort.ContainerPort {
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
// Name and HostIp shouldn't be set
|
// Name and HostIp shouldn't be set
|
||||||
|
|||||||
@ -48,6 +48,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/util/intstr"
|
"k8s.io/kubernetes/pkg/util/intstr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// OpenShift implements Transformer interface and represents OpenShift transformer
|
||||||
type OpenShift struct {
|
type OpenShift struct {
|
||||||
// Anonymous field allows for inheritance. We are basically inheriting
|
// Anonymous field allows for inheritance. We are basically inheriting
|
||||||
// all of kubernetes.Kubernetes Methods and variables here. We'll overwite
|
// all of kubernetes.Kubernetes Methods and variables here. We'll overwite
|
||||||
@ -55,7 +56,7 @@ type OpenShift struct {
|
|||||||
kubernetes.Kubernetes
|
kubernetes.Kubernetes
|
||||||
}
|
}
|
||||||
|
|
||||||
// timeout is how long we'll wait for the termination of OpenShift resource to be successful
|
// TIMEOUT is how long we'll wait for the termination of OpenShift resource to be successful
|
||||||
// used when undeploying resources from OpenShift
|
// used when undeploying resources from OpenShift
|
||||||
const TIMEOUT = 300
|
const TIMEOUT = 300
|
||||||
|
|
||||||
@ -72,9 +73,9 @@ func getImageTag(image string) string {
|
|||||||
p := strings.Split(image, ":")
|
p := strings.Split(image, ":")
|
||||||
if len(p) == 2 {
|
if len(p) == 2 {
|
||||||
return p[1]
|
return p[1]
|
||||||
} else {
|
|
||||||
return "latest"
|
|
||||||
}
|
}
|
||||||
|
return "latest"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasGitBinary checks if the 'git' binary is available on the system
|
// hasGitBinary checks if the 'git' binary is available on the system
|
||||||
@ -83,8 +84,8 @@ func hasGitBinary() bool {
|
|||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getGitCurrentRemoteUrl gets current git remote URI for the current git repo
|
// getGitCurrentRemoteURL gets current git remote URI for the current git repo
|
||||||
func getGitCurrentRemoteUrl(composeFileDir string) (string, error) {
|
func getGitCurrentRemoteURL(composeFileDir string) (string, error) {
|
||||||
cmd := exec.Command("git", "ls-remote", "--get-url")
|
cmd := exec.Command("git", "ls-remote", "--get-url")
|
||||||
cmd.Dir = composeFileDir
|
cmd.Dir = composeFileDir
|
||||||
out, err := cmd.Output()
|
out, err := cmd.Output()
|
||||||
@ -352,7 +353,7 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Buildconfig cannot be created because remote for current git branch couldn't be detected.")
|
logrus.Fatalf("Buildconfig cannot be created because remote for current git branch couldn't be detected.")
|
||||||
}
|
}
|
||||||
buildRepo, err = getGitCurrentRemoteUrl(composeFileDir)
|
buildRepo, err = getGitCurrentRemoteURL(composeFileDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatalf("Buildconfig cannot be created because git remote origin repo couldn't be detected.")
|
logrus.Fatalf("Buildconfig cannot be created because git remote origin repo couldn't be detected.")
|
||||||
}
|
}
|
||||||
@ -400,6 +401,7 @@ func (o *OpenShift) getOpenShiftClient() (*oclient.Client, error) {
|
|||||||
return oclient, nil
|
return oclient, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deploy transofrms and deploys kobject to OpenShift
|
||||||
func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
||||||
//Convert komposeObject
|
//Convert komposeObject
|
||||||
objects := o.Transform(komposeObject, opt)
|
objects := o.Transform(komposeObject, opt)
|
||||||
@ -470,6 +472,7 @@ func (o *OpenShift) Deploy(komposeObject kobject.KomposeObject, opt kobject.Conv
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Undeploy removes deployed artifacts from OpenShift cluster
|
||||||
func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.ConvertOptions) error {
|
||||||
//Convert komposeObject
|
//Convert komposeObject
|
||||||
objects := o.Transform(komposeObject, opt)
|
objects := o.Transform(komposeObject, opt)
|
||||||
@ -490,18 +493,18 @@ func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.Co
|
|||||||
err = oclient.ImageStreams(namespace).Delete(t.Name)
|
err = oclient.ImageStreams(namespace).Delete(t.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted ImageStream: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted ImageStream: %s", t.Name)
|
||||||
|
|
||||||
case *deployapi.DeploymentConfig:
|
case *deployapi.DeploymentConfig:
|
||||||
// delete deploymentConfig
|
// delete deploymentConfig
|
||||||
dcreaper := deploymentconfigreaper.NewDeploymentConfigReaper(oclient, kclient)
|
dcreaper := deploymentconfigreaper.NewDeploymentConfigReaper(oclient, kclient)
|
||||||
err := dcreaper.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
err := dcreaper.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted DeploymentConfig: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted DeploymentConfig: %s", t.Name)
|
||||||
|
|
||||||
case *api.Service:
|
case *api.Service:
|
||||||
//delete svc
|
//delete svc
|
||||||
rpService, err := kubectl.ReaperFor(api.Kind("Service"), kclient)
|
rpService, err := kubectl.ReaperFor(api.Kind("Service"), kclient)
|
||||||
@ -512,25 +515,25 @@ func (o *OpenShift) Undeploy(komposeObject kobject.KomposeObject, opt kobject.Co
|
|||||||
err = rpService.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
err = rpService.Stop(namespace, t.Name, TIMEOUT*time.Second, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted service: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted service: %s", t.Name)
|
||||||
|
|
||||||
case *api.PersistentVolumeClaim:
|
case *api.PersistentVolumeClaim:
|
||||||
// delete pvc
|
// delete pvc
|
||||||
err = kclient.PersistentVolumeClaims(namespace).Delete(t.Name)
|
err = kclient.PersistentVolumeClaims(namespace).Delete(t.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted PersistentVolumeClaim: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted PersistentVolumeClaim: %s", t.Name)
|
||||||
|
|
||||||
case *routeapi.Route:
|
case *routeapi.Route:
|
||||||
// delete route
|
// delete route
|
||||||
err = oclient.Routes(namespace).Delete(t.Name)
|
err = oclient.Routes(namespace).Delete(t.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else {
|
|
||||||
logrus.Infof("Successfully deleted Route: %s", t.Name)
|
|
||||||
}
|
}
|
||||||
|
logrus.Infof("Successfully deleted Route: %s", t.Name)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@ -150,7 +150,7 @@ func TestGetGitRemote(t *testing.T) {
|
|||||||
|
|
||||||
for name, test := range testCases {
|
for name, test := range testCases {
|
||||||
t.Log("Test case: ", name)
|
t.Log("Test case: ", name)
|
||||||
output, err = getGitCurrentRemoteUrl(test.dir)
|
output, err = getGitCurrentRemoteURL(test.dir)
|
||||||
|
|
||||||
if test.expectError {
|
if test.expectError {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Transformer interface defines transformer that is converting kobject to other resources
|
||||||
type Transformer interface {
|
type Transformer interface {
|
||||||
// Transform converts KomposeObject to transformer specific objects.
|
// Transform converts KomposeObject to transformer specific objects.
|
||||||
Transform(kobject.KomposeObject, kobject.ConvertOptions) []runtime.Object
|
Transform(kobject.KomposeObject, kobject.ConvertOptions) []runtime.Object
|
||||||
|
|||||||
@ -28,10 +28,11 @@ import (
|
|||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||||
|
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/runtime"
|
"k8s.io/kubernetes/pkg/runtime"
|
||||||
"path/filepath"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
|
const letterBytes = "abcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
@ -45,7 +46,7 @@ func RandStringBytes(n int) string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the file to write to if --out is specified
|
// CreateOutFile creates the file to write to if --out is specified
|
||||||
func CreateOutFile(out string) *os.File {
|
func CreateOutFile(out string) *os.File {
|
||||||
var f *os.File
|
var f *os.File
|
||||||
var err error
|
var err error
|
||||||
@ -58,7 +59,7 @@ func CreateOutFile(out string) *os.File {
|
|||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
// parseVolume parse a given volume, which might be [name:][host:]container[:access_mode]
|
// ParseVolume parses a given volume, which might be [name:][host:]container[:access_mode]
|
||||||
func ParseVolume(volume string) (name, host, container, mode string, err error) {
|
func ParseVolume(volume string) (name, host, container, mode string, err error) {
|
||||||
separator := ":"
|
separator := ":"
|
||||||
volumeStrings := strings.Split(volume, separator)
|
volumeStrings := strings.Split(volume, separator)
|
||||||
@ -94,12 +95,12 @@ func isPath(substring string) bool {
|
|||||||
return strings.Contains(substring, "/")
|
return strings.Contains(substring, "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure label
|
// ConfigLabels configures label
|
||||||
func ConfigLabels(name string) map[string]string {
|
func ConfigLabels(name string) map[string]string {
|
||||||
return map[string]string{"service": name}
|
return map[string]string{"service": name}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure annotations
|
// ConfigAnnotations configures annotations
|
||||||
func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
||||||
annotations := map[string]string{}
|
annotations := map[string]string{}
|
||||||
for key, value := range service.Annotations {
|
for key, value := range service.Annotations {
|
||||||
@ -109,8 +110,8 @@ func ConfigAnnotations(service kobject.ServiceConfig) map[string]string {
|
|||||||
return annotations
|
return annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform data to json/yaml
|
// TransformData transforms data to json/yaml
|
||||||
func TransformData(obj runtime.Object, GenerateJson bool) ([]byte, error) {
|
func TransformData(obj runtime.Object, GenerateJSON bool) ([]byte, error) {
|
||||||
// Convert to versioned object
|
// Convert to versioned object
|
||||||
objectVersion := obj.GetObjectKind().GroupVersionKind()
|
objectVersion := obj.GetObjectKind().GroupVersionKind()
|
||||||
version := unversioned.GroupVersion{Group: objectVersion.Group, Version: objectVersion.Version}
|
version := unversioned.GroupVersion{Group: objectVersion.Group, Version: objectVersion.Version}
|
||||||
@ -121,7 +122,7 @@ func TransformData(obj runtime.Object, GenerateJson bool) ([]byte, error) {
|
|||||||
|
|
||||||
// convert data to json / yaml
|
// convert data to json / yaml
|
||||||
data, err := yaml.Marshal(versionedObj)
|
data, err := yaml.Marshal(versionedObj)
|
||||||
if GenerateJson == true {
|
if GenerateJSON == true {
|
||||||
data, err = json.MarshalIndent(versionedObj, "", " ")
|
data, err = json.MarshalIndent(versionedObj, "", " ")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -131,11 +132,10 @@ func TransformData(obj runtime.Object, GenerateJson bool) ([]byte, error) {
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Either print to stdout or to file/s
|
// Print either prints to stdout or to file/s
|
||||||
func Print(name, path string, trailing string, data []byte, toStdout, generateJson bool, f *os.File) string {
|
func Print(name, path string, trailing string, data []byte, toStdout, generateJSON bool, f *os.File) string {
|
||||||
|
|
||||||
file := ""
|
file := ""
|
||||||
if generateJson {
|
if generateJSON {
|
||||||
file = fmt.Sprintf("%s-%s.json", name, trailing)
|
file = fmt.Sprintf("%s-%s.json", name, trailing)
|
||||||
} else {
|
} else {
|
||||||
file = fmt.Sprintf("%s-%s.yaml", name, trailing)
|
file = fmt.Sprintf("%s-%s.yaml", name, trailing)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user