Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ resources:
kind: MariaDBAccount
path: github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1
version: v1beta1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: openstack.org
group: mariadb
kind: GaleraBackup
path: github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1
version: v1beta1
version: "3"
146 changes: 146 additions & 0 deletions api/bases/mariadb.openstack.org_galerabackups.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
name: galerabackups.mariadb.openstack.org
spec:
group: mariadb.openstack.org
names:
kind: GaleraBackup
listKind: GaleraBackupList
plural: galerabackups
singular: galerabackup
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: Ready
jsonPath: .status.conditions[0].status
name: Ready
type: string
- description: Message
jsonPath: .status.conditions[0].message
name: Message
type: string
name: v1beta1
schema:
openAPIV3Schema:
description: GaleraBackup is the Schema for the galerabackups API
properties:
apiVersion:
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
type: object
spec:
description: GaleraBackupSpec defines the desired state of GaleraBackup
properties:
databaseInstance:
description: Galera cluster to backup
type: string
retention:
description: Time duration after which old backups must be reclaimed
on disk
type: string
schedule:
default: '@hourly'
description: The schedule in Cron format
type: string
storageClass:
description: Storage volume for backup data
type: string
storageRequest:
description: Storage Request for backup data
type: string
transferStorage:
description: Configuration of storage used for intermediate data transfer
properties:
storageClass:
description: Storage volume for backup data
type: string
storageRequest:
description: Storage Request for backup data
type: string
required:
- storageRequest
type: object
required:
- schedule
type: object
status:
description: GaleraBackupStatus defines the observed state of GaleraBackup
properties:
conditions:
description: Deployment Conditions
items:
description: Condition defines an observation of a API resource
operational state.
properties:
lastTransitionTime:
description: |-
Last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when
the API field changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase.
type: string
severity:
description: |-
Severity provides a classification of Reason code, so the current situation is immediately
understandable and could act accordingly.
It is meant for situations where Status=False and it should be indicated if it is just
informational, warning (next reconciliation might fix it) or an error (e.g. DB create issue
and no actions to automatically resolve the issue can/should be done).
For conditions where Status=Unknown or Status=True the Severity should be SeverityNone.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
hash:
additionalProperties:
type: string
description: Map of hashes to track input changes
type: object
observedGeneration:
description: |-
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)
format: int64
type: integer
type: object
type: object
served: true
storage: true
subresources:
status: {}
37 changes: 37 additions & 0 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (

// MariaDB Condition Types used by API objects.
const (
// MariaDBCreatedCondition Status=True indicates if there a Galera CR already exists
MariaDBResourceExistsCondition condition.Type = "MariaDBResourceExists"

// MariaDBInitializedCondition Status=True condition which indicates if the MariaDB dbinit has completed
MariaDBInitializedCondition condition.Type = "MariaDBInitialized"

Expand All @@ -35,6 +38,9 @@ const (

// MariaDB Reasons used by API objects.
const (
// ReasonResourceNotFound - Galera CR not found
ReasonResourceNotFound condition.Reason = "Galera CR not found"

// ReasonDBError - DB error
ReasonDBError condition.Reason = "DatabaseError"
// ReasonDBPatchError - new resource set to reason Init
Expand All @@ -57,6 +63,10 @@ const (
//
// MariaDBReady condition messages
//
MariaDBResourceInitMessage = "MariaDB / Galera resource not yet available"

MariaDBResourceExistsMessage = "MariaDB / Galera resource exists"

// MariaDBInitializedInitMessage
MariaDBInitializedInitMessage = "MariaDB dbinit not started"

Expand Down Expand Up @@ -98,3 +108,30 @@ const (

MariaDBAccountReadyForDeleteMessage = "MariaDBAccount ready for delete"
)

// GaleraBackup Condition Types used by API objects.
const (
PersistentVolumeClaimReadyCondition condition.Type = "PersistentVolumeClaimReady"

CronjobReadyCondition condition.Type = "CronjobReady"
)

const (
// PersistentVolumeClaimReadyErrorMessage
PersistentVolumeClaimReadyErrorMessage = "PersistentVolumeClaim error occurred %s"

// PersistentVolumeClaimReadyInitMessage
PersistentVolumeClaimReadyInitMessage = "PersistentVolumeClaim not created"

// PersistentVolumeClaimReadyMessage
PersistentVolumeClaimReadyMessage = "PersistentVolumeClaim created"

// CronjobReadyErrorMessage
CronjobReadyErrorMessage = "Cronjob error occurred %s"

// CronjobReadyInitMessage
CronjobReadyInitMessage = "Cronjob not created"

// CronjobReadyMessage
CronjobReadyMessage = "Cronjob created"
)
107 changes: 107 additions & 0 deletions api/v1beta1/galerabackup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright 2022.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1beta1

import (
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GaleraBackupSpec defines the desired state of GaleraBackup
type GaleraBackupSpec struct {
// Galera cluster to backup
DatabaseInstance string `json:"databaseInstance,omitempty"`
// Storage volume for backup data
StorageClass string `json:"storageClass,omitempty"`
// Storage Request for backup data
StorageRequest string `json:"storageRequest,omitempty"`
// Configuration of storage used for intermediate data transfer
TransferStorage *GaleraBackupTransferStorageSpec `json:"transferStorage,omitempty"`
// The schedule in Cron format
// +kubebuilder:default="@hourly"
Schedule string `json:"schedule"`
// Time duration after which old backups must be reclaimed on disk
// +optional
Retention *metav1.Duration `json:"retention,omitempty"`
}

type GaleraBackupTransferStorageSpec struct {
// Storage volume for backup data
StorageClass string `json:"storageClass,omitempty"`
// Storage Request for backup data
StorageRequest string `json:"storageRequest"`
}

// GaleraBackupStatus defines the observed state of GaleraBackup
type GaleraBackupStatus struct {
// Map of hashes to track input changes
Hash map[string]string `json:"hash,omitempty"`
// Deployment Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`
// 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)
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[0].status",description="Ready"
// +kubebuilder:printcolumn:name="Message",type="string",JSONPath=".status.conditions[0].message",description="Message"

// GaleraBackup is the Schema for the galerabackups API
type GaleraBackup struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec GaleraBackupSpec `json:"spec,omitempty"`
Status GaleraBackupStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// GaleraBackupList contains a list of GaleraBackup
type GaleraBackupList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []GaleraBackup `json:"items"`
}

func init() {
SchemeBuilder.Register(&GaleraBackup{}, &GaleraBackupList{})
}

// // IsReady - returns true if service is ready to serve requests
// func (instance Galera) IsReady() bool {
// return instance.Status.Conditions.IsTrue(condition.DeploymentReadyCondition)
// }

// RbacConditionsSet - sets the conditions for the rbac object
func (instance GaleraBackup) RbacConditionsSet(c *condition.Condition) {
instance.Status.Conditions.Set(c)
}

// RbacNamespace - returns the namespace name
func (instance GaleraBackup) RbacNamespace() string {
return instance.Namespace
}

// RbacResourceName - return the name to be used for rbac objects (serviceaccount, role, rolebinding)
func (instance GaleraBackup) RbacResourceName() string {
return "galerabackup-" + instance.Name
}
Loading