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

Commit

Permalink
Merge pull request #124 from containscafeine/fix_empty_deployment
Browse files Browse the repository at this point in the history
error out if invalid input data is passed
  • Loading branch information
surajssd authored Jul 6, 2017
2 parents f9d575b + febc669 commit af022b2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/transform/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,16 @@ func createServices(app *spec.App) ([]runtime.Object, error) {
return svcs, nil
}

// Creates a Deployment Kubernetes resource. The returned Deployment resource
// will be nil if it could not be generated due to insufficient input data.
func createDeployment(app *spec.App) (*ext_v1beta1.Deployment, error) {

// We need to error out if both, app.PodSpec and app.DeploymentSpec are empty
if reflect.DeepEqual(app.PodSpec, api_v1.PodSpec{}) && reflect.DeepEqual(app.DeploymentSpec, ext_v1beta1.DeploymentSpec{}) {
log.Debug("Both, app.PodSpec and app.DeploymentSpec are empty, not enough data to create a deployment.")
return nil, nil
}

// 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.
Expand Down Expand Up @@ -413,9 +421,13 @@ func CreateK8sObjects(app *spec.App) ([]runtime.Object, error) {
if err != nil {
return nil, errors.Wrapf(err, "app %q", app.Name)
}
objects = append(objects, deployment)
log.Debugf("app: %s, deployment: %s\n", app.Name, spew.Sprint(deployment))

// deployment will be nil if no deployment is generated and no error occurs,
// so we only need to append this when a legit deployment resource is returned
if deployment != nil {
objects = append(objects, deployment)
log.Debugf("app: %s, deployment: %s\n", app.Name, spew.Sprint(deployment))
}
objects = append(objects, configMap...)
log.Debugf("app: %s, configMap: %s\n", app.Name, spew.Sprint(configMap))

Expand All @@ -438,6 +450,10 @@ func Transform(app *spec.App) ([]runtime.Object, error) {
return nil, errors.Wrap(err, "failed to create Kubernetes objects")
}

if len(runtimeObjects) == 0 {
return nil, errors.New("No runtime objects created, possibly because not enough input data was passed")
}

for _, runtimeObject := range runtimeObjects {

gvk, isUnversioned, err := api.Scheme.ObjectKind(runtimeObject)
Expand Down

0 comments on commit af022b2

Please sign in to comment.