From ba244178039074525e8b0208278031169114aa82 Mon Sep 17 00:00:00 2001 From: Luca Miccini Date: Thu, 12 Sep 2024 09:35:28 +0200 Subject: [PATCH] Rename InstanceHA to InstanceHa and add image to configmap This commits renames InstanceHA to InstanceHa to adhere to the openstackversion naming (casing) scheme. It also adds the Infra InstanceHa image to a dedicated configmap so that the infra-operator can watch it and react to changes. --- ....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..665ff2def 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..81eab2b18 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..c0617e70e 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..9e99e619f 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..8dd932a71 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..665ff2def 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..81eab2b18 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..732bbecd1 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..e14b52b2c --- /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..1054e9208 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),