Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #102 from rebuy-de/fix-annotator
Browse files Browse the repository at this point in the history
fix annotator
  • Loading branch information
svenwltr authored May 30, 2018
2 parents 8d154ff + 3106fb7 commit fb5471d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pkg/interceptors/annotater/interceptor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package annotater

import (
"fmt"

"github.com/benbjohnson/clock"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -32,14 +34,19 @@ func (i *Interceptor) PostManifestRender(obj runtime.Object) (runtime.Object, er

now := i.clock.Now()

accessor.SetAnnotations(map[string]string{
"rebuy.com/kubernetes-deployment.deployment-date": now.String(),
"rebuy.com/kubernetes-deployment.commit-sha": i.branch.SHA,
"rebuy.com/kubernetes-deployment.commit-date": i.branch.Date.String(),
"rebuy.com/kubernetes-deployment.commit-author": i.branch.Author,
"rebuy.com/kubernetes-deployment.commit-message": i.branch.Message,
"rebuy.com/kubernetes-deployment.commit-location": i.branch.Location.String(),
})
annotations := accessor.GetAnnotations()
if annotations == nil {
annotations = map[string]string{}
}

annotations["rebuy.com/kubernetes-deployment.deployment-date"] = fmt.Sprint(now)
annotations["rebuy.com/kubernetes-deployment.commit-sha"] = i.branch.SHA
annotations["rebuy.com/kubernetes-deployment.commit-date"] = fmt.Sprint(i.branch.Date)
annotations["rebuy.com/kubernetes-deployment.commit-author"] = i.branch.Author
annotations["rebuy.com/kubernetes-deployment.commit-message"] = i.branch.Message
annotations["rebuy.com/kubernetes-deployment.commit-location"] = i.branch.Location.String()

accessor.SetAnnotations(annotations)

return obj, nil
}
11 changes: 11 additions & 0 deletions pkg/interceptors/annotater/interceptors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
apps "k8s.io/api/apps/v1beta1"
core "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/rebuy-de/kubernetes-deployment/pkg/gh"
Expand Down Expand Up @@ -45,6 +46,16 @@ func TestModify(t *testing.T) {
name: "service",
obj: &core.Service{},
},
{
name: "pvc",
obj: &core.PersistentVolumeClaim{
ObjectMeta: meta.ObjectMeta{
Annotations: map[string]string{
"volume.beta.kubernetes.io/storage-class": "aws-ebs-gp2",
},
},
},
},
}

mockClock := clock.NewMock()
Expand Down
18 changes: 18 additions & 0 deletions pkg/interceptors/annotater/test-fixtures/pvc-golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"metadata": {
"creationTimestamp": null,
"annotations": {
"rebuy.com/kubernetes-deployment.commit-author": "bim baz",
"rebuy.com/kubernetes-deployment.commit-date": "2009-02-13 23:31:30 +0000 UTC",
"rebuy.com/kubernetes-deployment.commit-location": "github.com/rebuy-de/example-silo/deployment/k8s@master",
"rebuy.com/kubernetes-deployment.commit-message": "fancy feature",
"rebuy.com/kubernetes-deployment.commit-sha": "1234567890abcdef",
"rebuy.com/kubernetes-deployment.deployment-date": "2009-02-13 23:31:30 +0000 UTC",
"volume.beta.kubernetes.io/storage-class": "aws-ebs-gp2"
}
},
"spec": {
"resources": {}
},
"status": {}
}

0 comments on commit fb5471d

Please sign in to comment.