Skip to content

Commit

Permalink
[CRD]Add DB purge API to NovaCell
Browse files Browse the repository at this point in the history
We will have one CronJob per cell to do db archiving and purging per
cell.

Pointer types are needed for nested struct field defaulting.

Operator-lint update is needed to handle the pointer types properly in
the omitempty check and to handle an edge case with generic types.

Implements: OSPRH-104
  • Loading branch information
gibizer committed Feb 20, 2024
1 parent 99f6ac4 commit 3fb6584
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ golint: get-ci-tools

.PHONY: operator-lint
operator-lint: $(LOCALBIN) gowork ## Runs operator-lint
GOBIN=$(LOCALBIN) go install github.com/gibizer/operator-lint@v0.3.0
GOBIN=$(LOCALBIN) go install github.com/gibizer/operator-lint@v0.5.0
go vet -vettool=$(LOCALBIN)/operator-lint ./... ./api/...

.PHONY: gowork
Expand Down
22 changes: 22 additions & 0 deletions api/bases/nova.openstack.org_nova.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,28 @@ spec:
type: object
type: object
type: object
dbPurge:
description: DBPurge defines the parameters for the DB archiving
and purging cron job
properties:
archiveAge:
default: 30
description: ArchiveAge defines the minimuma age of the
records in days that can be moved to the shadow tables.
minimum: 1
type: integer
purgeAge:
default: 90
description: PurgeAge defines the minimum age of the records
in days that can be deleted from the shadow tables
minimum: 1
type: integer
schedule:
default: 0 0 * * *
description: Schedule defines when to run the DB maintenance
job in a cron format. By default it runs every midnight.
type: string
type: object
hasAPIAccess:
description: HasAPIAccess defines if this Cell is configured
to have access to the API DB and message bus.
Expand Down
22 changes: 22 additions & 0 deletions api/bases/nova.openstack.org_novacells.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ spec:
type: object
type: object
type: object
dbPurge:
description: DBPurge defines the parameters for the DB archiving and
purging cron job
properties:
archiveAge:
default: 30
description: ArchiveAge defines the minimuma age of the records
in days that can be moved to the shadow tables.
minimum: 1
type: integer
purgeAge:
default: 90
description: PurgeAge defines the minimum age of the records in
days that can be deleted from the shadow tables
minimum: 1
type: integer
schedule:
default: 0 0 * * *
description: Schedule defines when to run the DB maintenance job
in a cron format. By default it runs every midnight.
type: string
type: object
keystoneAuthURL:
description: KeystoneAuthURL - the URL that the service in the cell
can use to talk to keystone
Expand Down
32 changes: 32 additions & 0 deletions api/v1beta1/novacell_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ type NovaCellTemplate struct {
// PasswordSelectors - Selectors to identify the DB passwords from the
// Secret
PasswordSelectors CellPasswordSelector `json:"passwordSelectors"`

// +kubebuilder:validation:Optional
// DBPurge defines the parameters for the DB archiving and purging cron job
DBPurge NovaCellDBPurge `json:"dbPurge"`
}

// NovaCellSpec defines the desired state of NovaCell
Expand Down Expand Up @@ -179,6 +183,34 @@ type NovaCellSpec struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS tls.Ca `json:"tls,omitempty"`

// +kubebuilder:validation:Optional
// DBPurge defines the parameters for the DB archiving and purging cron job
DBPurge NovaCellDBPurge `json:"dbPurge"`
}

// NovaCellDBPurge defines the parameters for the DB archiving and purging
// cron job
type NovaCellDBPurge struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default="0 0 * * *"
// Schedule defines when to run the DB maintenance job in a cron format.
// By default it runs every midnight.
Schedule *string `json:"schedule"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=30
// +kubebuilder:validation:Minimum=1
// ArchiveAge defines the minimuma age of the records in days that can be
// moved to the shadow tables.
ArchiveAge *int `json:"archiveAge"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=90
// +kubebuilder:validation:Minimum=1
// PurgeAge defines the minimum age of the records in days that can be
// deleted from the shadow tables
PurgeAge *int `json:"purgeAge"`
}

