From 3038a70ffb75445e4e61185ea6ec34c34097f88c Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Tue, 25 Jul 2023 16:33:18 +0800 Subject: [PATCH] upadate libyavirt(support tls and simple auth for yavirt) (#607) --- engine/virt/virt.go | 19 +++++++++++++++++-- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/engine/virt/virt.go b/engine/virt/virt.go index 050cc28a3..6b9ea7bca 100644 --- a/engine/virt/virt.go +++ b/engine/virt/virt.go @@ -6,6 +6,7 @@ import ( "encoding/json" "fmt" "io" + "os" "strconv" "strings" "time" @@ -43,7 +44,7 @@ type Virt struct { } // MakeClient makes a virt. client which wraps yavirt API client. -func MakeClient(_ context.Context, config coretypes.Config, _, endpoint, _, _, _ string) (engine.API, error) { +func MakeClient(_ context.Context, config coretypes.Config, nodename, endpoint, ca, _, _ string) (engine.API, error) { var uri string switch { case strings.HasPrefix(endpoint, HTTPPrefixKey): @@ -54,7 +55,21 @@ func MakeClient(_ context.Context, config coretypes.Config, _, endpoint, _, _, _ return nil, coretypes.ErrInvaildEngineEndpoint } - cli, err := virtapi.New(uri) + yCfg := &virttypes.Config{ + URI: uri, + } + if ca != "" { + caFile, err := os.CreateTemp(config.CertPath, fmt.Sprintf("ca-%s", nodename)) + if err != nil { + return nil, err + } + if _, err := caFile.WriteString(ca); err != nil { + return nil, err + } + defer os.Remove(caFile.Name()) + yCfg.CA = caFile.Name() + } + cli, err := virtapi.New(yCfg) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index ab5e3593d..e7bb58a0b 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b github.com/panjf2000/ants/v2 v2.7.3 github.com/patrickmn/go-cache v2.1.0+incompatible - github.com/projecteru2/libyavirt v0.0.0-20230705102231-8199e310da06 + github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625 github.com/prometheus/client_golang v1.15.0 github.com/rs/zerolog v1.29.1 github.com/sanity-io/litter v1.5.5 diff --git a/go.sum b/go.sum index 6f4a7eb26..3ff2407cd 100644 --- a/go.sum +++ b/go.sum @@ -459,8 +459,8 @@ github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= -github.com/projecteru2/libyavirt v0.0.0-20230705102231-8199e310da06 h1:p/1vyEftIPf9LPuMMr7STDllXlVzrWc1eUHHuUPcE9o= -github.com/projecteru2/libyavirt v0.0.0-20230705102231-8199e310da06/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw= +github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625 h1:liDnxQ0JxvOLC0/tUVRlz4tG9r/xbcp1NXgNVNBJsLQ= +github.com/projecteru2/libyavirt v0.0.0-20230725071905-9785e974d625/go.mod h1:N41KaKmqbailweGs4x/mt2H0O0Y7MizObZQ+igLdzpw= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= github.com/prometheus/client_golang v1.1.0/go.mod h1:I1FGZT9+L76gKKOs5djB6ezCbFQP1xR9D75/vuwEF3g=