mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #73812 from Adirio/patch-2
ControllerRef creation through factory function
This commit is contained in:
commit
2fd8f8aec1
@ -70,21 +70,10 @@ func NewControllerRevision(parent metav1.Object,
|
|||||||
for k, v := range templateLabels {
|
for k, v := range templateLabels {
|
||||||
labelMap[k] = v
|
labelMap[k] = v
|
||||||
}
|
}
|
||||||
blockOwnerDeletion := true
|
|
||||||
isController := true
|
|
||||||
cr := &apps.ControllerRevision{
|
cr := &apps.ControllerRevision{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Labels: labelMap,
|
Labels: labelMap,
|
||||||
OwnerReferences: []metav1.OwnerReference{
|
OwnerReferences: []metav1.OwnerReference{*metav1.NewControllerRef(parent, parentKind)},
|
||||||
{
|
|
||||||
APIVersion: parentKind.GroupVersion().String(),
|
|
||||||
Kind: parentKind.Kind,
|
|
||||||
Name: parent.GetName(),
|
|
||||||
UID: parent.GetUID(),
|
|
||||||
BlockOwnerDeletion: &blockOwnerDeletion,
|
|
||||||
Controller: &isController,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Data: data,
|
Data: data,
|
||||||
Revision: revision,
|
Revision: revision,
|
||||||
@ -417,8 +406,6 @@ func (fh *fakeHistory) UpdateControllerRevision(revision *apps.ControllerRevisio
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fh *fakeHistory) AdoptControllerRevision(parent metav1.Object, parentKind schema.GroupVersionKind, revision *apps.ControllerRevision) (*apps.ControllerRevision, error) {
|
func (fh *fakeHistory) AdoptControllerRevision(parent metav1.Object, parentKind schema.GroupVersionKind, revision *apps.ControllerRevision) (*apps.ControllerRevision, error) {
|
||||||
blockOwnerDeletion := true
|
|
||||||
isController := true
|
|
||||||
if owner := metav1.GetControllerOf(revision); owner != nil {
|
if owner := metav1.GetControllerOf(revision); owner != nil {
|
||||||
return nil, fmt.Errorf("attempt to adopt revision owned by %v", owner)
|
return nil, fmt.Errorf("attempt to adopt revision owned by %v", owner)
|
||||||
}
|
}
|
||||||
@ -434,16 +421,8 @@ func (fh *fakeHistory) AdoptControllerRevision(parent metav1.Object, parentKind
|
|||||||
return nil, errors.NewNotFound(apps.Resource("controllerrevisions"), revision.Name)
|
return nil, errors.NewNotFound(apps.Resource("controllerrevisions"), revision.Name)
|
||||||
}
|
}
|
||||||
clone := revision.DeepCopy()
|
clone := revision.DeepCopy()
|
||||||
clone.OwnerReferences = append(clone.OwnerReferences, metav1.OwnerReference{
|
clone.OwnerReferences = append(clone.OwnerReferences, *metav1.NewControllerRef(parent, parentKind))
|
||||||
APIVersion: parentKind.GroupVersion().String(),
|
|
||||||
Kind: parentKind.Kind,
|
|
||||||
Name: parent.GetName(),
|
|
||||||
UID: parent.GetUID(),
|
|
||||||
BlockOwnerDeletion: &blockOwnerDeletion,
|
|
||||||
Controller: &isController,
|
|
||||||
})
|
|
||||||
return clone, fh.indexer.Update(clone)
|
return clone, fh.indexer.Update(clone)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fh *fakeHistory) ReleaseControllerRevision(parent metav1.Object, revision *apps.ControllerRevision) (*apps.ControllerRevision, error) {
|
func (fh *fakeHistory) ReleaseControllerRevision(parent metav1.Object, revision *apps.ControllerRevision) (*apps.ControllerRevision, error) {
|
||||||
|
@ -484,16 +484,7 @@ func (rsc *ReplicaSetController) manageReplicas(filteredPods []*v1.Pod, rs *apps
|
|||||||
// after one of its pods fails. Conveniently, this also prevents the
|
// after one of its pods fails. Conveniently, this also prevents the
|
||||||
// event spam that those failures would generate.
|
// event spam that those failures would generate.
|
||||||
successfulCreations, err := slowStartBatch(diff, controller.SlowStartInitialBatchSize, func() error {
|
successfulCreations, err := slowStartBatch(diff, controller.SlowStartInitialBatchSize, func() error {
|
||||||
boolPtr := func(b bool) *bool { return &b }
|
err := rsc.podControl.CreatePodsWithControllerRef(rs.Namespace, &rs.Spec.Template, rs, metav1.NewControllerRef(rs, rsc.GroupVersionKind))
|
||||||
controllerRef := &metav1.OwnerReference{
|
|
||||||
APIVersion: rsc.GroupVersion().String(),
|
|
||||||
Kind: rsc.Kind,
|
|
||||||
Name: rs.Name,
|
|
||||||
UID: rs.UID,
|
|
||||||
BlockOwnerDeletion: boolPtr(true),
|
|
||||||
Controller: boolPtr(true),
|
|
||||||
}
|
|
||||||
err := rsc.podControl.CreatePodsWithControllerRef(rs.Namespace, &rs.Spec.Template, rs, controllerRef)
|
|
||||||
if err != nil && errors.IsTimeout(err) {
|
if err != nil && errors.IsTimeout(err) {
|
||||||
// Pod is created but its initialization has timed out.
|
// Pod is created but its initialization has timed out.
|
||||||
// If the initialization is successful eventually, the
|
// If the initialization is successful eventually, the
|
||||||
|
Loading…
Reference in New Issue
Block a user