Skip to content

Commit

Permalink
Support generating DeploymentConfigs from run
Browse files Browse the repository at this point in the history
Define "run/v1" as DeploymentConfig, and "run-controller/v1" as
the upstream.
  • Loading branch information
smarterclayton committed Aug 21, 2015
1 parent f16467f commit 91fe6d4
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pkg/cmd/cli/cmd/wrappers.go
Expand Up @@ -306,8 +306,9 @@ func NewCmdStop(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Com
const (
runLong = `Create and run a particular image, possibly replicated
Creates a replication controller to manage the created container(s). You can choose to run in the
foreground for an interactive container execution.`
Creates a deployment config to manage the created container(s). You can choose to run in the
foreground for an interactive container execution. You may pass 'run-controller/v1' to
--generator to create a replication controller instead of a deployment config.`

runExample = ` // Starts a single instance of nginx.
$ %[1]s run nginx --image=nginx
Expand Down Expand Up @@ -340,6 +341,9 @@ func NewCmdRun(fullName string, f *clientcmd.Factory, in io.Reader, out, errout
cmd := kcmd.NewCmdRun(f.Factory, in, out, errout)
cmd.Long = runLong
cmd.Example = fmt.Sprintf(runExample, fullName)
cmd.Flags().Set("generator", "")
cmd.Flag("generator").Usage = "The name of the API generator to use. Default is 'run/v1' if --restart=Always, otherwise the default is 'run-pod/v1'."
cmd.Flag("generator").DefValue = ""
return cmd
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/cmd/util/clientcmd/factory.go
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/openshift/origin/pkg/client"
"github.com/openshift/origin/pkg/cmd/cli/describe"
deployapi "github.com/openshift/origin/pkg/deploy/api"
deploygen "github.com/openshift/origin/pkg/deploy/generator"
deployreaper "github.com/openshift/origin/pkg/deploy/reaper"
deployscaler "github.com/openshift/origin/pkg/deploy/scaler"
routegen "github.com/openshift/origin/pkg/route/generator"
Expand Down Expand Up @@ -58,7 +59,9 @@ func NewFactory(clientConfig kclientcmd.ClientConfig) *Factory {
}

generators := map[string]kubectl.Generator{
"route/v1": routegen.RouteGenerator{},
"route/v1": routegen.RouteGenerator{},
"run/v1": deploygen.BasicDeploymentConfigController{},
"run-controller/v1": kubectl.BasicReplicationController{},
}

w := &Factory{
Expand Down
7 changes: 7 additions & 0 deletions pkg/deploy/api/v1/defaults.go
Expand Up @@ -12,6 +12,13 @@ func init() {
}

err := api.Scheme.AddDefaultingFuncs(
func(obj *DeploymentConfigSpec) {
if obj.Triggers == nil {
obj.Triggers = []DeploymentTriggerPolicy{
{Type: DeploymentTriggerOnConfigChange},
}
}
},
func(obj *DeploymentStrategy) {
if len(obj.Type) == 0 {
obj.Type = DeploymentStrategyTypeRolling
Expand Down
39 changes: 39 additions & 0 deletions pkg/deploy/generator/generator.go
@@ -0,0 +1,39 @@
package generator

import (
"fmt"
"reflect"

kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/runtime"

deployapi "github.com/openshift/origin/pkg/deploy/api"
)

var basic = kubectl.BasicReplicationController{}

type BasicDeploymentConfigController struct{}

func (BasicDeploymentConfigController) ParamNames() []kubectl.GeneratorParam {
return basic.ParamNames()
}

func (BasicDeploymentConfigController) Generate(genericParams map[string]string) (runtime.Object, error) {
obj, err := basic.Generate(genericParams)
if err != nil {
return nil, err
}
switch t := obj.(type) {
case *kapi.ReplicationController:
obj = &deployapi.DeploymentConfig{
ObjectMeta: t.ObjectMeta,
Template: deployapi.DeploymentTemplate{
ControllerTemplate: t.Spec,
},
}
default:
return nil, fmt.Errorf("unrecognized object type: %v", reflect.TypeOf(t))
}
return obj, nil
}
4 changes: 3 additions & 1 deletion test/cmd/basicresources.sh
Expand Up @@ -56,7 +56,9 @@ echo "expose: ok"
oc delete all --all

oc run --image=openshift/hello-openshift test
oc delete rc/test
oc run --image=openshift/hello-openshift --generator=run-controller/v1 test2
oc run --image=openshift/hello-openshift --restart=Never test3
oc delete dc/test rc/test2 pod/test3

oc process -f examples/sample-app/application-template-stibuild.json -l name=mytemplate | oc create -f -
oc delete all -l name=mytemplate
Expand Down

0 comments on commit 91fe6d4

Please sign in to comment.