in cmd/k8s-cloudkms-plugin/main.go [57:119]
func main() {
ctx, cancel := signal.NotifyContext(context.Background(),
syscall.SIGINT, syscall.SIGTERM)
defer cancel()
flag.Parse()
mustValidateFlags()
var (
httpClient = http.DefaultClient
err error
)
if !*integrationTest {
// httpClient should be constructed with context.Background. Sending a context with
// timeout or deadline will cause subsequent calls via the client to fail once the timeout or
// deadline is triggered. Instead, the plugin supplies a context per individual calls.
httpClient, err = plugin.NewHTTPClient(ctx, *gceConf)
if err != nil {
glog.Exitf("failed to instantiate http httpClient: %v", err)
}
}
kms, err := cloudkms.NewService(ctx, option.WithHTTPClient(httpClient))
if err != nil {
glog.Exitf("failed to instantiate cloud kms httpClient: %v", err)
}
if *integrationTest {
kms.BasePath = fmt.Sprintf("http://localhost:%d", *fakeKMSPort)
}
metrics := &plugin.Metrics{
ServingURL: &url.URL{
Host: fmt.Sprintf("localhost:%d", *metricsPort),
Path: *metricsPath,
},
}
var p plugin.Plugin
var healthChecker plugin.HealthChecker
switch *kmsVersion {
case "v1":
p = v1.NewPlugin(kms.Projects.Locations.KeyRings.CryptoKeys, *keyURI)
healthChecker = v1.NewHealthChecker()
glog.Info("Kubernetes KMS API v1beta1")
case "v2":
p = v2.NewPlugin(kms.Projects.Locations.KeyRings.CryptoKeys, *keyURI, *keySuffix)
healthChecker = v2.NewHealthChecker()
glog.Info("Kubernetes KMS API v2")
default:
glog.Exitf("invalid value %q for --kms", *kmsVersion)
}
hc := plugin.NewHealthChecker(healthChecker, *keyURI, kms.Projects.Locations.KeyRings.CryptoKeys, *pathToUnixSocket, *healthzTimeout, &url.URL{
Host: fmt.Sprintf("localhost:%d", *healthzPort),
Path: *healthzPath,
})
pluginManager := plugin.NewManager(p, *pathToUnixSocket)
glog.Exit(run(pluginManager, hc, metrics))
}