Skip to content

Commit

Permalink
adding logs
Browse files Browse the repository at this point in the history
  • Loading branch information
ddjjia committed Jun 28, 2024
1 parent 711b344 commit 041e068
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions pkg/controller/spd/spd.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ func (sc *SPDController) workloadWorker() {

func (sc *SPDController) processNextWorkload() bool {
key, quit := sc.workloadSyncQueue.Get()
klog.Infof("[spd] process next workload key: ", key)
if quit {
return false
}
Expand Down Expand Up @@ -454,7 +455,9 @@ func (sc *SPDController) createSPDWorker() {

func (sc *SPDController) processNextSPDCreation() bool {
key, quit := sc.createSPDWorkloadQueue.Get()
klog.Infof("[spd] create next SPD with workload: %s", key)
if quit {
klog.InfoS("[spd] createSPDWorkloadQueue shutdown")
return false
}
defer sc.createSPDWorkloadQueue.Done(key)
Expand All @@ -465,15 +468,15 @@ func (sc *SPDController) processNextSPDCreation() bool {
return true
}

utilruntime.HandleError(fmt.Errorf("sync %q failed with %v", key, err))
utilruntime.HandleError(fmt.Errorf("[spd] sync %q failed with %v", key, err))
sc.createSPDWorkloadQueue.AddRateLimited(key)

return true
}

// syncWorkloadCreateSPD manages workload spd creation lifecycle and patch first batch of annotation.
func (sc *SPDController) syncWorkloadCreateSPD(key string) error {
klog.V(5).Infof("[spd] syncing workload create SPD [%v]", key)
klog.Infof("[spd] syncing workload create SPD [%v]", key)
workloadGVR, namespace, name, err := native.ParseUniqGVRNameKey(key)
if err != nil {
klog.Errorf("[spd] failed to parse key %s to workload", key)
Expand Down Expand Up @@ -584,11 +587,13 @@ func (sc *SPDController) syncSPD(key string) error {
newSPD := spd.DeepCopy()
err = sc.updateSPDAnnotations(newSPD)
if err != nil {
klog.Errorf("[spd] failed to update SPD key [%v] annotations: %v", key, err)
return err
}

_, err = sc.spdControl.PatchSPD(sc.ctx, spd, newSPD)
if err != nil {
klog.Errorf("[spd] failed to patch SPD key [%v]: %v", key, err)
return err
}

Expand Down Expand Up @@ -720,7 +725,7 @@ func (sc *SPDController) getOrCreateSPDForWorkload(workload *unstructured.Unstru

err = sc.updateSPDAnnotations(spd)
if err != nil {
return nil, err
return nil, fmt.Errorf("[spd] failed to update spd [%v] annotation: %v", spd.Name, err)
}

spd, err = sc.spdControl.CreateSPD(sc.ctx, spd, metav1.CreateOptions{})
Expand All @@ -740,6 +745,7 @@ func (sc *SPDController) getOrCreateSPDForWorkload(workload *unstructured.Unstru
}

func (sc *SPDController) setSPDStatus(workload *unstructured.Unstructured, spd *apiworkload.ServiceProfileDescriptor) (*apiworkload.ServiceProfileDescriptor, error) {
klog.Infof("[spd] setting status for new SPD")
for _, plugin := range sc.indicatorPlugins {
aggMetrics, err := plugin.GetAggMetrics(workload)
if err != nil {
Expand All @@ -753,6 +759,7 @@ func (sc *SPDController) setSPDStatus(workload *unstructured.Unstructured, spd *

err := sc.updateHash(spd)
if err != nil {
klog.Errorf("[spd] failed to update hash for workload %s: %v", workload, err)
return nil, err
}

Expand All @@ -771,7 +778,7 @@ func (sc *SPDController) setPodListSPDAnnotation(podList []*core.Pod, workload *
spdName := workload.GetName()
spd, err := util.GetSPDForWorkload(workload, sc.spdIndexer, sc.spdLister)
if err != nil {
return err
return fmt.Errorf("[spd] failed to get spd %s: %v", spdName, err)
}
spdCreationTime := spd.GetCreationTimestamp()
setPodAnnotations := func(i int) {
Expand Down Expand Up @@ -809,7 +816,7 @@ func (sc *SPDController) setPodSPDAnnotation(pod *core.Pod, spdName string, spdC

err := sc.podUpdater.PatchPod(sc.ctx, pod, podCopy)
if err != nil {
return err
return fmt.Errorf("[spd] failed to patch pod spd annotation: %v", err)
}

if pod.GetCreationTimestamp().Sub(spdCreationTime.Time) > 0 {
Expand Down Expand Up @@ -854,7 +861,7 @@ func (sc *SPDController) cleanPodSPDAnnotation(pod *core.Pod) error {

err := sc.podUpdater.PatchPod(sc.ctx, pod, podCopy)
if err != nil {
return err
return fmt.Errorf("[spd] failed to patch clean spd annotation: %v", err)
}

klog.Infof("[spd] successfully clear annotations for pod %v", pod.GetName())
Expand Down

0 comments on commit 041e068

Please sign in to comment.