Skip to content

Commit 432f283

Browse files
committed
*: Make libvirt support completely conditional (behind TAGS=libvirt)
Previously, destroy support was behind TAGS=libvirt_destroy and create support was always built in. But since 3fb4400 (terraform/plugins: add `libvirt`, `aws`, `ignition`, `openstack` to KnownPlugins, 2018-12-14, #919), the bundled libvirt Terraform provider has also been behind libvirt_destroy. That leads to cluster creation failing with: $ openshift-install create cluster ... ERROR Missing required providers. ERROR ERROR The following provider constraints are not met by the currently-installed ERROR provider plugins: ERROR ERROR * libvirt (any version) ERROR ERROR Terraform can automatically download and install plugins to meet the given ERROR constraints, but this step was skipped due to the use of -get-plugins=false ERROR and/or -plugin-dir on the command line. ... With this commit, folks trying to 'create cluster' without libvirt compiled in will get: FATAL failed to fetch Common Manifests: failed to load asset "Install Config": invalid "install-config.yaml" file: platform: Invalid value: types.Platform{AWS:(*aws.Platform)(nil), Libvirt:(*libvirt.Platform)(0xc4209511f0), OpenStack:(*openstack.Platform)(nil)}: platform must be one of: aws, openstack before we get to Terraform. Now that the build tag guards both creation and deletion, I've renamed it from 'libvirt_destroy' to the unqualified 'libvirt'. I've also adjusted the install-config validation testing to use regular expressions so we can distinguish between failures because libvirt was not compiled in as a valid platform and failures because some portion of the libvirt configuration was broken. In order to get stable error messages for comparison, I've added some strings.Sort calls for various allowed-value string-slice computations.
1 parent f93dcff commit 432f283

File tree

13 files changed

+60
-42
lines changed

13 files changed

+60
-42
lines changed

docs/dev/libvirt-howto.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,21 @@ This step allows installer and users to resolve cluster-internal hostnames from
202202
## Build and run the installer
203203

204204
With [libvirt configured](#install-and-enable-libvirt), you can proceed with [the usual quick-start](../../README.md#quick-start).
205-
Set `TAGS` when building if you need `destroy cluster` support for libvirt; this is not enabled by default because it requires [cgo][]:
205+
Set `TAGS=libvirt` to add support for libvirt; this is not enabled by default because libvirt is [development only](../../README.md#supported-platforms).
206206

207207
```sh
208-
TAGS=libvirt_destroy hack/build.sh
208+
TAGS=libvirt hack/build.sh
209209
```
210210

211211
## Cleanup
212212

213-
If you compiled with `libvirt_destroy`, you can use:
213+
To remove resources associated with your cluster, run:
214214

215215
```sh
216216
openshift-install destroy cluster
217217
```
218218

219-
If you did not compile with `libvirt_destroy`, you can use [`virsh-cleanup.sh`](../../scripts/maintenance/virsh-cleanup.sh), but note it will currently destroy *all* libvirt resources.
219+
You can also use [`virsh-cleanup.sh`](../../scripts/maintenance/virsh-cleanup.sh), but note that it will currently destroy *all* libvirt resources.
220220

221221
### Firewall
222222

@@ -341,7 +341,6 @@ If your issue is not reported, please do.
341341
[arch_firewall_superuser]: https://superuser.com/questions/1063240/libvirt-failed-to-initialize-a-valid-firewall-backend
342342
[brokenmacosissue201]: https://github.com/openshift/installer/issues/201
343343
[bugzilla_libvirt_race]: https://bugzilla.redhat.com/show_bug.cgi?id=1576464
344-
[cgo]: https://golang.org/cmd/cgo/
345344
[issues_libvirt]: https://github.com/openshift/installer/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+libvirt
346345
[libvirt_selinux_issues]: https://github.com/dmacvicar/terraform-provider-libvirt/issues/142#issuecomment-409040151
347346
[tfprovider_libvirt_race]: https://github.com/dmacvicar/terraform-provider-libvirt/issues/402#issuecomment-419500064

hack/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ dev)
5959
exit 1
6060
esac
6161

62-
if (echo "${TAGS}" | grep -q 'libvirt_destroy')
62+
if (echo "${TAGS}" | grep -q 'libvirt')
6363
then
6464
export CGO_ENABLED=1
6565
fi

images/nested-libvirt/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
FROM openshift/origin-release:golang-1.10 AS build
44
WORKDIR /go/src/github.com/openshift/installer
55
COPY . .
6-
RUN TAGS=libvirt_destroy hack/build.sh
6+
RUN TAGS=libvirt hack/build.sh
77

88
FROM centos:7
99
COPY --from=build /go/src/github.com/openshift/installer/bin/openshift-install /bin/openshift-install

pkg/destroy/libvirt/libvirt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build libvirt_destroy
1+
// +build libvirt
22

33
package libvirt
44

pkg/destroy/libvirt/register.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build libvirt_destroy
1+
// +build libvirt
22

33
package libvirt
44

pkg/terraform/exec/plugins/libvirt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build libvirt_destroy
1+
// +build libvirt
22

33
package plugins
44

pkg/types/aws/validation/platform.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package validation
22

33
import (
4+
"sort"
5+
46
"k8s.io/apimachinery/pkg/util/validation/field"
57

68
"github.com/openshift/installer/pkg/types/aws"
@@ -39,6 +41,7 @@ var (
3941
validValues[i] = r
4042
i++
4143
}
44+
sort.Strings(validValues)
4245
return validValues
4346
}()
4447
)

pkg/types/installconfig.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ var (
1414
// alphabetical order.
1515
PlatformNames = []string{
1616
aws.Name,
17-
libvirt.Name,
1817
openstack.Name,
1918
}
2019
)

pkg/types/installconfig_libvirt.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// +build libvirt
2+
3+
package types
4+
5+
import (
6+
"sort"
7+
8+
"github.com/openshift/installer/pkg/types/libvirt"
9+
)
10+
11+
func init() {
12+
PlatformNames = append(PlatformNames, libvirt.Name)
13+
sort.Strings(PlatformNames)
14+
}

pkg/types/validation/installconfig.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package validation
33
import (
44
"fmt"
55
"net"
6+
"sort"
7+
"strings"
68

79
netopv1 "github.com/openshift/cluster-network-operator/pkg/apis/networkoperator/v1"
810
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -108,12 +110,14 @@ func validateMachinePools(pools []types.MachinePool, fldPath *field.Path, platfo
108110

109111
func validatePlatform(platform *types.Platform, fldPath *field.Path, openStackValidValuesFetcher openstackvalidation.ValidValuesFetcher) field.ErrorList {
110112
allErrs := field.ErrorList{}
111-
activePlatform := ""
113+
activePlatform := platform.Name()
114+
i := sort.SearchStrings(types.PlatformNames, activePlatform)
115+
if i == len(types.PlatformNames) || types.PlatformNames[i] != activePlatform {
116+
allErrs = append(allErrs, field.Invalid(fldPath, platform, fmt.Sprintf("must specify one of the platforms (%s)", strings.Join(types.PlatformNames, ", "))))
117+
}
112118
validate := func(n string, value interface{}, validation func(*field.Path) field.ErrorList) {
113-
if activePlatform != "" {
119+
if n != activePlatform {
114120
allErrs = append(allErrs, field.Invalid(fldPath, platform, fmt.Sprintf("must only specify a single type of platform; cannot use both %q and %q", activePlatform, n)))
115-
} else {
116-
activePlatform = n
117121
}
118122
allErrs = append(allErrs, validation(fldPath.Child(n))...)
119123
}
@@ -128,8 +132,5 @@ func validatePlatform(platform *types.Platform, fldPath *field.Path, openStackVa
128132
return openstackvalidation.ValidatePlatform(platform.OpenStack, f, openStackValidValuesFetcher)
129133
})
130134
}
131-
if activePlatform == "" {
132-
allErrs = append(allErrs, field.Invalid(fldPath, platform, "must specify one of the platforms"))
133-
}
134135
return allErrs
135136
}

0 commit comments

Comments
 (0)