diff --git a/pkg/control/sidecarcontrol/sidecarset_control.go b/pkg/control/sidecarcontrol/sidecarset_control.go index ca56c63de5..394571894f 100644 --- a/pkg/control/sidecarcontrol/sidecarset_control.go +++ b/pkg/control/sidecarcontrol/sidecarset_control.go @@ -101,7 +101,7 @@ func (c *commonControl) UpdatePodAnnotationsInUpgrade(changedContainers []string // if it is changed, indicates the update is complete. // format: sidecarset.name -> appsv1alpha1.InPlaceUpdateState sidecarUpdateStates := make(map[string]*pub.InPlaceUpdateState) - if stateStr, _ := pod.Annotations[SidecarsetInplaceUpdateStateKey]; len(stateStr) > 0 { + if stateStr := pod.Annotations[SidecarsetInplaceUpdateStateKey]; len(stateStr) > 0 { if err := json.Unmarshal([]byte(stateStr), &sidecarUpdateStates); err != nil { klog.Errorf("parse pod(%s/%s) annotations[%s] value(%s) failed: %s", pod.Namespace, pod.Name, SidecarsetInplaceUpdateStateKey, stateStr, err.Error()) @@ -136,7 +136,6 @@ func (c *commonControl) UpdatePodAnnotationsInUpgrade(changedContainers []string sidecarUpdateStates[sidecarSet.Name] = inPlaceUpdateState by, _ := json.Marshal(sidecarUpdateStates) pod.Annotations[SidecarsetInplaceUpdateStateKey] = string(by) - return } // only check sidecar container is consistent diff --git a/pkg/controller/advancedcronjob/advancedcronjob_controller_test.go b/pkg/controller/advancedcronjob/advancedcronjob_controller_test.go index e4fe1310cb..ec68d319eb 100644 --- a/pkg/controller/advancedcronjob/advancedcronjob_controller_test.go +++ b/pkg/controller/advancedcronjob/advancedcronjob_controller_test.go @@ -200,11 +200,9 @@ func createNode(nodeName string) *v1.Node { } func createJob(jobName string, template appsv1alpha1.CronJobTemplate) *appsv1alpha1.AdvancedCronJob { - var historyLimit int32 - historyLimit = 3 + var historyLimit int32 = 3 - var paused bool - paused = false + paused := false job1 := &appsv1alpha1.AdvancedCronJob{ ObjectMeta: metav1.ObjectMeta{ Name: jobName, diff --git a/pkg/controller/broadcastjob/broadcastjob_controller.go b/pkg/controller/broadcastjob/broadcastjob_controller.go index 3ac4c0b4ff..df0047c7d3 100644 --- a/pkg/controller/broadcastjob/broadcastjob_controller.go +++ b/pkg/controller/broadcastjob/broadcastjob_controller.go @@ -123,10 +123,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { } // Watch for changes to Node - if err = c.Watch(&source.Kind{Type: &corev1.Node{}}, &enqueueBroadcastJobForNode{reader: mgr.GetCache()}); err != nil { - return err - } - return nil + return c.Watch(&source.Kind{Type: &corev1.Node{}}, &enqueueBroadcastJobForNode{reader: mgr.GetCache()}) } var _ reconcile.Reconciler = &ReconcileBroadcastJob{} @@ -178,7 +175,8 @@ func (r *ReconcileBroadcastJob) Reconcile(_ context.Context, request reconcile.R addLabelToPodTemplate(job) if IsJobFinished(job) { - if isPast, leftTime := pastTTLDeadline(job); isPast { + isPast, leftTime := pastTTLDeadline(job) + if isPast { klog.Infof("deleting the job %s", job.Name) err = r.Delete(context.TODO(), job) if err != nil { @@ -245,9 +243,8 @@ func (r *ReconcileBroadcastJob) Reconcile(_ context.Context, request reconcile.R failed := int32(len(failedPods)) succeeded := int32(len(succeededPods)) - var desired int32 desiredNodes, restNodesToRunPod, podsToDelete := getNodesToRunPod(nodes, job, existingNodeToPodMap) - desired = int32(len(desiredNodes)) + desired := int32(len(desiredNodes)) klog.Infof("%s/%s has %d/%d nodes remaining to schedule pods", job.Namespace, job.Name, len(restNodesToRunPod), desired) klog.Infof("Before broadcastjob reconcile %s/%s, desired=%d, active=%d, failed=%d", job.Namespace, job.Name, desired, active, failed) job.Status.Active = active @@ -302,7 +299,7 @@ func (r *ReconcileBroadcastJob) Reconcile(_ context.Context, request reconcile.R } else { // Job is still active if len(podsToDelete) > 0 { - //should we remove the pods without nodes associated, the podgc controller will do this if enabled + // should we remove the pods without nodes associated, the podgc controller will do this if enabled failed, active, err = r.deleteJobPods(job, podsToDelete, failed, active) if err != nil { klog.Errorf("failed to deleteJobPods for job %s,", job.Name) @@ -391,13 +388,11 @@ func (r *ReconcileBroadcastJob) reconcilePods(job *appsv1alpha1.BroadcastJob, restNodesToRunPod []*corev1.Node, active, desired int32) (int32, error) { // max concurrent running pods - var parallelism int32 - var err error parallelismInt, err := intstr.GetValueFromIntOrPercent(intstr.ValueOrDefault(job.Spec.Parallelism, intstr.FromInt(1<<31-1)), int(desired), true) if err != nil { return active, err } - parallelism = int32(parallelismInt) + parallelism := int32(parallelismInt) // The rest pods to run rest := int32(len(restNodesToRunPod)) @@ -405,7 +400,7 @@ func (r *ReconcileBroadcastJob) reconcilePods(job *appsv1alpha1.BroadcastJob, if active > parallelism { // exceed parallelism limit r.recorder.Eventf(job, corev1.EventTypeWarning, "TooManyActivePods", "Number of active pods exceed parallelism limit") - //TODO should we remove the extra pods ? it may just finish by its own. + // TODO should we remove the extra pods ? it may just finish by its own. } else if active < parallelism { // diff is the current number of pods to run in this reconcile loop diff --git a/pkg/controller/broadcastjob/broadcastjob_utils.go b/pkg/controller/broadcastjob/broadcastjob_utils.go index 39cb1c82fd..a2de791ff8 100644 --- a/pkg/controller/broadcastjob/broadcastjob_utils.go +++ b/pkg/controller/broadcastjob/broadcastjob_utils.go @@ -133,10 +133,10 @@ func validateControllerRef(controllerRef *metav1.OwnerReference) error { if len(controllerRef.Kind) == 0 { return fmt.Errorf("controllerRef has empty Kind") } - if controllerRef.Controller == nil || *controllerRef.Controller != true { + if controllerRef.Controller == nil || !*controllerRef.Controller { return fmt.Errorf("controllerRef.Controller is not set to true") } - if controllerRef.BlockOwnerDeletion == nil || *controllerRef.BlockOwnerDeletion != true { + if controllerRef.BlockOwnerDeletion == nil || !*controllerRef.BlockOwnerDeletion { return fmt.Errorf("controllerRef.BlockOwnerDeletion is not set") } return nil diff --git a/pkg/controller/cloneset/cloneset_predownload_image.go b/pkg/controller/cloneset/cloneset_predownload_image.go index b7626eebe8..f02fd4f019 100644 --- a/pkg/controller/cloneset/cloneset_predownload_image.go +++ b/pkg/controller/cloneset/cloneset_predownload_image.go @@ -61,12 +61,12 @@ func (r *ReconcileCloneSet) createImagePullJobsForInPlaceUpdate(cs *appsv1alpha1 // ignore if all Pods update in one batch var partition, maxUnavailable int if cs.Spec.UpdateStrategy.Partition != nil { - if pValue, err := util.CalculatePartitionReplicas(cs.Spec.UpdateStrategy.Partition, cs.Spec.Replicas); err != nil { + pValue, err := util.CalculatePartitionReplicas(cs.Spec.UpdateStrategy.Partition, cs.Spec.Replicas) + if err != nil { klog.Errorf("CloneSet %s/%s partition value is illegal", cs.Namespace, cs.Name) return err - } else { - partition = pValue } + partition = pValue } maxUnavailable, _ = intstrutil.GetValueFromIntOrPercent( intstrutil.ValueOrDefault(cs.Spec.UpdateStrategy.MaxUnavailable, intstrutil.FromString(appsv1alpha1.DefaultCloneSetMaxUnavailable)), int(*cs.Spec.Replicas), false) diff --git a/pkg/controller/persistentpodstate/persistent_pod_state_controller.go b/pkg/controller/persistentpodstate/persistent_pod_state_controller.go index 0e11977c8e..a411d72431 100644 --- a/pkg/controller/persistentpodstate/persistent_pod_state_controller.go +++ b/pkg/controller/persistentpodstate/persistent_pod_state_controller.go @@ -299,10 +299,10 @@ func parseStsPodIndex(podName string) (int, error) { } // map[string]*corev1.Pod -> map[Pod.Name]*corev1.Pod -func (p *ReconcilePersistentPodState) getPodsAndStatefulset(persistentPodState *appsv1alpha1.PersistentPodState) (map[string]*corev1.Pod, *innerStatefulset, error) { +func (r *ReconcilePersistentPodState) getPodsAndStatefulset(persistentPodState *appsv1alpha1.PersistentPodState) (map[string]*corev1.Pod, *innerStatefulset, error) { inner := &innerStatefulset{} ref := persistentPodState.Spec.TargetReference - workload, err := p.finder.GetScaleAndSelectorForRef(ref.APIVersion, ref.Kind, persistentPodState.Namespace, ref.Name, "") + workload, err := r.finder.GetScaleAndSelectorForRef(ref.APIVersion, ref.Kind, persistentPodState.Namespace, ref.Name, "") if err != nil { klog.Errorf("persistentPodState(%s/%s) fetch statefulSet(%s) failed: %s", persistentPodState.Namespace, persistentPodState.Name, ref.Name, err.Error()) return nil, nil, err @@ -314,7 +314,7 @@ func (p *ReconcilePersistentPodState) getPodsAndStatefulset(persistentPodState * inner.DeletionTimestamp = workload.Metadata.DeletionTimestamp // DisableDeepCopy:true, indicates must be deep copy before update pod objection - pods, _, err := p.finder.GetPodsForRef(ref.APIVersion, ref.Kind, persistentPodState.Namespace, ref.Name, true) + pods, _, err := r.finder.GetPodsForRef(ref.APIVersion, ref.Kind, persistentPodState.Namespace, ref.Name, true) if err != nil { klog.Errorf("list persistentPodState(%s/%s) pods failed: %s", persistentPodState.Namespace, persistentPodState.Name, err.Error()) return nil, nil, err diff --git a/pkg/controller/podunavailablebudget/podunavailablebudget_controller.go b/pkg/controller/podunavailablebudget/podunavailablebudget_controller.go index 1dbd4467f1..16f424a437 100644 --- a/pkg/controller/podunavailablebudget/podunavailablebudget_controller.go +++ b/pkg/controller/podunavailablebudget/podunavailablebudget_controller.go @@ -140,10 +140,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { UpdateFunc: func(e event.UpdateEvent) bool { old := e.ObjectOld.(*apps.Deployment) new := e.ObjectNew.(*apps.Deployment) - if *old.Spec.Replicas != *new.Spec.Replicas { - return true - } - return false + return *old.Spec.Replicas != *new.Spec.Replicas }, DeleteFunc: func(deleteEvent event.DeleteEvent) bool { return true @@ -157,10 +154,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { UpdateFunc: func(e event.UpdateEvent) bool { old := e.ObjectOld.(*kruiseappsv1beta1.StatefulSet) new := e.ObjectNew.(*kruiseappsv1beta1.StatefulSet) - if *old.Spec.Replicas != *new.Spec.Replicas { - return true - } - return false + return *old.Spec.Replicas != *new.Spec.Replicas }, DeleteFunc: func(deleteEvent event.DeleteEvent) bool { return true @@ -174,10 +168,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { UpdateFunc: func(e event.UpdateEvent) bool { old := e.ObjectOld.(*kruiseappsv1alpha1.CloneSet) new := e.ObjectNew.(*kruiseappsv1alpha1.CloneSet) - if *old.Spec.Replicas != *new.Spec.Replicas { - return true - } - return false + return *old.Spec.Replicas != *new.Spec.Replicas }, DeleteFunc: func(deleteEvent event.DeleteEvent) bool { return true @@ -191,10 +182,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error { UpdateFunc: func(e event.UpdateEvent) bool { old := e.ObjectOld.(*apps.StatefulSet) new := e.ObjectNew.(*apps.StatefulSet) - if *old.Spec.Replicas != *new.Spec.Replicas { - return true - } - return false + return *old.Spec.Replicas != *new.Spec.Replicas }, DeleteFunc: func(deleteEvent event.DeleteEvent) bool { return true diff --git a/pkg/controller/sidecarset/sidecarset_hotupgrade.go b/pkg/controller/sidecarset/sidecarset_hotupgrade.go index 56f10778ca..39e1036a4e 100644 --- a/pkg/controller/sidecarset/sidecarset_hotupgrade.go +++ b/pkg/controller/sidecarset/sidecarset_hotupgrade.go @@ -37,7 +37,7 @@ func (p *Processor) flipHotUpgradingContainers(control sidecarcontrol.SidecarCon p.recorder.Eventf(pod, corev1.EventTypeWarning, "ResetContainerFailed", fmt.Sprintf("reset sidecar container image empty failed: %s", err.Error())) return err } - p.recorder.Eventf(pod, corev1.EventTypeNormal, "ResetContainerSucceed", fmt.Sprintf("reset sidecar container image empty successfully")) + p.recorder.Eventf(pod, corev1.EventTypeNormal, "ResetContainerSucceed", "reset sidecar container image empty successfully") } return nil } diff --git a/pkg/controller/workloadspread/workloadspread_controller.go b/pkg/controller/workloadspread/workloadspread_controller.go index 716de82849..b2087e4ee6 100644 --- a/pkg/controller/workloadspread/workloadspread_controller.go +++ b/pkg/controller/workloadspread/workloadspread_controller.go @@ -499,7 +499,7 @@ func (r *ReconcileWorkloadSpread) calculateWorkloadSpreadStatus(ws *appsv1alpha1 // set the generation in the returned status status := appsv1alpha1.WorkloadSpreadStatus{} status.ObservedGeneration = ws.Generation - //status.ObservedWorkloadReplicas = workloadReplicas + // status.ObservedWorkloadReplicas = workloadReplicas status.SubsetStatuses = make([]appsv1alpha1.WorkloadSpreadSubsetStatus, len(ws.Spec.Subsets)) scheduleFailedPodMap := make(map[string][]*corev1.Pod) @@ -512,7 +512,7 @@ func (r *ReconcileWorkloadSpread) calculateWorkloadSpreadStatus(ws *appsv1alpha1 oldSubsetStatusMap[oldSubsetStatuses[i].Name] = &oldSubsetStatuses[i] } - var rescheduleCriticalSeconds int32 = 0 + var rescheduleCriticalSeconds int32 if ws.Spec.ScheduleStrategy.Type == appsv1alpha1.AdaptiveWorkloadSpreadScheduleStrategyType && ws.Spec.ScheduleStrategy.Adaptive != nil && ws.Spec.ScheduleStrategy.Adaptive.RescheduleCriticalSeconds != nil { @@ -590,7 +590,7 @@ func (r *ReconcileWorkloadSpread) calculateWorkloadSpreadSubsetStatus(ws *appsv1 } oldDeletingPods = oldSubsetStatus.DeletingPods } - var active int32 = 0 + var active int32 for _, pod := range pods { // remove this Pod from creatingPods map because this Pod has been created. @@ -667,7 +667,7 @@ func (r *ReconcileWorkloadSpread) calculateWorkloadSpreadSubsetStatus(ws *appsv1 func (r *ReconcileWorkloadSpread) UpdateWorkloadSpreadStatus(ws *appsv1alpha1.WorkloadSpread, status *appsv1alpha1.WorkloadSpreadStatus) error { if status.ObservedGeneration == ws.Status.ObservedGeneration && - //status.ObservedWorkloadReplicas == ws.Status.ObservedWorkloadReplicas && + // status.ObservedWorkloadReplicas == ws.Status.ObservedWorkloadReplicas && apiequality.Semantic.DeepEqual(status.SubsetStatuses, ws.Status.SubsetStatuses) { return nil } diff --git a/pkg/webhook/resourcedistribution/validating/resourcedistribution_create_update_handler.go b/pkg/webhook/resourcedistribution/validating/resourcedistribution_create_update_handler.go index f1616147c8..306f62b0c8 100755 --- a/pkg/webhook/resourcedistribution/validating/resourcedistribution_create_update_handler.go +++ b/pkg/webhook/resourcedistribution/validating/resourcedistribution_create_update_handler.go @@ -57,7 +57,7 @@ func (h *ResourceDistributionCreateUpdateHandler) validateResourceDistributionSp return } // deserialize old resource if need - var oldResource runtime.Object = nil + var oldResource runtime.Object if oldObj != nil { oldResource, errs = DeserializeResource(&oldObj.Spec.Resource, fldPath) allErrs = append(allErrs, errs...)