Skip to content

Commit

Permalink
remove unused var
Browse files Browse the repository at this point in the history
Signed-off-by: Heba Elayoty <hebaelayoty@gmail.com>
  • Loading branch information
helayoty committed Mar 16, 2023
1 parent caa3bc6 commit 92b0eb6
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 72 deletions.
67 changes: 38 additions & 29 deletions cmd/virtual-kubelet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,23 @@ import (
"github.com/virtual-kubelet/virtual-kubelet/log"
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"
"github.com/virtual-kubelet/virtual-kubelet/node"
"github.com/virtual-kubelet/virtual-kubelet/node/api"
"github.com/virtual-kubelet/virtual-kubelet/node/nodeutil"
v1 "k8s.io/api/core/v1"
"k8s.io/apiserver/pkg/server/dynamiccertificates"
"k8s.io/apiserver/pkg/server/options"
"k8s.io/klog/v2"
)

var (
buildVersion = "N/A"
buildTime = "N/A"
k8sVersion = "v1.25.0" // This should follow the version of k8s.io/client-go we are importing
k8sVersion = "v1.25.0" // This should follow the version of k8s.io we are importing

taintKey = envOrDefault("VKUBELET_TAINT_KEY", "virtual-kubelet.io/provider")
taintEffect = envOrDefault("VKUBELET_TAINT_EFFECT", string(v1.TaintEffectNoSchedule))
taintValue = envOrDefault("VKUBELET_TAINT_VALUE", "azure")

logLevel = "debug"
logLevel = "info"
traceSampleRate string

// for aci
Expand Down Expand Up @@ -112,7 +113,6 @@ func main() {
kubeConfigPath = filepath.Join(home, ".kube", "config")
}
}
mux := http.NewServeMux()

withTaint := func(cfg *nodeutil.NodeConfig) error {
if disableTaint {
Expand Down Expand Up @@ -140,39 +140,49 @@ func main() {
cfg.NodeSpec.Status.NodeInfo.KubeletVersion = strings.Join([]string{k8sVersion, "vk-azure-aci", buildVersion}, "-")
return nil
}

configureRoutes := func(cfg *nodeutil.NodeConfig) error {
mux := http.NewServeMux()
cfg.Handler = mux
return nodeutil.AttachProviderRoutes(mux)(cfg)
}
withWebhookAuth := func(cfg *nodeutil.NodeConfig) error {
if !webhookAuth {
cfg.Handler = api.InstrumentHandler(nodeutil.WithAuth(nodeutil.NoAuth(), cfg.Handler))
return nil
}
auth, err := nodeutil.WebhookAuth(cfg.Client, cfg.NodeSpec.Name, func(cfg *nodeutil.WebhookAuthConfig) error {
if webhookAuthnCacheTTL > 0 {
cfg.AuthnConfig.CacheTTL = webhookAuthnCacheTTL
}
if webhookAuthzAuthedCacheTTL > 0 {
cfg.AuthzConfig.AllowCacheTTL = webhookAuthzAuthedCacheTTL
}
if webhookAuthzUnauthedCacheTTL > 0 {
cfg.AuthzConfig.AllowCacheTTL = webhookAuthzUnauthedCacheTTL
}

log.G(ctx).Debug("clientCACert value is: %s", clientCACert)
if clientCACert != "" {
log.G(ctx).Debug("clientCACert is not nil: %s", clientCACert)
ca, err := dynamiccertificates.NewDynamicCAContentFromFile("client-ca", clientCACert)
if err != nil {
return err
auth, err := nodeutil.WebhookAuth(cfg.Client, nodeName,
func(cfg *nodeutil.WebhookAuthConfig) error {
var err error

cfg.AuthzConfig.WebhookRetryBackoff = options.DefaultAuthWebhookRetryBackoff()
cfg.AuthzConfig.WebhookRetryBackoff = options.DefaultAuthWebhookRetryBackoff()

if webhookAuthnCacheTTL > 0 {
cfg.AuthnConfig.CacheTTL = webhookAuthnCacheTTL
}
cfg.AuthnConfig.ClientCertificateCAContentProvider = ca
go ca.Run(ctx, 1)
}
return nil
})
if webhookAuthzAuthedCacheTTL > 0 {
cfg.AuthzConfig.AllowCacheTTL = webhookAuthzAuthedCacheTTL
}
if webhookAuthzUnauthedCacheTTL > 0 {
cfg.AuthzConfig.AllowCacheTTL = webhookAuthzUnauthedCacheTTL
}
if clientCACert != "" {
ca, err := dynamiccertificates.NewDynamicCAContentFromFile("client-ca", clientCACert)
if err != nil {
return err
}
cfg.AuthnConfig.ClientCertificateCAContentProvider = ca
go ca.Run(ctx, 1)
}
return err
})

if err != nil {
return err
}
cfg.TLSConfig.ClientAuth = tls.RequestClientCert
cfg.Handler = nodeutil.WithAuth(auth, cfg.Handler)
cfg.Handler = api.InstrumentHandler(nodeutil.WithAuth(auth, cfg.Handler))
return nil
}

Expand Down Expand Up @@ -222,14 +232,13 @@ func main() {
withVersion,
nodeutil.WithTLSConfig(nodeutil.WithKeyPairFromPath(certPath, keyPath), withCA),
withWebhookAuth,
configureRoutes,
func(cfg *nodeutil.NodeConfig) error {
cfg.Handler = mux
cfg.InformerResyncPeriod = resync
cfg.NumWorkers = numberOfWorkers
cfg.HTTPListenAddr = fmt.Sprintf(":%d", listenPort)
return nil
},
nodeutil.AttachProviderRoutes(mux),
)
if err != nil {
return err
Expand Down
31 changes: 22 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.7.0
github.com/virtual-kubelet/virtual-kubelet v1.7.0
github.com/stretchr/testify v1.8.0
github.com/virtual-kubelet/virtual-kubelet v1.8.0
go.opencensus.io v0.23.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
gotest.tools v2.2.0+incompatible
k8s.io/api v0.25.0
k8s.io/apimachinery v0.25.0
k8s.io/api v0.26.2
k8s.io/apimachinery v0.26.2
k8s.io/apiserver v0.25.0
k8s.io/client-go v0.25.0
k8s.io/klog/v2 v2.80.1
Expand All @@ -40,14 +40,18 @@ require (
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/AzureAD/microsoft-authentication-library-for-go v0.7.0 // indirect
github.com/NYTimes/gziphandler v1.1.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/census-instrumentation/opencensus-proto v0.2.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
Expand All @@ -59,9 +63,10 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand All @@ -81,7 +86,11 @@ require (
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.etcd.io/etcd/api/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/pkg/v3 v3.5.4 // indirect
go.etcd.io/etcd/client/v3 v3.5.4 // indirect
go.opentelemetry.io/contrib v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.20.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.20.0 // indirect
go.opentelemetry.io/otel v0.20.0 // indirect
go.opentelemetry.io/otel/exporters/otlp v0.20.0 // indirect
Expand All @@ -91,24 +100,28 @@ require (
go.opentelemetry.io/otel/sdk/metric v0.20.0 // indirect
go.opentelemetry.io/otel/trace v0.20.0 // indirect
go.opentelemetry.io/proto/otlp v0.7.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
google.golang.org/api v0.43.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/api v0.57.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
google.golang.org/grpc v1.47.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.25.0 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.32 // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
Expand Down
Loading

0 comments on commit 92b0eb6

Please sign in to comment.