@@ -4,11 +4,14 @@ package openstack
4
4
import (
5
5
"encoding/json"
6
6
7
+ "github.com/openshift/installer/pkg/rhcos"
8
+
7
9
"sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1"
8
10
)
9
11
10
12
type config struct {
11
- BaseImage string `json:"openstack_base_image,omitempty"`
13
+ BaseImageName string `json:"openstack_base_image_name,omitempty"`
14
+ BaseImageURL string `json:"openstack_base_image_url,omitempty"`
12
15
ExternalNetwork string `json:"openstack_external_network,omitempty"`
13
16
Cloud string `json:"openstack_credentials_cloud,omitempty"`
14
17
FlavorName string `json:"openstack_master_flavor_name,omitempty"`
@@ -23,9 +26,8 @@ type config struct {
23
26
}
24
27
25
28
// TFVars generates OpenStack-specific Terraform variables.
26
- func TFVars (masterConfig * v1alpha1.OpenstackProviderSpec , cloud string , externalNetwork string , lbFloatingIP string , apiVIP string , dnsVIP string , ingressVIP string , trunkSupport string , octaviaSupport string ) ([]byte , error ) {
29
+ func TFVars (masterConfig * v1alpha1.OpenstackProviderSpec , cloud string , externalNetwork string , lbFloatingIP string , apiVIP string , dnsVIP string , ingressVIP string , trunkSupport string , octaviaSupport string , baseImage string , infraID string ) ([]byte , error ) {
27
30
cfg := & config {
28
- BaseImage : masterConfig .Image ,
29
31
ExternalNetwork : externalNetwork ,
30
32
Cloud : cloud ,
31
33
FlavorName : masterConfig .Flavor ,
@@ -36,6 +38,23 @@ func TFVars(masterConfig *v1alpha1.OpenstackProviderSpec, cloud string, external
36
38
TrunkSupport : trunkSupport ,
37
39
OctaviaSupport : octaviaSupport ,
38
40
}
41
+
42
+ // Normally baseImage contains a URL that we will use to create a new Glance image, but for testing
43
+ // purposes we also allow to set a custom Glance image name to skip the uploading. Here we check
44
+ // whether baseImage is a URL or not. If this is the first case, it means that the image should be
45
+ // created by the installer from the URL. Otherwise, it means that we are given the name of the pre-created
46
+ // Glance image, which we should use for instances.
47
+ imageName , isURL := rhcos .GenerateOpenStackImageName (baseImage , infraID )
48
+ cfg .BaseImageName = imageName
49
+ if isURL {
50
+ // Valid URL -> use baseImage as a URL that will be used to create new Glance image with name "<infraID>-rhcos".
51
+ cfg .BaseImageURL = baseImage
52
+ } else {
53
+ // Not a URL -> use baseImage value as a Glance image name.
54
+
55
+ // TODO(mfedosin): add validations that this image exists and there are no other images with this name.
56
+ }
57
+
39
58
if masterConfig .RootVolume != nil {
40
59
cfg .RootVolumeSize = masterConfig .RootVolume .Size
41
60
cfg .RootVolumeType = masterConfig .RootVolume .VolumeType
0 commit comments