// NovaCellStatus defines the observed state of NovaCell
Expand Down
32 changes: 32 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions config/crd/bases/nova.openstack.org_nova.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,28 @@ spec:
type: object
type: object
type: object
dbPurge:
description: DBPurge defines the parameters for the DB archiving
and purging cron job
properties:
archiveAge:
default: 30
description: ArchiveAge defines the minimuma age of the
records in days that can be moved to the shadow tables.
minimum: 1
type: integer
purgeAge:
default: 90
description: PurgeAge defines the minimum age of the records
in days that can be deleted from the shadow tables
minimum: 1
type: integer
schedule:
default: 0 0 * * *
description: Schedule defines when to run the DB maintenance
job in a cron format. By default it runs every midnight.
type: string
type: object
hasAPIAccess:
description: HasAPIAccess defines if this Cell is configured
to have access to the API DB and message bus.
Expand Down
22 changes: 22 additions & 0 deletions config/crd/bases/nova.openstack.org_novacells.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ spec:
type: object
type: object
type: object
dbPurge:
description: DBPurge defines the parameters for the DB archiving and
purging cron job
properties:
archiveAge:
default: 30
description: ArchiveAge defines the minimuma age of the records
in days that can be moved to the shadow tables.
minimum: 1
type: integer
purgeAge:
default: 90
description: PurgeAge defines the minimum age of the records in
days that can be deleted from the shadow tables
minimum: 1
type: integer
schedule:
default: 0 0 * * *
description: Schedule defines when to run the DB maintenance job
in a cron format. By default it runs every midnight.
type: string
type: object
keystoneAuthURL:
description: KeystoneAuthURL - the URL that the service in the cell
can use to talk to keystone
Expand Down
12 changes: 12 additions & 0 deletions test/functional/nova_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
. "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"

condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
Expand Down Expand Up @@ -135,6 +136,14 @@ var _ = Describe("Nova controller", func() {
Expect(instance.Status.RegisteredCells).To(BeEmpty())
})

It("defaults Spec fields", func() {
nova := GetNova(novaNames.NovaName)
cell0Template := nova.Spec.CellTemplates["cell0"]
Expect(cell0Template.DBPurge.Schedule).To(Equal(ptr.To("0 0 * * *")))
Expect(cell0Template.DBPurge.ArchiveAge).To(Equal(ptr.To(30)))
Expect(cell0Template.DBPurge.PurgeAge).To(Equal(ptr.To(90)))
})

It("registers nova service to keystone", func() {
// assert that the KeystoneService for nova is created
keystone.GetKeystoneService(novaNames.KeystoneServiceName)
Expand Down Expand Up @@ -223,6 +232,9 @@ var _ = Describe("Nova controller", func() {
cell := GetNovaCell(cell0.CellCRName)
Expect(cell.Spec.ServiceUser).To(Equal("nova"))
Expect(cell.Spec.ServiceAccount).To(Equal(novaNames.ServiceAccountName.Name))
Expect(cell.Spec.DBPurge.Schedule).To(Equal(ptr.To("0 0 * * *")))
Expect(cell.Spec.DBPurge.ArchiveAge).To(Equal(ptr.To(30)))
Expect(cell.Spec.DBPurge.PurgeAge).To(Equal(ptr.To(90)))

conductor := GetNovaConductor(cell0.ConductorName)
Expect(conductor.Spec.ServiceUser).To(Equal("nova"))
Expand Down
7 changes: 7 additions & 0 deletions test/functional/novacell_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ var _ = Describe("NovaCell controller", func() {
)
})

It("defaults Spec fields", func() {
cell0 := GetNovaCell(cell0.CellCRName)
Expect(cell0.Spec.DBPurge.Schedule).To(Equal(ptr.To("0 0 * * *")))
Expect(cell0.Spec.DBPurge.ArchiveAge).To(Equal(ptr.To(30)))
Expect(cell0.Spec.DBPurge.PurgeAge).To(Equal(ptr.To(90)))
})

It("is not Ready", func() {
th.ExpectCondition(
cell0.CellCRName,
Expand Down

0 comments on commit 3fb6584

Please sign in to comment.