Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit e657404

Browse files
togashidmtejasshahintel
authored andcommitted
Fix the issues pointed by the internal checks
Adding a proper error handling to fix an improper error throw operations. Adjusting klog to avoid a possibility for a race condition.
1 parent a451073 commit e657404

File tree

9 files changed

+60
-23
lines changed

9 files changed

+60
-23
lines changed

.github/e2e/e2e_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"testing"
1212
"time"
1313

14+
"k8s.io/klog/v2"
15+
1416
"github.com/pkg/errors"
1517

1618
"github.com/intel/platform-aware-scheduling/telemetry-aware-scheduling/pkg/metrics"
@@ -54,25 +56,25 @@ func init() {
5456
}
5557
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
5658
if err != nil {
57-
panic(err.Error())
59+
klog.Exit(err.Error())
5860
}
5961

6062
// create the clientset
6163
cl, err = kubernetes.NewForConfig(config)
6264
if err != nil {
63-
panic(err.Error())
65+
klog.Exit(err.Error())
6466
}
6567
cm = metrics.NewClient(config)
6668

6769
tascl, err = tasclient.New(*config, "default")
6870
if err != nil {
69-
panic(err.Error())
71+
klog.Exit(err.Error())
7072
}
7173
//TODO: Replace the generic timeout with an explicit check for the custom metrics from the API Server which times out after some period
7274
err = waitForMetrics(120 * time.Second)
7375

7476
if err != nil {
75-
panic(err.Error())
77+
klog.Exit(err.Error())
7678
}
7779
}
7880

