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 #454 from piyush1594/add_field_appversion
Browse files Browse the repository at this point in the history
This will add a new key appversion
  • Loading branch information
kadel authored Nov 27, 2017
2 parents 9ce3f49 + b8a4279 commit 272f1a6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
6 changes: 6 additions & 0 deletions pkg/spec/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func (deployment *DeploymentSpecMod) Fix() error {

deployment.ControllerFields.ObjectMeta.Labels = addKeyValueToMap(appLabelKey, deployment.ControllerFields.Name, deployment.ControllerFields.ObjectMeta.Labels)

if deployment.ControllerFields.Appversion != "" {
deployment.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap(appVersion, deployment.ControllerFields.Appversion, deployment.ControllerFields.ObjectMeta.Annotations)
}

return nil
}

Expand Down Expand Up @@ -134,6 +138,8 @@ func (deployment *DeploymentSpecMod) createKubernetesController() (*ext_v1beta1.
// TODO: merge with already existing labels and avoid duplication
deploymentSpec.Template.ObjectMeta.Labels = deployment.Labels

deploymentSpec.Template.ObjectMeta.Annotations = deployment.Annotations

return &ext_v1beta1.Deployment{
ObjectMeta: deployment.ObjectMeta,
Spec: deploymentSpec,
Expand Down
6 changes: 6 additions & 0 deletions pkg/spec/deploymentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func (deploymentConfig *DeploymentConfigSpecMod) fixDeploymentConfig() {
deploymentConfig.ControllerFields.Name,
deploymentConfig.ControllerFields.ObjectMeta.Labels)

if deploymentConfig.ControllerFields.Appversion != "" {
deploymentConfig.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap(appVersion,
deploymentConfig.ControllerFields.Appversion,
deploymentConfig.ControllerFields.ObjectMeta.Annotations)
}

// If the replicas are not specified at all, we need to set the value as 1
if deploymentConfig.Replicas == nil {
deploymentConfig.Replicas = getInt32Addr(1)
Expand Down
6 changes: 5 additions & 1 deletion pkg/spec/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ func (job *JobSpecMod) Fix() error {

job.ControllerFields.ObjectMeta.Labels = addKeyValueToMap(appLabelKey, job.ControllerFields.Name, job.ControllerFields.ObjectMeta.Labels)

if job.ControllerFields.Appversion != "" {
job.ControllerFields.ObjectMeta.Annotations = addKeyValueToMap(appVersion, job.ControllerFields.Appversion, job.ControllerFields.ObjectMeta.Annotations)
}

// if RestartPolicy is not set by user default it to 'OnFailure'
if job.RestartPolicy == "" {
job.RestartPolicy = api_v1.RestartPolicyOnFailure
}

return nil
}

Expand Down Expand Up @@ -136,7 +141,6 @@ func (job *JobSpecMod) Validate() error {
if job.RestartPolicy == api_v1.RestartPolicyAlways {
return fmt.Errorf("the Job %q is invalid: restartPolicy: unsupported value: \"Always\": supported values: OnFailure, Never", job.Name)
}

return nil
}

Expand Down
19 changes: 19 additions & 0 deletions pkg/spec/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

"github.com/davecgh/go-spew/spew"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
Expand All @@ -44,6 +45,7 @@ import (
// allLabelKey is the key that Kedge injects in every Kubernetes resource that
// it generates as an ObjectMeta label
const appLabelKey = "app"
const appVersion = "appversion"

// Fix

Expand Down Expand Up @@ -585,6 +587,23 @@ func (app *ControllerFields) CreateK8sObjects() ([]runtime.Object, []string, err
objects = append(objects, configMap...)
log.Debugf("app: %s, configMap: %s\n", app.Name, spew.Sprint(configMap))

//Adding annotations to all the resources
//Objects are runtimeobjects, so accessing them using meta library
if app.Appversion != "" {
accessor := meta.NewAccessor()
for _, object := range objects {
annotations, err := accessor.Annotations(object)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot get annotations")
}
annotations = addKeyValueToMap(appVersion, app.Appversion, annotations)
err = accessor.SetAnnotations(object, annotations)
if err != nil {
return nil, nil, errors.Wrap(err, "cannot set annotations")
}
}
}

return objects, app.IncludeResources, nil
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/spec/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ type BuildConfigSpecMod struct {

// ControllerFields are the common fields in every controller Kedge supports
type ControllerFields struct {
// Field to specify the version of application
// +optional
Appversion string `json:"appversion,omitempty"`

Controller string `json:"controller,omitempty"`
// List of volume that should be mounted on the pod.
// ref: io.kedge.VolumeClaim
Expand Down
10 changes: 4 additions & 6 deletions pkg/spec/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import (
"encoding/json"

log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
//"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api"
api_v1 "k8s.io/kubernetes/pkg/api/v1"
//kapi "k8s.io/kubernetes/pkg/api/v1"
build_v1 "github.com/openshift/origin/pkg/build/apis/build/v1"
os_deploy_v1 "github.com/openshift/origin/pkg/deploy/apis/apps/v1"
image_v1 "github.com/openshift/origin/pkg/image/apis/image/v1"
os_route_v1 "github.com/openshift/origin/pkg/route/apis/route/v1"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/kubernetes/pkg/api"
api_v1 "k8s.io/kubernetes/pkg/api/v1"
batch_v1 "k8s.io/kubernetes/pkg/apis/batch/v1"
)

Expand Down

0 comments on commit 272f1a6

Please sign in to comment.