Skip to content

Commit

Permalink
add OpenShift Apps scheme for DeploymentConfig
Browse files Browse the repository at this point in the history
This commit adds OpenShift's Apps scheme to support
DeploymentConfig.

Prior to this commit, TypeMeta for a DeploymentConfig had to
be hard coded, but now it's derived from the generated scheme
after addition of the Apps scheme.

The code in Transform() method in pkg/spec/deploymentconfig.go is
also refactored to leverage the scheme and be aligned with the
code in pkg/spec/deployment.go

Fixes kedgeproject#349
  • Loading branch information
concaf committed Oct 24, 2017
1 parent 83c6761 commit f4c3808
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
33 changes: 13 additions & 20 deletions pkg/spec/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/ghodss/yaml"
os_deploy_v1 "github.com/openshift/origin/pkg/deploy/apis/apps/v1"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
kapi "k8s.io/kubernetes/pkg/api/v1"
)
Expand Down Expand Up @@ -86,21 +85,7 @@ func (deploymentConfig *DeploymentConfigSpecMod) Transform() ([]runtime.Object,
return nil, nil, errors.Wrap(err, "failed to create Kubernetes objects")
}

// Set appropriate GVK BEFORE adding DeploymentConfig controller
// as OpenShift controllers are not available in the Kubernetes controller / setGVK check
scheme, err := GetScheme()
if err != nil {
return nil, nil, errors.Wrap(err, "unable to get scheme")
}

// Set's the appropriate GVK
for _, runtimeObject := range runtimeObjects {
if err := SetGVK(runtimeObject, scheme); err != nil {
return nil, nil, errors.Wrap(err, "unable to set Group, Version and Kind for generated Kubernetes resources")
}
}

// Create the DeploymentConfig controller!
// Create the DeploymentConfig controller
deploy, err := deploymentConfig.createOpenShiftController()
if err != nil {
return nil, nil, errors.Wrap(err, "failed to create DeploymentConfig controller")
Expand All @@ -118,6 +103,18 @@ func (deploymentConfig *DeploymentConfigSpecMod) Transform() ([]runtime.Object,
return nil, nil, errors.New("No runtime objects created, possibly because not enough input data was passed")
}

scheme, err := GetScheme()
if err != nil {
return nil, nil, errors.Wrap(err, "unable to get scheme")
}

// Set's the appropriate GVK
for _, runtimeObject := range runtimeObjects {
if err := SetGVK(runtimeObject, scheme); err != nil {
return nil, nil, errors.Wrap(err, "unable to set Group, Version and Kind for generated resources")
}
}

return runtimeObjects, extraResources, nil
}

Expand All @@ -131,10 +128,6 @@ func (deploymentConfig *DeploymentConfigSpecMod) createOpenShiftController() (*o
}

return &os_deploy_v1.DeploymentConfig{
TypeMeta: metav1.TypeMeta{
Kind: "DeploymentConfig",
APIVersion: "v1",
},
ObjectMeta: deploymentConfig.ObjectMeta,
Spec: dcSpec,
}, nil
Expand Down
8 changes: 0 additions & 8 deletions pkg/spec/deploymentconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,6 @@ func TestDeploymentConfigSpecMod_CreateOpenShiftController(t *testing.T) {
},
},
deployment: &os_deploy_v1.DeploymentConfig{
TypeMeta: meta_v1.TypeMeta{
Kind: "DeploymentConfig",
APIVersion: "v1",
},
ObjectMeta: meta_v1.ObjectMeta{
Name: "testJob",
},
Expand Down Expand Up @@ -186,10 +182,6 @@ func TestDeploymentConfigSpecMod_CreateOpenShiftController(t *testing.T) {
},
},
deployment: &os_deploy_v1.DeploymentConfig{
TypeMeta: meta_v1.TypeMeta{
Kind: "DeploymentConfig",
APIVersion: "v1",
},
ObjectMeta: meta_v1.ObjectMeta{
Name: "testJob",
},
Expand Down
6 changes: 6 additions & 0 deletions pkg/spec/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/kubernetes/pkg/api"
api_v1 "k8s.io/kubernetes/pkg/api/v1"
//kapi "k8s.io/kubernetes/pkg/api/v1"
os_deploy_v1 "github.com/openshift/origin/pkg/deploy/apis/apps/v1"
os_route_v1 "github.com/openshift/origin/pkg/route/apis/route/v1"
batch_v1 "k8s.io/kubernetes/pkg/apis/batch/v1"
)
Expand Down Expand Up @@ -70,6 +71,11 @@ func GetScheme() (*runtime.Scheme, error) {
// to the v1 scheme, instead we should be able to have different scheme for
// different controllers

// Adding the apps scheme to support DeploymentConfig
if err := os_deploy_v1.AddToScheme(scheme); err != nil {
return nil, errors.Wrap(err, "unable to add 'apps' (OpenShift) to scheme")
}

// Adding the batch scheme to support Jobs
if err := batch_v1.AddToScheme(scheme); err != nil {
return nil, errors.Wrap(err, "unable to add 'batch' to scheme")
Expand Down

0 comments on commit f4c3808

Please sign in to comment.