Skip to content

Commit 9469d17

Browse files
Merge pull request openshift#7252 from zaneb/libvirt-static
OCPBUGS-15861: Use a static pure-go libvirt library
2 parents 42a1e5e + 518244f commit 9469d17

File tree

134 files changed

+26445
-29550
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+26445
-29550
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ require (
3333
github.com/coreos/ignition/v2 v2.18.0
3434
github.com/coreos/stream-metadata-go v0.1.8
3535
github.com/daixiang0/gci v0.10.1
36+
github.com/digitalocean/go-libvirt v0.0.0-20240220204746-fcabe97a6eed
3637
github.com/diskfs/go-diskfs v1.4.0
3738
github.com/form3tech-oss/jwt-go v3.2.3+incompatible
3839
github.com/go-openapi/errors v0.21.1
@@ -52,7 +53,6 @@ require (
5253
github.com/hashicorp/terraform-exec v0.17.3
5354
github.com/jongio/azidext/go/azidext v0.5.0
5455
github.com/kdomanski/iso9660 v0.2.1
55-
github.com/libvirt/libvirt-go v5.10.0+incompatible
5656
github.com/metal3-io/baremetal-operator/apis v0.4.0
5757
github.com/metal3-io/baremetal-operator/pkg/hardwareutils v0.4.0
5858
github.com/microsoft/kiota-authentication-azure-go v0.5.0

go.sum

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
250250
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
251251
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
252252
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
253+
github.com/digitalocean/go-libvirt v0.0.0-20240220204746-fcabe97a6eed h1:pDXysiX24X+SE6MwVcfd5lGE21a4jNH9ZgaF9AyshHY=
254+
github.com/digitalocean/go-libvirt v0.0.0-20240220204746-fcabe97a6eed/go.mod h1:isF7ghADfbC01gQx4vZnIOrxXT5RXLG81y+UCb5XSwc=
253255
github.com/dimchansky/utfbom v1.1.1 h1:vV6w1AhK4VMnhBno/TPVCoK9U/LP0PkLCS9tbxHdi/U=
254256
github.com/dimchansky/utfbom v1.1.1/go.mod h1:SxdoEBH5qIqFocHMyGOXVAybYJdr71b1Q/j0mACtrfE=
255257
github.com/diskfs/go-diskfs v1.4.0 h1:MAybY6TPD+fmhY+a2qFhmdvMeIKvCqlgh4QIc1uCmBs=
@@ -663,8 +665,6 @@ github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0
663665
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
664666
github.com/leodido/go-urn v1.3.0 h1:jX8FDLfW4ThVXctBNZ+3cIWnCSnrACDV73r76dy0aQQ=
665667
github.com/leodido/go-urn v1.3.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
666-
github.com/libvirt/libvirt-go v5.10.0+incompatible h1:01fwkdUHH2hk4YyFNCr48OvSGqXYLzp9cofUpeyeLNc=
667-
github.com/libvirt/libvirt-go v5.10.0+incompatible/go.mod h1:34zsnB4iGeOv7Byj6qotuW8Ya4v4Tr43ttjz/F0wjLE=
668668
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de h1:9TO3cAIGXtEhnIaL+V+BEER86oLrvS+kWobKpbJuye0=
669669
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de/go.mod h1:zAbeS9B/r2mtpb6U+EI2rYA5OAXxsYw6wTamcNW+zcE=
670670
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@@ -957,6 +957,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
957957
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
958958
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
959959
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
960+
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
960961
github.com/zclconf/go-cty v1.2.0/go.mod h1:hOPWgoHbaTUnI5k4D2ld+GRpFJSCe6bCM7m1q/N4PQ8=
961962
github.com/zclconf/go-cty v1.10.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUAzyuvAk=
962963
github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0=
@@ -1045,6 +1046,8 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
10451046
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
10461047
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
10471048
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
1049+
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
1050+
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
10481051
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
10491052
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
10501053
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw=
@@ -1075,6 +1078,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
10751078
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
10761079
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
10771080
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
1081+
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
10781082
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
10791083
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
10801084
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
@@ -1143,10 +1147,12 @@ golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBc
11431147
golang.org/x/sys v0.0.0-20220408201424-a24fb2fb8a0f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11441148
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11451149
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1150+
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11461151
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11471152
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11481153
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11491154
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
1155+
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11501156
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11511157
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
11521158
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -1233,6 +1239,8 @@ golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff/go.mod h1:YD9qOF0M9xpSpd
12331239
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
12341240
golang.org/x/tools v0.1.9/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
12351241
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
1242+
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
1243+
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
12361244
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
12371245
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
12381246
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

images/baremetal/Dockerfile.ci

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
# This Dockerfile is a used by CI to publish an installer image
22
# It builds an image containing openshift-install.
33

4-
ARG libvirt_version="8.0.0"
5-
64
FROM registry.ci.openshift.org/ocp/4.16:installer-terraform-providers AS providers
75

86
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.21-openshift-4.16 AS builder
9-
ARG libvirt_version
107
ARG TAGS="libvirt baremetal"
11-
RUN dnf install -y libvirt-devel-$libvirt_version && \
12-
dnf clean all && rm -rf /var/cache/yum/*
138
WORKDIR /go/src/github.com/openshift/installer
149
COPY . .
1510
COPY --from=providers /go/src/github.com/openshift/installer/terraform/bin/ terraform/bin/
1611
RUN DEFAULT_ARCH="$(go env GOHOSTARCH)" hack/build.sh
1712

1813

1914
FROM registry.ci.openshift.org/ocp/4.16:base
20-
ARG libvirt_version
2115
COPY --from=builder /go/src/github.com/openshift/installer/bin/openshift-install /bin/openshift-install
2216

2317
RUN dnf upgrade -y && \
2418
dnf install --setopt=tsflags=nodocs -y \
25-
libvirt-libs-$libvirt_version openssl unzip jq openssh-clients && \
19+
openssl unzip jq openssh-clients && \
2620
dnf clean all && rm -rf /var/cache/yum/*
2721

2822
RUN mkdir /output && chown 1000:1000 /output

images/libvirt/Dockerfile.ci

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ FROM registry.ci.openshift.org/ocp/4.16:installer-terraform-providers as provide
66

77
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.21-openshift-4.16 AS builder
88
ARG TAGS="libvirt"
9-
RUN yum install -y libvirt-devel && \
10-
yum clean all && rm -rf /var/cache/yum/*
119
WORKDIR /go/src/github.com/openshift/installer
1210
COPY . .
1311
COPY --from=providers /go/src/github.com/openshift/installer/terraform/bin/ terraform/bin/

pkg/destroy/baremetal/baremetal.go

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
package baremetal
55

66
import (
7-
"github.com/libvirt/libvirt-go"
8-
"github.com/pkg/errors"
7+
"fmt"
8+
"net/url"
9+
10+
libvirt "github.com/digitalocean/go-libvirt"
911
"github.com/sirupsen/logrus"
1012

1113
"github.com/openshift/installer/pkg/destroy/providers"
@@ -24,17 +26,27 @@ type ClusterUninstaller struct {
2426
func (o *ClusterUninstaller) Run() (*types.ClusterQuota, error) {
2527
o.Logger.Debug("Deleting bare metal resources")
2628

27-
// FIXME: close the connection
28-
conn, err := libvirt.NewConnect(o.LibvirtURI)
29+
uri, err := url.Parse(o.LibvirtURI)
2930
if err != nil {
30-
return nil, errors.Wrap(err, "failed to connect to Libvirt daemon")
31+
return nil, err
3132
}
32-
err = o.deleteStoragePool(conn)
33+
34+
virt, err := libvirt.ConnectToURI(uri)
3335
if err != nil {
34-
return nil, errors.Wrap(err, "failed to clean baremetal bootstrap storage pool")
36+
return nil, err
3537
}
38+
defer func() {
39+
if err := virt.Disconnect(); err != nil {
40+
if o.Logger != nil {
41+
o.Logger.Warn("failed to disconnect from libvirt", err)
42+
}
43+
}
44+
}()
3645

37-
o.Logger.Debug("FIXME: delete resources!")
46+
err = o.deleteStoragePool(virt)
47+
if err != nil {
48+
return nil, fmt.Errorf("failed to clean baremetal bootstrap storage pool: %w", err)
49+
}
3850

3951
return nil, nil
4052
}
@@ -51,47 +63,45 @@ func New(logger logrus.FieldLogger, metadata *types.ClusterMetadata) (providers.
5163

5264
// deleteStoragePool destroys, deletes and undefines any storagePool left behind during the creation
5365
// of the bootstrap VM
54-
func (o *ClusterUninstaller) deleteStoragePool(conn *libvirt.Connect) error {
66+
func (o *ClusterUninstaller) deleteStoragePool(virt *libvirt.Libvirt) error {
5567
o.Logger.Debug("Deleting baremetal bootstrap volumes")
5668

5769
pName := o.InfraID + "-bootstrap"
58-
pool, err := conn.LookupStoragePoolByName(pName)
70+
pool, err := virt.StoragePoolLookupByName(pName)
5971
if err != nil {
6072
o.Logger.Warnf("Unable to get storage pool %s: %s", pName, err)
6173
return nil
6274
}
63-
defer pool.Free()
6475

6576
// delete vols
66-
vols, err := pool.ListAllStorageVolumes(0)
77+
vols, err := virt.StoragePoolListVolumes(pool, 0)
6778
if err != nil {
6879
o.Logger.Warnf("Unable to get volumes in storage pool %s: %s", pName, err)
6980
return nil
7081
}
7182

72-
for _, vol := range vols {
73-
defer vol.Free()
74-
vName, err := vol.GetName()
83+
for _, vName := range vols {
84+
vol, err := virt.StorageVolLookupByName(pool, vName)
7585
if err != nil {
7686
o.Logger.Warnf("Unable to get volume %s in storage pool %s: %s", vName, pName, err)
7787
return nil
7888
}
79-
if err := vol.Delete(0); err != nil {
89+
if err := virt.StorageVolDelete(vol, 0); err != nil {
8090
o.Logger.Warnf("Unable to delete volume %s in storage pool %s: %s", vName, pName, err)
8191
return nil
8292
}
8393
o.Logger.WithField("volume", vName).Info("Deleted volume")
8494
}
8595

86-
if err := pool.Destroy(); err != nil {
96+
if err := virt.StoragePoolDestroy(pool); err != nil {
8797
o.Logger.Warnf("Unable to destroy storage pool %s: %s", pName, err)
8898
}
8999

90-
if err := pool.Delete(0); err != nil {
100+
if err := virt.StoragePoolDelete(pool, 0); err != nil {
91101
o.Logger.Warnf("Unable to delete storage pool %s: %s", pName, err)
92102
}
93103

94-
if err := pool.Undefine(); err != nil {
104+
if err := virt.StoragePoolUndefine(pool); err != nil {
95105
o.Logger.Warnf("Unable to undefine storage pool %s: %s", pName, err)
96106
}
97107
o.Logger.WithField("pool", pName).Info("Deleted pool")

0 commit comments

Comments
 (0)