From cddc84b77d1e3b21e308db6b286e69f63b788f50 Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Fri, 19 Nov 2021 13:14:51 +0000 Subject: [PATCH] Set osctlplane defaults for PhysNet and OpenStackRelease Set defaults via the new way for PhysNet and OpenStackRelease via the webhook.Defaulter. --- api/v1beta1/openstackcontrolplane_webhook.go | 22 +++++++++++++++++++ config/default/manager_default_images.yaml | 2 ++ ...irector_v1beta1_openstackcontrolplane.yaml | 2 +- main.go | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/api/v1beta1/openstackcontrolplane_webhook.go b/api/v1beta1/openstackcontrolplane_webhook.go index c7670a64..776ce0fc 100644 --- a/api/v1beta1/openstackcontrolplane_webhook.go +++ b/api/v1beta1/openstackcontrolplane_webhook.go @@ -30,11 +30,14 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" + + controlplane "github.com/openstack-k8s-operators/osp-director-operator/pkg/controlplane" ) // OpenStackControlPlaneDefaults - type OpenStackControlPlaneDefaults struct { OpenStackClientImageURL string + OpenStackRelease string } var openstackControlPlaneDefaults OpenStackControlPlaneDefaults @@ -117,4 +120,23 @@ func (r *OpenStackControlPlane) Default() { r.Spec.OpenStackClientImageURL = openstackControlPlaneDefaults.OpenStackClientImageURL } + // + // set default PhysNetworks name/prefix if non speficied + // + if len(r.Spec.PhysNetworks) == 0 { + r.Spec.PhysNetworks = []Physnet{ + { + Name: controlplane.DefaultOVNChassisPhysNetName, + MACPrefix: controlplane.DefaultOVNChassisPhysNetMACPrefix, + }, + } + } + + // + // set default OpenStackRelease + // + if r.Spec.OpenStackRelease == "" { + r.Spec.OpenStackRelease = openstackControlPlaneDefaults.OpenStackRelease + } + } diff --git a/config/default/manager_default_images.yaml b/config/default/manager_default_images.yaml index 43192163..a3dfa532 100644 --- a/config/default/manager_default_images.yaml +++ b/config/default/manager_default_images.yaml @@ -27,3 +27,5 @@ spec: value: quay.io/openstack-k8s-operators/provision-ip-discovery-agent:0.0.1 - name: APACHE_IMAGE_URL_DEFAULT value: registry.redhat.io/rhel8/httpd-24:latest + - name: OPENSTACK_RELEASE_DEFAULT + value: 16.2 diff --git a/config/samples/osp-director_v1beta1_openstackcontrolplane.yaml b/config/samples/osp-director_v1beta1_openstackcontrolplane.yaml index 11382d37..37943917 100644 --- a/config/samples/osp-director_v1beta1_openstackcontrolplane.yaml +++ b/config/samples/osp-director_v1beta1_openstackcontrolplane.yaml @@ -21,7 +21,7 @@ spec: - name: datacentre2 macPrefix: fa:16:3b virtualMachineRoles: - Controller: + controller: baseImageVolumeName: controller-base-img cores: 6 ctlplaneInterface: enp2s0 diff --git a/main.go b/main.go index 713152d9..8e4afea7 100644 --- a/main.go +++ b/main.go @@ -278,6 +278,7 @@ func main() { openstackControlPlaneDefaults := ospdirectorv1beta1.OpenStackControlPlaneDefaults{ OpenStackClientImageURL: os.Getenv("OPENSTACKCLIENT_IMAGE_URL_DEFAULT"), + OpenStackRelease: os.Getenv("OPENSTACK_RELEASE_DEFAULT"), } if err = (&ospdirectorv1beta1.OpenStackControlPlane{}).SetupWebhookWithManager(mgr, openstackControlPlaneDefaults); err != nil {