Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

merge DeploymentSpec with PodSpec on the top level #36

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ServicePortMod struct {
api_v1.ServicePort `json:",inline"`
// Endpoint allows specifying an ingress resource in the format
// `<Host>/<Path>`
Endpoint string `json:"endpoint"`
Endpoint string `json:"endpoint"`
}

type ServiceSpecMod struct {
Expand All @@ -30,6 +30,8 @@ type IngressSpecMod struct {
}

type Container struct {
// one common definitions for livenessProbe and readinessProbe
// this allows to have only one place to define both probes (if they are the same)
Health *api_v1.Probe `json:"health,omitempty"`
api_v1.Container `json:",inline"`
}
Expand All @@ -41,7 +43,11 @@ type App struct {
PersistentVolumes []PersistentVolume `json:"persistentVolumes,omitempty"`
ConfigData map[string]string `json:"configData,omitempty"`
Services []ServiceSpecMod `json:"services,omitempty"`
Containers []Container `json:"containers,omitempty"`
Ingress []IngressSpecMod `json:"ingress,omitempty"`
api_v1.PodSpec `json:",inline"`

// overwrite containers from PodSpec
Containers []Container `json:"containers,omitempty"`

api_v1.PodSpec `json:",inline"`
ext_v1beta1.DeploymentSpec `json:",inline"`
}
48 changes: 33 additions & 15 deletions pkg/transform/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

_ "k8s.io/client-go/pkg/api/install"
_ "k8s.io/client-go/pkg/apis/extensions/install"
"reflect"
)

func getLabels(app *spec.App) map[string]string {
Expand Down Expand Up @@ -116,25 +117,39 @@ func createServices(app *spec.App) ([]runtime.Object, error) {
return svcs, nil
}

func createDeployment(app *spec.App) *ext_v1beta1.Deployment {
// bare minimum deployment
return &ext_v1beta1.Deployment{
func createDeployment(app *spec.App) (*ext_v1beta1.Deployment, error) {

// We are merging whole DeploymentSpec with PodSpec.
// This means that someone could specify containers in template.spec and also in top level PodSpec.
// This stupid check is supposed to make sure that only one of them set.
// TODO: merge DeploymentSpec.Template.Spec and top level PodSpec
if !(reflect.DeepEqual(app.DeploymentSpec.Template.Spec, api_v1.PodSpec{}) || reflect.DeepEqual(app.PodSpec, api_v1.PodSpec{})) {
return nil, fmt.Errorf("Pod can't be specfied in two places. Use top level PodSpec or template.spec (DeploymentSpec.Template.Spec) not both")
}

deploymentSpec := app.DeploymentSpec

// top level PodSpec is not empty, use it for deployment template
// we already know that if app.PodSpec is not empty app.DeploymentSpec.Template.Spec is empty
if !reflect.DeepEqual(app.PodSpec, api_v1.PodSpec{}) {
deploymentSpec.Template.Spec = app.PodSpec
}

// TODO: check if this wasn't set by user, in that case we shouldn't ovewrite it
deploymentSpec.Template.ObjectMeta.Name = app.Name

// TODO: merge with already existing labels and avoid duplication
deploymentSpec.Template.ObjectMeta.Labels = app.Labels

deployment := ext_v1beta1.Deployment{
ObjectMeta: api_v1.ObjectMeta{
Name: app.Name,
Labels: app.Labels,
},
Spec: ext_v1beta1.DeploymentSpec{
Replicas: app.Replicas,
Template: api_v1.PodTemplateSpec{
ObjectMeta: api_v1.ObjectMeta{
Name: app.Name,
Labels: app.Labels,
},
// get pod spec out of the original info
Spec: api_v1.PodSpec(app.PodSpec),
},
},
Spec: deploymentSpec,
}

return &deployment, nil
}

// search through all the persistent volumes defined in the root level
Expand Down Expand Up @@ -334,7 +349,10 @@ func CreateK8sObjects(app *spec.App) ([]runtime.Object, error) {

}

deployment := createDeployment(app)
deployment, err := createDeployment(app)
if err != nil {
return nil, errors.Wrapf(err, "app %q", app.Name)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

objects = append(objects, deployment)
log.Debugf("app: %s, deployment: %s\n", app.Name, spew.Sprint(deployment))

Expand Down