Skip to content

Commit

Permalink
unified expression about DaemonSet
Browse files Browse the repository at this point in the history
Signed-off-by: 李龙峰 <lilongfeng@inspur.com>
  • Loading branch information
李龙峰 committed Sep 8, 2023
1 parent e825768 commit 4938375
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,23 @@ var (
)

const (
// UpdateAnnotation is the annotation key used in daemonset spec to indicate
// UpdateAnnotation is the annotation key used in DaemonSet spec to indicate
// which update strategy is selected. Currently, "OTA" and "AdvancedRollingUpdate" are supported.
UpdateAnnotation = "apps.openyurt.io/update-strategy"

// OTAUpdate set daemonset to over-the-air update mode.
// OTAUpdate set DaemonSet to over-the-air update mode.
// In daemonPodUpdater controller, we add PodNeedUpgrade condition to pods.
OTAUpdate = "OTA"
// AutoUpdate set daemonset to Auto update mode.
// In this mode, daemonset will keep updating even if there are not-ready nodes.
// AutoUpdate set DaemonSet to Auto update mode.
// In this mode, DaemonSet will keep updating even if there are not-ready nodes.
// For more details, see https://github.com/openyurtio/openyurt/pull/921.
AutoUpdate = "Auto"
AdvancedRollingUpdate = "AdvancedRollingUpdate"

// PodNeedUpgrade indicates whether the pod is able to upgrade.
PodNeedUpgrade corev1.PodConditionType = "PodNeedUpgrade"

// MaxUnavailableAnnotation is the annotation key added to daemonset to indicate
// MaxUnavailableAnnotation is the annotation key added to DaemonSet to indicate
// the max unavailable pods number. It's used with "apps.openyurt.io/update-strategy=AdvancedRollingUpdate".
// If this annotation is not explicitly stated, it will be set to the default value 1.
MaxUnavailableAnnotation = "apps.openyurt.io/max-unavailable"
Expand Down Expand Up @@ -176,7 +176,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return nil
}

// daemonsetUpdate filter events: daemonset update with customized annotation
// daemonsetUpdate filter events: DaemonSet update with customized annotation
func daemonsetUpdate(evt event.UpdateEvent) bool {
if _, ok := evt.ObjectOld.(*appsv1.DaemonSet); !ok {
return false
Expand All @@ -185,7 +185,7 @@ func daemonsetUpdate(evt event.UpdateEvent) bool {
oldDS := evt.ObjectOld.(*appsv1.DaemonSet)
newDS := evt.ObjectNew.(*appsv1.DaemonSet)

// Only handle daemonset meets prerequisites
// Only handle DaemonSet meets prerequisites
if !checkPrerequisites(newDS) {
return false
}
Expand All @@ -194,7 +194,7 @@ func daemonsetUpdate(evt event.UpdateEvent) bool {
return false
}

klog.V(5).Infof("Got daemonset udpate event: %v", newDS.Name)
klog.V(5).Infof("Got DaemonSet update event: %v", newDS.Name)
return true
}

Expand Down Expand Up @@ -225,16 +225,16 @@ func (r *ReconcileDaemonpodupdater) Reconcile(_ context.Context, request reconci
return reconcile.Result{}, nil
}

// Only process daemonset that meets expectations
// Otherwise, wait native daemonset controller reconciling
// Only process DaemonSet that meets expectations
// Otherwise, wait native DaemonSet controller reconciling
if !r.expectations.SatisfiedExpectations(request.NamespacedName.String()) {
return reconcile.Result{}, nil
}

// Recheck required annotation
v, ok := instance.Annotations[UpdateAnnotation]
if !ok {
klog.V(4).Infof("won't sync daemonset %q without annotation 'apps.openyurt.io/update-strategy'",
klog.V(4).Infof("won't sync DaemonSet %q without annotation 'apps.openyurt.io/update-strategy'",
request.NamespacedName)
return reconcile.Result{}, nil
}
Expand Down Expand Up @@ -266,7 +266,7 @@ func (r *ReconcileDaemonpodupdater) deletePod(evt event.DeleteEvent, _ workqueue
return
}

klog.V(5).Infof("Daemonset pod %s deleted.", pod.Name)
klog.V(5).Infof("DaemonSet pod %s deleted.", pod.Name)

controllerRef := metav1.GetControllerOf(pod)
if controllerRef == nil {
Expand All @@ -278,7 +278,7 @@ func (r *ReconcileDaemonpodupdater) deletePod(evt event.DeleteEvent, _ workqueue
return
}

// Only care daemonset meets prerequisites
// Only care DaemonSet meets prerequisites
if !checkPrerequisites(ds) {
return
}
Expand All @@ -291,8 +291,8 @@ func (r *ReconcileDaemonpodupdater) deletePod(evt event.DeleteEvent, _ workqueue
r.expectations.DeletionObserved(dsKey)
}

// otaUpdate compare every pod to its owner daemonset to check if pod is updatable
// If pod is in line with the latest daemonset spec, set pod condition "PodNeedUpgrade" to "false"
// otaUpdate compare every pod to its owner DaemonSet to check if pod is updatable
// If pod is in line with the latest DaemonSet spec, set pod condition "PodNeedUpgrade" to "false"
// while not, set pod condition "PodNeedUpgrade" to "true"
func (r *ReconcileDaemonpodupdater) otaUpdate(ds *appsv1.DaemonSet) error {
pods, err := GetDaemonsetPods(r.Client, ds)
Expand Down Expand Up @@ -328,7 +328,7 @@ func (r *ReconcileDaemonpodupdater) advancedRollingUpdate(ds *appsv1.DaemonSet)

for nodeName, pods := range nodeToDaemonPods {
// Check if node is ready, ignore not-ready node
// this is a significant difference from the native daemonset controller
// this is a significant difference from the native DaemonSet controller
ready, err := NodeReadyByName(r.Client, nodeName)
if err != nil {
return fmt.Errorf("couldn't check node %q ready status, %v", nodeName, err)
Expand Down

0 comments on commit 4938375

Please sign in to comment.