extender/scheduler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ func (m Server) StartServer(port string, certFile string, keyFile string, caFile
9393
if unsafe {
9494
klog.V(2).InfoS("Extender Listening on HTTP "+port, "component", "extender")
9595
err = http.ListenAndServe(":"+port, mx)
96+
if err != nil {
97+
klog.V(2).InfoS("Listening on HTTP failed: "+err.Error(), "component", "extender")
98+
}
9699
} else {
97100
srv := configureSecureServer(port, caFile)
98101
srv.Handler = mx

telemetry-aware-scheduling/cmd/main.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,27 @@ func main() {
5151
//tasController The controller load the TAS policy/strategies and places them into a local cache that is available
5252
//to all TAS components. It also monitors the current state of policies.
5353
func tasController(kubeConfig string, syncPeriod string, cache *tascache.AutoUpdatingCache) {
54+
defer func() {
55+
err := recover()
56+
if err != nil {
57+
klog.V(2).InfoS("Recovered from runtime error", "component", "controller")
58+
}
59+
}()
5460
kubeClient, clientConfig, err := getkubeClient(kubeConfig)
5561
if err != nil {
56-
klog.V(2).InfoS("Issue in getting client config: "+err.Error(), "component", "controller")
57-
panic(err)
62+
klog.V(2).InfoS("Issue in getting client config", "component", "controller")
63+
klog.Exit(err.Error())
5864
}
5965
syncDuration, err := time.ParseDuration(syncPeriod)
6066
if err != nil {
61-
klog.V(2).InfoS("Sync problems in Parsing: "+err.Error(), "component", "controller")
62-
panic(err)
67+
klog.V(2).InfoS("Sync problems in Parsing", "component", "controller")
68+
klog.Exit(err.Error())
6369
}
6470
metricsClient := metrics.NewClient(clientConfig)
6571
telpolicyClient, _, err := telemetrypolicyclient.NewRest(*clientConfig)
6672
if err != nil {
67-
klog.V(2).InfoS("Rest client access to telemetrypolicy CRD problem: "+err.Error(), "component", "controller")
68-
panic(err)
73+
klog.V(2).InfoS("Rest client access to telemetrypolicy CRD problem", "component", "controller")
74+
klog.Exit(err.Error())
6975
}
7076
metricTicker := time.NewTicker(syncDuration)
7177
initialData := map[string]interface{}{}

telemetry-aware-scheduling/pkg/cache/mocks.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ package cache
44
import (
55
"time"
66

7+
"k8s.io/klog/v2"
8+
79
"github.com/intel/platform-aware-scheduling/telemetry-aware-scheduling/pkg/metrics"
810
telemetrypolicy "github.com/intel/platform-aware-scheduling/telemetry-aware-scheduling/pkg/telemetrypolicy/api/v1alpha1"
911
"k8s.io/apimachinery/pkg/api/resource"
@@ -20,9 +22,18 @@ func MockEmptySelfUpdatingCache() ReaderWriter {
2022
//MockSelfUpdatingCache returns auto updating cache
2123
func MockSelfUpdatingCache() *AutoUpdatingCache {
2224
n := MockEmptySelfUpdatingCache()
23-
_ = n.WriteMetric("dummyMetric1", TestNodeMetricCustomInfo([]string{"node A", "node B"}, []int64{50, 30}))
24-
_ = n.WriteMetric("dummyMetric2", TestNodeMetricCustomInfo([]string{"node 1", "node2"}, []int64{100, 200}))
25-
_ = n.WriteMetric("dummyMetric3", TestNodeMetricCustomInfo([]string{"node Z", "node Y"}, []int64{8, 40000000}))
25+
err := n.WriteMetric("dummyMetric1", TestNodeMetricCustomInfo([]string{"node A", "node B"}, []int64{50, 30}))
26+
if err != nil {
27+
klog.InfoS("Unable to create a dummymetric: "+err.Error(), "component", "testing")
28+
}
29+
err = n.WriteMetric("dummyMetric2", TestNodeMetricCustomInfo([]string{"node 1", "node2"}, []int64{100, 200}))
30+
if err != nil {
31+
klog.InfoS("Unable to create a dummymetric: "+err.Error(), "component", "testing")
32+
}
33+
err = n.WriteMetric("dummyMetric3", TestNodeMetricCustomInfo([]string{"node Z", "node Y"}, []int64{8, 40000000}))
34+
if err != nil {
35+
klog.InfoS("Unable to create a dummymetric: "+err.Error(), "component", "testing")
36+
}
2637
return n.(*AutoUpdatingCache)
2738
}
2839

telemetry-aware-scheduling/pkg/controller/controller.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"errors"
88
"fmt"
9+
"log"
910

1011
strategy "github.com/intel/platform-aware-scheduling/telemetry-aware-scheduling/pkg/strategies/core"
1112
"github.com/intel/platform-aware-scheduling/telemetry-aware-scheduling/pkg/strategies/deschedule"
@@ -20,11 +21,15 @@ import (
2021

2122
//Run starts the controller watching on the Informer queue and doesnt' stop it until the Done signal is received from context
2223
func (controller *TelemetryPolicyController) Run(context context.Context) {
23-
klog.V(2).InfoS("Watching Telemetry Policies", "component", "controller")
24+
log.Print("Watching Telemetry Policies", "component", "controller")
25+
defer func() {
26+
if err := recover(); err != nil {
27+
log.Print("Recovered from runtime error", "component", "controller")
28+
}
29+
}()
2430
_, err := controller.watch(context)
2531
if err != nil {
26-
klog.V(2).InfoS(err.Error(), "component", "controller")
27-
panic(err)
32+
log.Panic(err.Error())
2833
}
2934
<-context.Done()
3035
}

telemetry-aware-scheduling/pkg/metrics/client_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ var baseTimeStamp = time.Date(2019, time.May, 20, 12, 25, 00, 0, time.UTC)
2929
//As in NewTestFactory method from kubectl/testing/fake.go
3030
//Reproduced rather than referenced because of dependency issues.
3131
func dummyRestClientConfig() *restclient.Config {
32+
defer func() {
33+
if err := recover(); err != nil {
34+
klog.InfoS("Recovered from runtime error", "component", "testing")
35+
}
36+
}()
3237
tmpFile, err := ioutil.TempFile("", "cmdtests_temp")
3338
if err != nil {
34-
klog.InfoS("Unable to create a fake client config: "+err.Error(), "component", "testing")
35-
panic(err)
39+
klog.InfoS("Unable to create a fake client config", "component", "testing")
40+
klog.Exit(err.Error())
3641
}
3742
loadingRules := &clientcmd.ClientConfigLoadingRules{
3843
Precedence: []string{tmpFile.Name()},

telemetry-aware-scheduling/pkg/metrics/mocks.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,15 @@ import (
1616

1717
//DummyRestClientConfig Mocks used for testing in the metrics and other packages
1818
func DummyRestClientConfig() *restclient.Config {
19+
defer func() {
20+
if err := recover(); err != nil {
21+
klog.InfoS("Recovered from runtime error", "component", "testing")
22+
}
23+
}()
1924
tmpFile, err := ioutil.TempFile("", "cmdtests_temp")
2025
if err != nil {
21-
klog.InfoS("Unable to create a fake client config: "+err.Error(), "component", "testing")
22-
panic(err)
26+
klog.InfoS("Unable to create a fake client config", "component", "testing")
27+
klog.Exit(err.Error())
2328
}
2429
loadingRules := &clientcmd.ClientConfigLoadingRules{
2530
Precedence: []string{tmpFile.Name()},

telemetry-aware-scheduling/pkg/strategies/core/enforcer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package core
22

33
import (
44
"fmt"
5+
"log"
56
"sync"
67
"time"
78

@@ -121,8 +122,7 @@ func (e *MetricEnforcer) enforceStrategy(strategyType string, cache cache.Reader
121122
if enf, ok := str.(Enforceable); ok {
122123
_, err := enf.Enforce(e, cache)
123124
if err != nil {
124-
msg := fmt.Sprintf("Strategy was not enforceable: %v", err)
125-
klog.V(2).InfoS(msg, "component", "controller")
125+
log.Print("Strategy was not enforceable.", err.Error(), "component", "controller")
126126
}
127127
}
128128
}

telemetry-aware-scheduling/pkg/strategies/dontschedule/strategy_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestDontScheduleStrategy_Violated(t *testing.T) {
3333
err := tt.args.cache.WriteMetric("memory", metrics.NodeMetricsInfo{"node-1": {Timestamp: time.Now(), Window: 1, Value: *resource.NewQuantity(10, resource.DecimalSI)}})
3434
if err != nil {
3535
klog.V(4).InfoS(err.Error(), "component", "testing")
36-
panic(err)
36+
klog.Exit(err)
3737
}
3838
if got := tt.d.Violated(tt.args.cache); !reflect.DeepEqual(got, tt.want) {
3939
t.Errorf("Strategy.Violated() = %v, want %v", got, tt.want)

0 commit comments

Comments
 (0)