mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Merge pull request #5842 from simon3z/rc-annotation
Replica Controller Name Annotation in Pods
This commit is contained in:
		@@ -17,6 +17,7 @@ limitations under the License.
 | 
				
			|||||||
package controller
 | 
					package controller
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import (
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/json"
 | 
				
			||||||
	"fmt"
 | 
						"fmt"
 | 
				
			||||||
	"sort"
 | 
						"sort"
 | 
				
			||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
@@ -62,6 +63,7 @@ type RealPodControl struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Time period of main replication controller sync loop
 | 
					// Time period of main replication controller sync loop
 | 
				
			||||||
const DefaultSyncPeriod = 5 * time.Second
 | 
					const DefaultSyncPeriod = 5 * time.Second
 | 
				
			||||||
 | 
					const CreatedByAnnotation = "kubernetes.io/created-by"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (r RealPodControl) createReplica(namespace string, controller api.ReplicationController) {
 | 
					func (r RealPodControl) createReplica(namespace string, controller api.ReplicationController) {
 | 
				
			||||||
	desiredLabels := make(labels.Set)
 | 
						desiredLabels := make(labels.Set)
 | 
				
			||||||
@@ -73,6 +75,20 @@ func (r RealPodControl) createReplica(namespace string, controller api.Replicati
 | 
				
			|||||||
		desiredAnnotations[k] = v
 | 
							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
 | 
						// use the dash (if the name isn't too long) to make the pod name a bit prettier
 | 
				
			||||||
	prefix := fmt.Sprintf("%s-", controller.Name)
 | 
						prefix := fmt.Sprintf("%s-", controller.Name)
 | 
				
			||||||
	if ok, _ := validation.ValidatePodName(prefix, true); !ok {
 | 
						if ok, _ := validation.ValidatePodName(prefix, true); !ok {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,6 +43,10 @@ type FakePodControl struct {
 | 
				
			|||||||
	lock           sync.Mutex
 | 
						lock           sync.Mutex
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func init() {
 | 
				
			||||||
 | 
						api.ForTesting_ReferencesAllowBlankSelfLinks = true
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (f *FakePodControl) createReplica(namespace string, spec api.ReplicationController) {
 | 
					func (f *FakePodControl) createReplica(namespace string, spec api.ReplicationController) {
 | 
				
			||||||
	f.lock.Lock()
 | 
						f.lock.Lock()
 | 
				
			||||||
	defer f.lock.Unlock()
 | 
						defer f.lock.Unlock()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user