From 63a1d2d91e5ca0b748a9c73c15a7bd11cde626d2 Mon Sep 17 00:00:00 2001 From: Luca Miccini Date: Wed, 4 Sep 2024 16:38:57 +0200 Subject: [PATCH] add instance ha cm to set container image --- ....openstack.org_openstackcontrolplanes.yaml | 2 + .../core.openstack.org_openstackversions.yaml | 6 +++ apis/core/v1beta1/conditions.go | 9 ++++ apis/core/v1beta1/openstackversion_types.go | 1 + apis/core/v1beta1/zz_generated.deepcopy.go | 5 ++ ....openstack.org_openstackcontrolplanes.yaml | 2 + .../core.openstack.org_openstackversions.yaml | 6 +++ config/default/manager_default_images.yaml | 2 + .../core/openstackcontrolplane_controller.go | 7 +++ hack/export_related_images.sh | 1 + pkg/openstack/instanceha.go | 54 +++++++++++++++++++ pkg/openstack/version.go | 1 + 12 files changed, 96 insertions(+) create mode 100644 pkg/openstack/instanceha.go diff --git a/apis/bases/core.openstack.org_openstackcontrolplanes.yaml b/apis/bases/core.openstack.org_openstackcontrolplanes.yaml index 6f867b75b..9281276b7 100644 --- a/apis/bases/core.openstack.org_openstackcontrolplanes.yaml +++ b/apis/bases/core.openstack.org_openstackcontrolplanes.yaml @@ -17611,6 +17611,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: diff --git a/apis/bases/core.openstack.org_openstackversions.yaml b/apis/bases/core.openstack.org_openstackversions.yaml index 48bf17ccc..b617f16a2 100644 --- a/apis/bases/core.openstack.org_openstackversions.yaml +++ b/apis/bases/core.openstack.org_openstackversions.yaml @@ -125,6 +125,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: @@ -328,6 +330,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: @@ -502,6 +506,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: diff --git a/apis/core/v1beta1/conditions.go b/apis/core/v1beta1/conditions.go index c04b362dc..1cca2ec62 100644 --- a/apis/core/v1beta1/conditions.go +++ b/apis/core/v1beta1/conditions.go @@ -146,6 +146,9 @@ const ( // OpenStackControlPlaneTestCMReadyCondition Status=True condition which indicates if Test operator CM is ready OpenStackControlPlaneTestCMReadyCondition condition.Type = "OpenStackControlPlaneTestCMReadyCondition" + + // OpenStackControlPlaneInstanceHACMReadyCondition Status=True condition which indicates if InstanceHA CM is ready + OpenStackControlPlaneInstanceHACMReadyCondition condition.Type = "OpenStackControlPlaneInstanceHACMReadyCondition" ) // Common Messages used by API objects. @@ -456,6 +459,12 @@ const ( // OpenStackControlPlaneTestCMReadyMessage OpenStackControlPlaneTestCMReadyMessage = "OpenStackControlPlane Test Operator CM is available" + + // OpenStackControlPlaneInstanceHACMReadyErrorMessage + OpenStackControlPlaneInstanceHACMReadyErrorMessage = "OpenStackControlPlane InstanceHA CM error occured %s" + + // OpenStackControlPlaneInstanceHACMReadyMessage + OpenStackControlPlaneInstanceHACMReadyMessage = "OpenStackControlPlane InstanceHA CM is available" ) // Version Conditions used by API objects. diff --git a/apis/core/v1beta1/openstackversion_types.go b/apis/core/v1beta1/openstackversion_types.go index b13c809a3..1058c8d95 100644 --- a/apis/core/v1beta1/openstackversion_types.go +++ b/apis/core/v1beta1/openstackversion_types.go @@ -114,6 +114,7 @@ type ContainerTemplate struct { InfraDnsmasqImage *string `json:"infraDnsmasqImage,omitempty"` InfraMemcachedImage *string `json:"infraMemcachedImage,omitempty"` InfraRedisImage *string `json:"infraRedisImage,omitempty"` + InfraInstanceHAImage *string `json:"infraInstanceHAImage,omitempty"` IronicAPIImage *string `json:"ironicAPIImage,omitempty"` IronicConductorImage *string `json:"ironicConductorImage,omitempty"` IronicInspectorImage *string `json:"ironicInspectorImage,omitempty"` diff --git a/apis/core/v1beta1/zz_generated.deepcopy.go b/apis/core/v1beta1/zz_generated.deepcopy.go index 2269aff10..b558f2595 100644 --- a/apis/core/v1beta1/zz_generated.deepcopy.go +++ b/apis/core/v1beta1/zz_generated.deepcopy.go @@ -653,6 +653,11 @@ func (in *ContainerTemplate) DeepCopyInto(out *ContainerTemplate) { *out = new(string) **out = **in } + if in.InfraInstanceHAImage != nil { + in, out := &in.InfraInstanceHAImage, &out.InfraInstanceHAImage + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ContainerTemplate. diff --git a/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml b/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml index 6f867b75b..9281276b7 100644 --- a/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml +++ b/config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml @@ -17611,6 +17611,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: diff --git a/config/crd/bases/core.openstack.org_openstackversions.yaml b/config/crd/bases/core.openstack.org_openstackversions.yaml index 48bf17ccc..b617f16a2 100644 --- a/config/crd/bases/core.openstack.org_openstackversions.yaml +++ b/config/crd/bases/core.openstack.org_openstackversions.yaml @@ -125,6 +125,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: @@ -328,6 +330,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: @@ -502,6 +506,8 @@ spec: type: string infraDnsmasqImage: type: string + infraInstanceHAImage: + type: string infraMemcachedImage: type: string infraRedisImage: diff --git a/config/default/manager_default_images.yaml b/config/default/manager_default_images.yaml index fccaa17a0..6d007b7d2 100644 --- a/config/default/manager_default_images.yaml +++ b/config/default/manager_default_images.yaml @@ -97,6 +97,8 @@ spec: value: quay.io/podified-antelope-centos9/openstack-memcached:current-podified - name: RELATED_IMAGE_INFRA_REDIS_IMAGE_URL_DEFAULT value: quay.io/podified-antelope-centos9/openstack-redis:current-podified + - name: RELATED_IMAGE_INFRA_INSTANCE_HA_IMAGE_URL_DEFAULT + value: quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified - name: RELATED_IMAGE_IRONIC_API_IMAGE_URL_DEFAULT value: quay.io/podified-antelope-centos9/openstack-ironic-api:current-podified - name: RELATED_IMAGE_IRONIC_CONDUCTOR_IMAGE_URL_DEFAULT diff --git a/controllers/core/openstackcontrolplane_controller.go b/controllers/core/openstackcontrolplane_controller.go index 9a1a2e590..3f7a42b6c 100644 --- a/controllers/core/openstackcontrolplane_controller.go +++ b/controllers/core/openstackcontrolplane_controller.go @@ -452,6 +452,13 @@ func (r *OpenStackControlPlaneReconciler) reconcileNormal(ctx context.Context, i return ctrlResult, nil } + ctrlResult, err = openstack.ReconcileInstanceHA(ctx, instance, version, helper) + if err != nil { + return ctrl.Result{}, err + } else if (ctrlResult != ctrl.Result{}) { + return ctrlResult, nil + } + return ctrl.Result{}, nil } diff --git a/hack/export_related_images.sh b/hack/export_related_images.sh index d32b33b7d..ccc0fd980 100755 --- a/hack/export_related_images.sh +++ b/hack/export_related_images.sh @@ -7,6 +7,7 @@ export RELATED_IMAGE_KEYSTONE_API_IMAGE_URL_DEFAULT=quay.io/podified-antelope-ce export RELATED_IMAGE_MARIADB_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-mariadb:current-podified export RELATED_IMAGE_INFRA_MEMCACHED_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-memcached:current-podified export RELATED_IMAGE_INFRA_REDIS_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-redis:current-podified +export RELATED_IMAGE_INFRA_INSTANCE_HA_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-openstackclient:current-podified export RELATED_IMAGE_ANSIBLEEE_IMAGE_URL_DEFAULT=quay.io/openstack-k8s-operators/openstack-ansibleee-runner:current-podified export RELATED_IMAGE_NOVA_API_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-nova-api:current-podified export RELATED_IMAGE_NOVA_CONDUCTOR_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-nova-conductor:current-podified diff --git a/pkg/openstack/instanceha.go b/pkg/openstack/instanceha.go new file mode 100644 index 000000000..af0a427f0 --- /dev/null +++ b/pkg/openstack/instanceha.go @@ -0,0 +1,54 @@ +package openstack + +import ( + "context" + + "github.com/openstack-k8s-operators/lib-common/modules/common/condition" + "github.com/openstack-k8s-operators/lib-common/modules/common/configmap" + "github.com/openstack-k8s-operators/lib-common/modules/common/helper" + "github.com/openstack-k8s-operators/lib-common/modules/common/util" + + corev1beta1 "github.com/openstack-k8s-operators/openstack-operator/apis/core/v1beta1" + ctrl "sigs.k8s.io/controller-runtime" +) + +const ( + InstanceHAConfigMap = "infra-instanceha-config" + InstanceHAImageKey = "instanceha-image" +) + +func ReconcileInstanceHA(ctx context.Context, instance *corev1beta1.OpenStackControlPlane, version *corev1beta1.OpenStackVersion, helper *helper.Helper) (ctrl.Result, error) { + missingImageDefault := "" + customData := map[string]string{ + InstanceHAImageKey: *getImg(version.Status.ContainerImages.InfraInstanceHAImage, &missingImageDefault), + } + + cms := []util.Template{ + { + Name: InstanceHAConfigMap, + Namespace: instance.Namespace, + InstanceType: instance.Kind, + Labels: nil, + ConfigOptions: nil, + CustomData: customData, + }, + } + + if err := configmap.EnsureConfigMaps(ctx, helper, instance, cms, nil); err != nil { + instance.Status.Conditions.Set(condition.FalseCondition( + corev1beta1.OpenStackControlPlaneInstanceHACMReadyCondition, + condition.ErrorReason, + condition.SeverityWarning, + corev1beta1.OpenStackControlPlaneInstanceHACMReadyErrorMessage, + err.Error())) + + return ctrl.Result{}, err + } + + instance.Status.Conditions.Set(condition.TrueCondition( + corev1beta1.OpenStackControlPlaneInstanceHACMReadyCondition, + corev1beta1.OpenStackControlPlaneInstanceHACMReadyMessage, + )) + + return ctrl.Result{}, nil +} diff --git a/pkg/openstack/version.go b/pkg/openstack/version.go index 70de6946c..698bd5819 100644 --- a/pkg/openstack/version.go +++ b/pkg/openstack/version.go @@ -126,6 +126,7 @@ func GetContainerImages(defaults *corev1beta1.ContainerDefaults, instance corev1 InfraDnsmasqImage: getImg(instance.Spec.CustomContainerImages.InfraDnsmasqImage, defaults.InfraDnsmasqImage), InfraMemcachedImage: getImg(instance.Spec.CustomContainerImages.InfraMemcachedImage, defaults.InfraMemcachedImage), InfraRedisImage: getImg(instance.Spec.CustomContainerImages.InfraRedisImage, defaults.InfraRedisImage), + InfraInstanceHAImage: getImg(instance.Spec.CustomContainerImages.InfraInstanceHAImage, defaults.InfraInstanceHAImage), IronicAPIImage: getImg(instance.Spec.CustomContainerImages.IronicAPIImage, defaults.IronicAPIImage), IronicConductorImage: getImg(instance.Spec.CustomContainerImages.IronicConductorImage, defaults.IronicConductorImage), IronicInspectorImage: getImg(instance.Spec.CustomContainerImages.IronicInspectorImage, defaults.IronicInspectorImage),