From 5fbbc0835ffa87d6cb72a8580c3cef84c871f430 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Tue, 17 Sep 2024 15:46:29 +0100 Subject: [PATCH] Use lib-common dojob on AEE Signed-off-by: Fabricio Aguiar --- ...ack.org_openstackdataplanedeployments.yaml | 10 ++ .../openstackdataplanedeployment_types.go | 12 ++ .../v1beta1/zz_generated.deepcopy.go | 7 + ...ack.org_openstackdataplanedeployments.yaml | 10 ++ docs/assemblies/ctlplane_resources.adoc | 140 ++++++++++++++++-- docs/assemblies/dataplane_resources.adoc | 10 ++ pkg/dataplane/util/ansible_execution.go | 31 ++-- ...tackdataplanedeployment_controller_test.go | 11 ++ 8 files changed, 208 insertions(+), 23 deletions(-) diff --git a/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml b/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml index e1cea05f8..403b30db0 100644 --- a/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml +++ b/apis/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml @@ -65,6 +65,12 @@ spec: type: string minItems: 1 type: array + preserveJobs: + default: true + enum: + - true + - false + type: boolean servicesOverride: items: type: string @@ -78,6 +84,10 @@ spec: rule: self == oldSelf status: properties: + ansibleEEHashes: + additionalProperties: + type: string + type: object conditions: items: properties: diff --git a/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go b/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go index cff88307e..4f062da84 100644 --- a/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go +++ b/apis/dataplane/v1beta1/openstackdataplanedeployment_types.go @@ -35,6 +35,12 @@ type OpenStackDataPlaneDeploymentSpec struct { // +operator-sdk:csv:customresourcedefinitions:type=spec,xDescriptors={"urn:alm:descriptor:com.tectonic.ui:number"} BackoffLimit *int32 `json:"backoffLimit,omitempty"` + // PreserveJobs - do not delete jobs after they finished e.g. to check logs + // PreserveJobs default: true + // +kubebuilder:validation:Enum:=true;false + // +kubebuilder:default:=true + PreserveJobs bool `json:"preserveJobs,omitempty"` + // AnsibleTags for ansible execution // +kubebuilder:validation:Optional AnsibleTags string `json:"ansibleTags,omitempty"` @@ -68,6 +74,9 @@ type OpenStackDataPlaneDeploymentStatus struct { // NodeSetConditions NodeSetConditions map[string]condition.Conditions `json:"nodeSetConditions,omitempty" optional:"true"` + // AnsibleEEHashes + AnsibleEEHashes map[string]string `json:"ansibleEEHashes,omitempty" optional:"true"` + // ConfigMapHashes ConfigMapHashes map[string]string `json:"configMapHashes,omitempty" optional:"true"` @@ -166,6 +175,9 @@ func (instance *OpenStackDataPlaneDeployment) InitHashesAndImages() { if instance.Status.NodeSetHashes == nil { instance.Status.NodeSetHashes = make(map[string]string) } + if instance.Status.AnsibleEEHashes == nil { + instance.Status.AnsibleEEHashes = make(map[string]string) + } if instance.Status.ContainerImages == nil { instance.Status.ContainerImages = make(map[string]string) } diff --git a/apis/dataplane/v1beta1/zz_generated.deepcopy.go b/apis/dataplane/v1beta1/zz_generated.deepcopy.go index 22a535f39..6b5dd4c34 100644 --- a/apis/dataplane/v1beta1/zz_generated.deepcopy.go +++ b/apis/dataplane/v1beta1/zz_generated.deepcopy.go @@ -380,6 +380,13 @@ func (in *OpenStackDataPlaneDeploymentStatus) DeepCopyInto(out *OpenStackDataPla (*out)[key] = outVal } } + if in.AnsibleEEHashes != nil { + in, out := &in.AnsibleEEHashes, &out.AnsibleEEHashes + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.ConfigMapHashes != nil { in, out := &in.ConfigMapHashes, &out.ConfigMapHashes *out = make(map[string]string, len(*in)) diff --git a/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml b/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml index e1cea05f8..403b30db0 100644 --- a/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml +++ b/config/crd/bases/dataplane.openstack.org_openstackdataplanedeployments.yaml @@ -65,6 +65,12 @@ spec: type: string minItems: 1 type: array + preserveJobs: + default: true + enum: + - true + - false + type: boolean servicesOverride: items: type: string @@ -78,6 +84,10 @@ spec: rule: self == oldSelf status: properties: + ansibleEEHashes: + additionalProperties: + type: string + type: object conditions: items: properties: diff --git a/docs/assemblies/ctlplane_resources.adoc b/docs/assemblies/ctlplane_resources.adoc index 20e3720ff..11aefccbf 100644 --- a/docs/assemblies/ctlplane_resources.adoc +++ b/docs/assemblies/ctlplane_resources.adoc @@ -41,6 +41,7 @@ * <> * <> * <> +* <> * <> * <> * <> @@ -1323,6 +1324,11 @@ OpenStackControlPlaneSpec defines the desired state of OpenStackControlPlane | <> | false +| redis +| Redis - Parameters related to the Redis service +| <> +| false + | openstackclient | OpenStackClient - Parameters related to the OpenStackClient | <> @@ -1518,6 +1524,27 @@ RabbitmqSection defines the desired state of RabbitMQ service <> +[#redissection] +==== RedisSection + +RedisSection defines the desired state of the Redis service + +|=== +| Field | Description | Scheme | Required + +| enabled +| Enabled - Whether the Redis service should be deployed and managed +| bool +| true + +| templates +| Templates - Overrides to use when creating the Redis Resources +| *map[string]redisv1.RedisSpecCore +| false +|=== + +<> + [#swiftsection] ==== SwiftSection @@ -1730,6 +1757,16 @@ ContainerImages - struct acts as the source of truth for container image URLs to |=== | Field | Description | Scheme | Required +| octaviaApacheImage +| +| *string +| false + +| ceilometerProxyImage +| +| *string +| false + | cinderVolumeImages | CinderVolumeImages custom Cinder Volume images for each backend (default Cinder volume image is stored 'default' key) | map[string]*string @@ -1782,7 +1819,7 @@ ContainerTemplate - struct that contains container image URLs for each service i | false | apacheImage -| +| this is shared by BaremetalOperator, OctaviaOperator, and TelemetryOperator | *string | false @@ -1826,11 +1863,6 @@ ContainerTemplate - struct that contains container image URLs for each service i | *string | false -| ceilometerProxyImage -| -| *string -| false - | cinderAPIImage | | *string @@ -1966,6 +1998,16 @@ ContainerTemplate - struct that contains container image URLs for each service i | *string | false +| infraRedisImage +| +| *string +| false + +| infraInstanceHaImage +| +| *string +| false + | ironicAPIImage | | *string @@ -4545,6 +4587,11 @@ DesignateAPISpecBase - | Override, provides the ability to override the generated manifest of several child resources. | <> | false + +| tls +| TLS - Parameters related to the TLS +| tls.API +| false |=== <> @@ -4778,6 +4825,11 @@ DesignateCentralSpecBase - | ServiceAccount - service account name used internally to provide Designate services the default SA name | string | true + +| tls +| TLS - Parameters related to the TLS +| tls.Ca +| false |=== <> @@ -4873,11 +4925,6 @@ DesignateMdnsSpecBase - |=== | Field | Description | Scheme | Required -| replicas -| Replicas - Designate Mdns Replicas -| *int32 -| true - | databaseHostname | DatabaseHostname - Designate Database Hostname | string @@ -4892,6 +4939,11 @@ DesignateMdnsSpecBase - | ServiceAccount - service account name used internally to provide Designate services the default SA name | string | true + +| tls +| TLS - Parameters related to the TLS +| tls.Ca +| false |=== <> @@ -4909,6 +4961,11 @@ DesignateMdnsStatus defines the observed state of DesignateMdns | int32 | false +| desiredNumberScheduled +| DesiredNumberScheduled - total number of the nodes which should be running Daemon +| int32 +| false + | hash | Map of hashes to track e.g. job status | map[string]string @@ -5006,6 +5063,11 @@ DesignateProducerSpec defines the desired state of DesignateProducer | ServiceAccount - service account name used internally to provide Designate services the default SA name | string | true + +| tls +| TLS - Parameters related to the TLS +| tls.Ca +| false |=== <> @@ -5224,6 +5286,11 @@ DesignateWorkerSpecBase - | ServiceAccount - service account name used internally to provide Designate services the default SA name | string | true + +| tls +| TLS - Parameters related to the TLS +| tls.Ca +| false |=== <> @@ -6738,6 +6805,11 @@ HorizonSpecBase - | ExtraMounts containing conf files | []<> | false + +| networkAttachments +| NetworkAttachments is a list of NetworkAttachment resource names to expose the services to the given network +| []string +| false |=== <> @@ -6774,6 +6846,11 @@ HorizonStatus defines the observed state of Horizon | ObservedGeneration - the most recent generation observed for this service. If the observed generation is less than the spec generation, then the controller has not processed the latest changes injected by the opentack-operator in the top-level CR (e.g. the ContainerImage) | int64 | false + +| networkAttachments +| NetworkAttachments status of the deployment pods +| map[string][]string +| false |=== <> @@ -10063,6 +10140,11 @@ PasswordSelector to identify the DB and AdminUser password from the Secret | MetadataSecret - the name of the field to get the metadata secret from the Secret | string | true + +| prefixMetadataCellsSecret +| prefixMetadataCellsSecret - the prefix name of the field to get the metadata secret from the Secret for cells. Vale of metadata_proxy_shared_secret information for the nova-metadata service. This secret is shared between nova and neutron ovn-metadata inside selected cell and if this is not defined the global metadata_proxy_shared_secret secret will be used +| string +| true |=== <> @@ -13412,6 +13494,11 @@ OpenStackProvisionServerSpec defines the desired state of OpenStackProvisionServ | string | true +| osImageDir +| OSImageDir - Directory on the container which holds the OS qcow2 image and checksum +| *string +| true + | osContainerImageUrl | OSContainerImageURL - Container image URL for init with the OS qcow2 image (osImage) | string @@ -13436,6 +13523,11 @@ OpenStackProvisionServerSpec defines the desired state of OpenStackProvisionServ | Resources - Compute Resources required by this provision server (Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | corev1.ResourceRequirements | false + +| preserveJobs +| PreserveJobs - do not delete jobs after they finished e.g. to check logs +| bool +| true |=== <> @@ -13472,6 +13564,21 @@ OpenStackProvisionServerStatus defines the observed state of OpenStackProvisionS | URL of provisioning image on underlying Apache web server | string | false + +| osImageChecksumFilename +| Filename of OSImage checksum +| string +| false + +| osImageChecksumType +| OSImage checksum type +| metal3v1.ChecksumType +| false + +| localImageChecksumUrl +| URL of provisioning image checksum on underlying Apache web server +| string +| false |=== <> @@ -15634,7 +15741,7 @@ Storage defines the options used for storage of metrics | Field | Description | Scheme | Required | strategy -| Strategy to use for storage. Can be "persistent" or empty, in which case a COO default is used +| Strategy to use for storage. Can be "persistent", "ephemeral" or empty, in which case a COO default is used | string | true @@ -15645,8 +15752,8 @@ Storage defines the options used for storage of metrics | persistent | Used to specify the options of persistent storage when strategy = "persistent" -| <> -| true +| *<> +| false |=== <> @@ -15980,6 +16087,11 @@ MemcachedSpecCore - this version is used by the OpenStackControlplane CR (no con | *int32 | true +| nodeSelector +| NodeSelector to target subset of worker nodes running this service +| map[string]string +| false + | tls | TLS settings for memcached service | tls.SimpleService diff --git a/docs/assemblies/dataplane_resources.adoc b/docs/assemblies/dataplane_resources.adoc index 8732e2376..3ea88ab5b 100644 --- a/docs/assemblies/dataplane_resources.adoc +++ b/docs/assemblies/dataplane_resources.adoc @@ -92,6 +92,11 @@ OpenStackDataPlaneDeploymentSpec defines the desired state of OpenStackDataPlane | *int32 | false +| preserveJobs +| PreserveJobs - do not delete jobs after they finished e.g. to check logs PreserveJobs default: true +| bool +| false + | ansibleTags | AnsibleTags for ansible execution | string @@ -138,6 +143,11 @@ OpenStackDataPlaneDeploymentStatus defines the observed state of OpenStackDataPl | map[string]condition.Conditions | false +| ansibleEEHashes +| AnsibleEEHashes +| map[string]string +| false + | configMapHashes | ConfigMapHashes | map[string]string diff --git a/pkg/dataplane/util/ansible_execution.go b/pkg/dataplane/util/ansible_execution.go index 798749f90..35bdbe3dc 100644 --- a/pkg/dataplane/util/ansible_execution.go +++ b/pkg/dataplane/util/ansible_execution.go @@ -22,6 +22,7 @@ import ( "fmt" "sort" "strings" + "time" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" @@ -29,9 +30,9 @@ import ( k8serrors "k8s.io/apimachinery/pkg/api/errors" apimachineryvalidation "k8s.io/apimachinery/pkg/util/validation" "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" "github.com/openstack-k8s-operators/lib-common/modules/common/helper" + job "github.com/openstack-k8s-operators/lib-common/modules/common/job" nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment" "github.com/openstack-k8s-operators/lib-common/modules/storage" dataplanev1 "github.com/openstack-k8s-operators/openstack-operator/apis/dataplane/v1beta1" @@ -83,22 +84,33 @@ func AnsibleExecution( ansibleEE.ExtraMounts = append(aeeSpec.ExtraMounts, []storage.VolMounts{ansibleEEMounts}...) ansibleEE.Env = aeeSpec.Env - aeeJob, err := ansibleEE.JobForOpenStackAnsibleEE(helper) + currentJobHash := deployment.Status.AnsibleEEHashes[ansibleEE.Name] + jobDef, err := ansibleEE.JobForOpenStackAnsibleEE(helper) if err != nil { return err } - // CreateOrPatch the AnsibleExecution Job - _, err = controllerutil.CreateOrPatch(ctx, helper.GetClient(), aeeJob, func() error { - // Set controller reference on the Job object - err := controllerutil.SetControllerReference( - helper.GetBeforeObject(), aeeJob, helper.GetScheme()) - return err - }) + ansibleeeJob := job.NewJob( + jobDef, + ansibleEE.Name, + ansibleEE.PreserveJobs, + time.Duration(5)*time.Second, + currentJobHash, + ) + + _, err = ansibleeeJob.DoJob( + ctx, + helper, + ) + if err != nil { return err } + if ansibleeeJob.HasChanged() { + deployment.Status.AnsibleEEHashes[ansibleEE.Name] = ansibleeeJob.GetHash() + } + return nil } @@ -193,6 +205,7 @@ func (a *EEJob) BuildAeeJobSpec( } a.BackoffLimit = deployment.Spec.BackoffLimit + a.PreserveJobs = deployment.Spec.PreserveJobs a.FormatAEECmdLineArguments(aeeSpec) a.FormatAEEExtraVars(aeeSpec, service, deployment, nodeSet) a.DetermineAeeImage(aeeSpec) diff --git a/tests/functional/dataplane/openstackdataplanedeployment_controller_test.go b/tests/functional/dataplane/openstackdataplanedeployment_controller_test.go index 81d596ad8..29abd907d 100644 --- a/tests/functional/dataplane/openstackdataplanedeployment_controller_test.go +++ b/tests/functional/dataplane/openstackdataplanedeployment_controller_test.go @@ -155,6 +155,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: nil, } @@ -349,6 +350,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: nil, } @@ -557,6 +559,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: nil, } @@ -669,6 +672,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: nil, } @@ -819,6 +823,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: nil, } @@ -980,6 +985,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: []string{dataplaneServiceName.Name, "duplicate-service"}, } @@ -1140,6 +1146,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: []string{"global-service"}, } @@ -1346,6 +1353,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: []string{"foo-service", "global-service", "foo-update-service"}, } @@ -1507,6 +1515,7 @@ var _ = Describe("Dataplane Deployment Test", func() { AnsibleLimit: "", AnsibleSkipTags: "", BackoffLimit: &DefaultBackoffLimit, + PreserveJobs: true, DeploymentRequeueTime: 15, ServicesOverride: nil, } @@ -1609,6 +1618,7 @@ var _ = Describe("Dataplane Deployment Test", func() { DeploymentRequeueTime: 15, ServicesOverride: nil, BackoffLimit: ptr.To(int32(6)), + PreserveJobs: true, } Expect(dataplaneDeploymentInstance.Spec).Should(Equal(expectedSpec)) }) @@ -1708,6 +1718,7 @@ var _ = Describe("Dataplane Deployment Test", func() { DeploymentRequeueTime: 15, ServicesOverride: nil, BackoffLimit: ptr.To(int32(6)), + PreserveJobs: true, } Expect(dataplaneDeploymentInstance.Spec).Should(Equal(expectedSpec)) })