Skip to content

Commit

Permalink
Merge pull request kubernetes#5842 from simon3z/rc-annotation
Browse files Browse the repository at this point in the history
Replica Controller Name Annotation in Pods
  • Loading branch information
bgrant0607 committed Apr 23, 2015
2 parents e8b28c5 + 253ce4b commit 73322af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/controller/replication_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package controller

import (
"encoding/json"
"fmt"
"sort"
"sync"
Expand Down Expand Up @@ -62,6 +63,7 @@ type RealPodControl struct {

// Time period of main replication controller sync loop
const DefaultSyncPeriod = 5 * time.Second
const CreatedByAnnotation = "kubernetes.io/created-by"

func (r RealPodControl) createReplica(namespace string, controller api.ReplicationController) {
desiredLabels := make(labels.Set)
Expand All @@ -73,6 +75,20 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati
desiredAnnotations[k] = v
}

createdByRef, err := api.GetReference(&controller)
if err != nil {
util.HandleError(fmt.Errorf("unable to get controller reference: %v", err))
return
}

createdByRefJson, err := json.Marshal(createdByRef)
if err != nil {
util.HandleError(fmt.Errorf("unable to serialize controller reference: %v", err))
return
}

desiredAnnotations[CreatedByAnnotation] = string(createdByRefJson)

// use the dash (if the name isn't too long) to make the pod name a bit prettier
prefix := fmt.Sprintf("%s-", controller.Name)
if ok, _ := validation.ValidatePodName(prefix, true); !ok {
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/replication_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type FakePodControl struct {
lock sync.Mutex
}

func init() {
api.ForTesting_ReferencesAllowBlankSelfLinks = true
}

func (f *FakePodControl) createReplica(namespace string, spec api.ReplicationController) {
f.lock.Lock()
defer f.lock.Unlock()
Expand Down

0 comments on commit 73322af

Please sign in to comment.