Skip to content

Commit

Permalink
render: Log when a MC is deleted, comment out deletion code
Browse files Browse the repository at this point in the history
  • Loading branch information
cgwalters committed Jan 21, 2019
1 parent fe1c20f commit c8a7ce4
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions pkg/controller/render/render_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/wait"
clientset "k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -232,12 +231,13 @@ func (ctrl *Controller) deleteMachineConfig(obj interface{}) {
}
}

glog.Infof("MachineConfig %s deleted", mc.Name)

if controllerRef := metav1.GetControllerOf(mc); controllerRef != nil {
pool := ctrl.resolveControllerRef(controllerRef)
if pool == nil {
return
}
glog.V(4).Infof("MachineConfig %s deleted", mc.Name)
ctrl.enqueueMachineConfigPool(pool)
return
}
Expand All @@ -248,7 +248,6 @@ func (ctrl *Controller) deleteMachineConfig(obj interface{}) {
return
}

glog.V(4).Infof("MachineConfig %s deleted", mc.Name)
for _, p := range pools {
ctrl.enqueueMachineConfigPool(p)
}
Expand Down Expand Up @@ -461,35 +460,36 @@ func (ctrl *Controller) syncGeneratedMachineConfig(pool *mcfgv1.MachineConfigPoo
return err
}

gmcs, err := ctrl.mcLister.List(labels.Everything())
if err != nil {
return err
}
for _, gmc := range gmcs {
if gmc.Name == generated.Name {
continue
}

deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, pool.UID, gmc.UID)
_, err = ctrl.client.MachineconfigurationV1().MachineConfigs().Patch(gmc.Name, types.JSONPatchType, []byte(deleteOwnerRefPatch))
if err != nil {
if errors.IsNotFound(err) {
// If the machineconfig no longer exists, ignore it.
continue
}
if errors.IsInvalid(err) {
// Invalid error will be returned in two cases: 1. the machineconfig
// has no owner reference, 2. the uid of the machineconfig doesn't
// match.
// In both cases, the error can be ignored.
continue
}
// Let's not make it fatal for now
glog.Warningf("Failed to delete ownerReference from %s: %v", gmc.Name, err)
} else {
glog.Infof("Queued for GC: %s", gmc.Name)
}
}
// this code is known broken
// gmcs, err := ctrl.mcLister.List(labels.Everything())
// if err != nil {
// return err
// }
// for _, gmc := range gmcs {
// if gmc.Name == generated.Name {
// continue
// }

// deleteOwnerRefPatch := fmt.Sprintf(`{"metadata":{"ownerReferences":[{"$patch":"delete","uid":"%s"}],"uid":"%s"}}`, pool.UID, gmc.UID)
// _, err = ctrl.client.MachineconfigurationV1().MachineConfigs().Patch(gmc.Name, types.JSONPatchType, []byte(deleteOwnerRefPatch))
// if err != nil {
// if errors.IsNotFound(err) {
// // If the machineconfig no longer exists, ignore it.
// continue
// }
// if errors.IsInvalid(err) {
// // Invalid error will be returned in two cases: 1. the machineconfig
// // has no owner reference, 2. the uid of the machineconfig doesn't
// // match.
// // In both cases, the error can be ignored.
// continue
// }
// // Let's not make it fatal for now
// glog.Warningf("Failed to delete ownerReference from %s: %v", gmc.Name, err)
// } else {
// glog.Infof("Queued for GC: %s", gmc.Name)
// }
// }

return nil
}
Expand Down

0 comments on commit c8a7ce4

Please sign in to comment.