Initial implementation of BuildConfig support for Openshift provider.
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
_ "k8s.io/kubernetes/pkg/apis/extensions/install"
|
||||
|
||||
// install OpenShift api
|
||||
_ "github.com/openshift/origin/pkg/build/api/install"
|
||||
_ "github.com/openshift/origin/pkg/deploy/api/install"
|
||||
_ "github.com/openshift/origin/pkg/image/api/install"
|
||||
_ "github.com/openshift/origin/pkg/route/api/install"
|
||||
@@ -62,6 +63,7 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
|
||||
|
||||
// OpenShift specific flags
|
||||
deploymentConfig := cmd.Flags().Lookup("deployment-config").Changed
|
||||
buildConfig := cmd.Flags().Lookup("build-config").Changed
|
||||
|
||||
// Kubernetes specific flags
|
||||
chart := cmd.Flags().Lookup("chart").Changed
|
||||
@@ -88,6 +90,9 @@ func ValidateFlags(bundle string, args []string, cmd *cobra.Command, opt *kobjec
|
||||
if deploymentConfig {
|
||||
logrus.Fatalf("--deployment-config is an OpenShift only flag")
|
||||
}
|
||||
if buildConfig {
|
||||
logrus.Fatalf("--build-config is an Openshift only flag")
|
||||
}
|
||||
}
|
||||
|
||||
// Standard checks regardless of provider
|
||||
|
||||
@@ -33,6 +33,7 @@ type ConvertOptions struct {
|
||||
CreateRC bool
|
||||
CreateDS bool
|
||||
CreateDeploymentConfig bool
|
||||
CreateBuildConfig bool
|
||||
CreateChart bool
|
||||
GenerateYaml bool
|
||||
EmptyVols bool
|
||||
|
||||
@@ -270,6 +270,7 @@ func (c *Compose) LoadFile(file string) kobject.KomposeObject {
|
||||
if composeServiceConfig, ok := composeObject.ServiceConfigs.Get(name); ok {
|
||||
serviceConfig := kobject.ServiceConfig{}
|
||||
serviceConfig.Image = composeServiceConfig.Image
|
||||
serviceConfig.Build = composeServiceConfig.Build.Context
|
||||
serviceConfig.ContainerName = composeServiceConfig.ContainerName
|
||||
serviceConfig.Command = composeServiceConfig.Entrypoint
|
||||
serviceConfig.Args = composeServiceConfig.Command
|
||||
|
||||
@@ -37,6 +37,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/apis/extensions"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
|
||||
buildapi "github.com/openshift/origin/pkg/build/api"
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
imageapi "github.com/openshift/origin/pkg/image/api"
|
||||
routeapi "github.com/openshift/origin/pkg/route/api"
|
||||
@@ -211,6 +212,8 @@ func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateYaml, f)
|
||||
case *deployapi.DeploymentConfig:
|
||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateYaml, f)
|
||||
case *buildapi.BuildConfig:
|
||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateYaml, f)
|
||||
case *imageapi.ImageStream:
|
||||
file = transformer.Print(t.Name, dirName, strings.ToLower(t.Kind), data, opt.ToStdout, opt.GenerateYaml, f)
|
||||
case *api.Service:
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/fatih/structs"
|
||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||
"github.com/kubernetes-incubator/kompose/pkg/transformer"
|
||||
buildapi "github.com/openshift/origin/pkg/build/api"
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
|
||||
// install kubernetes api
|
||||
@@ -512,6 +513,8 @@ func (k *Kubernetes) UpdateController(obj runtime.Object, updateTemplate func(*a
|
||||
updateTemplate(&p)
|
||||
t.Spec = p.Spec
|
||||
t.ObjectMeta = p.ObjectMeta
|
||||
case *buildapi.BuildConfig:
|
||||
updateMeta(&t.ObjectMeta)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package openshift
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/kubernetes-incubator/kompose/pkg/kobject"
|
||||
@@ -26,6 +27,7 @@ import (
|
||||
"github.com/Sirupsen/logrus"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
kapi "k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/unversioned"
|
||||
"k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
|
||||
"k8s.io/kubernetes/pkg/runtime"
|
||||
@@ -35,6 +37,7 @@ import (
|
||||
|
||||
"time"
|
||||
|
||||
buildapi "github.com/openshift/origin/pkg/build/api"
|
||||
deployapi "github.com/openshift/origin/pkg/deploy/api"
|
||||
deploymentconfigreaper "github.com/openshift/origin/pkg/deploy/cmd"
|
||||
imageapi "github.com/openshift/origin/pkg/image/api"
|
||||
@@ -72,6 +75,15 @@ func getImageTag(image string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// getGitRemote gets git remote URI for the current git repo
|
||||
func getGitRemote(remote string) string {
|
||||
out, err := exec.Command("git", "remote", "get-url", remote).Output()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// initImageStream initialize ImageStream object
|
||||
func (o *OpenShift) initImageStream(name string, service kobject.ServiceConfig) *imageapi.ImageStream {
|
||||
tag := getImageTag(service.Image)
|
||||
@@ -98,6 +110,52 @@ func (o *OpenShift) initImageStream(name string, service kobject.ServiceConfig)
|
||||
return is
|
||||
}
|
||||
|
||||
// initBuildConfig initialize Openshifts BuildConfig Object
|
||||
func initBuildConfig(name string, service kobject.ServiceConfig) *buildapi.BuildConfig {
|
||||
bc := &buildapi.BuildConfig{
|
||||
TypeMeta: unversioned.TypeMeta{
|
||||
Kind: "BuildConfig",
|
||||
APIVersion: "v1",
|
||||
},
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
Spec: buildapi.BuildConfigSpec{
|
||||
// Triggers
|
||||
[]buildapi.BuildTriggerPolicy{
|
||||
{Type: "ConfigChange"},
|
||||
{Type: "ImageChange"},
|
||||
},
|
||||
// RunPolicy
|
||||
"serial",
|
||||
buildapi.CommonSpec{
|
||||
Source: buildapi.BuildSource{
|
||||
Git: &buildapi.GitBuildSource{
|
||||
Ref: "master",
|
||||
URI: getGitRemote("origin"),
|
||||
},
|
||||
ContextDir: "./",
|
||||
},
|
||||
Strategy: buildapi.BuildStrategy{
|
||||
DockerStrategy: &buildapi.DockerBuildStrategy{
|
||||
From: &kapi.ObjectReference{
|
||||
Kind: "ImageStreamTag",
|
||||
Name: name + ":from",
|
||||
},
|
||||
},
|
||||
},
|
||||
Output: buildapi.BuildOutput{
|
||||
To: &kapi.ObjectReference{
|
||||
Kind: "ImageStreamTag",
|
||||
Name: name + ":latest",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
return bc
|
||||
}
|
||||
|
||||
// initDeploymentConfig initialize OpenShifts DeploymentConfig object
|
||||
func (o *OpenShift) initDeploymentConfig(name string, service kobject.ServiceConfig, replicas int) *deployapi.DeploymentConfig {
|
||||
tag := getImageTag(service.Image)
|
||||
@@ -212,6 +270,10 @@ func (o *OpenShift) Transform(komposeObject kobject.KomposeObject, opt kobject.C
|
||||
objects = append(objects, o.initImageStream(name, service))
|
||||
}
|
||||
|
||||
if opt.CreateBuildConfig && service.Build != "" {
|
||||
objects = append(objects, initBuildConfig(name, service)) // Openshift BuildConfigs
|
||||
}
|
||||
|
||||
// If ports not provided in configuration we will not make service
|
||||
if o.PortsExist(name, service) {
|
||||
svc := o.CreateService(name, service, objects)
|
||||
|
||||
Reference in New Issue
Block a user