From 210515a32abd1b9c52fc6deacc98f385dd10bf54 Mon Sep 17 00:00:00 2001 From: Heba Elayoty Date: Wed, 18 Jan 2023 13:27:11 -0800 Subject: [PATCH] use NotifyContext and remove NotifyNodeStatus Signed-off-by: Heba Elayoty --- cmd/virtual-kubelet/context.go | 31 ------------------------------- cmd/virtual-kubelet/main.go | 8 ++++---- pkg/provider/aci_test.go | 2 +- provider/aci.go | 3 --- 4 files changed, 5 insertions(+), 39 deletions(-) delete mode 100644 cmd/virtual-kubelet/context.go diff --git a/cmd/virtual-kubelet/context.go b/cmd/virtual-kubelet/context.go deleted file mode 100644 index 8a72e9ab..00000000 --- a/cmd/virtual-kubelet/context.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright (c) Microsoft Corporation. -Licensed under the Apache 2.0 license. -*/ -package main - -import ( - "context" - "os" - "os/signal" -) - -func BaseContext(ctx context.Context) (context.Context, func()) { - sigC := make(chan os.Signal, 1) - ctx, cancel := context.WithCancel(ctx) - - go func() { - for { - select { - case <-ctx.Done(): - signal.Stop(sigC) - return - case <-sigC: - cancel() - } - } - }() - - signal.Notify(sigC, cancelSigs()...) - return ctx, cancel -} diff --git a/cmd/virtual-kubelet/main.go b/cmd/virtual-kubelet/main.go index 8e75bbc7..b2ce858b 100644 --- a/cmd/virtual-kubelet/main.go +++ b/cmd/virtual-kubelet/main.go @@ -21,6 +21,7 @@ import ( "fmt" "net/http" "os" + "os/signal" "path/filepath" "strconv" "strings" @@ -51,7 +52,7 @@ var ( ) func main() { - ctx, cancel := BaseContext(context.Background()) + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) defer cancel() binaryName := filepath.Base(os.Args[0]) @@ -226,12 +227,11 @@ func main() { } if vkVersion { - p, err := azproviderv2.NewACIProvider(ctx, cfgPath, azConfig, azACIAPIs, cfg, os.Getenv("VKUBELET_POD_IP"), int32(listenPort), operatingSystem, clusterDomain) - // azproviderv2.NewACIProvider(ctx, cfg.ConfigPath, azConfig, azACIAPIs, cfg.ResourceManager, cfg.NodeName, cfg.OperatingSystem, cfg.InternalIP, cfg.DaemonPort, cfg.KubeClusterDomain) + p, err := azproviderv2.NewACIProvider(ctx, cfgPath, azConfig, azACIAPIs, cfg, nodeName, operatingSystem, os.Getenv("VKUBELET_POD_IP"), int32(listenPort), clusterDomain) return p, nil, err } else { p, err := azproviderv1.NewACIProvider(cfgPath, cfg, os.Getenv("VKUBELET_POD_IP"), int32(listenPort), operatingSystem, clusterDomain) - return p, p, err + return p, nil, err } }, withConfigureRoutes, diff --git a/pkg/provider/aci_test.go b/pkg/provider/aci_test.go index 812261b2..8ad8f64a 100644 --- a/pkg/provider/aci_test.go +++ b/pkg/provider/aci_test.go @@ -587,7 +587,7 @@ func createTestProvider(aciMocks *MockACIProvider, configMapMocker *MockConfigMa cfg.Node.Name = fakeNodeName cfg.Node.Status.NodeInfo.OperatingSystem = "Linux" - provider, err := NewACIProvider(ctx, "example.toml", azConfig, aciMocks, cfg, "0.0.0.0", 10250, "Linux", "cluster.local") + provider, err := NewACIProvider(ctx, "example.toml", azConfig, aciMocks, cfg, fakeNodeName, "Linux", "0.0.0.0", 10250, "cluster.local") if err != nil { return nil, err } diff --git a/provider/aci.go b/provider/aci.go index d70807eb..0ff4d825 100644 --- a/provider/aci.go +++ b/provider/aci.go @@ -1233,9 +1233,6 @@ func (p *ACIProvider) Ping(ctx context.Context) error { return nil } -func (p *ACIProvider) NotifyNodeStatus(ctx context.Context, cb func(*v1.Node)) { -} - // getContainerGroup returns a container group from ACI. func (p *ACIProvider) getContainerGroup(ctx context.Context, namespace, name string) (*aci.ContainerGroup, error) { cg, status, err := p.aciClient.GetContainerGroup(ctx, p.resourceGroup, fmt.Sprintf("%s-%s", namespace, name))