Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backups absent permissions #760

Merged
merged 1 commit into from
Dec 10, 2024
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
20 changes: 5 additions & 15 deletions api/v1alpha1/backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,8 @@ import (

// BackupSpec defines the desired state of Backup
type BackupSpec struct {
// +kubebuilder:default="0 */6 * * *"

// Schedule is a Cron expression defining when to run the Backup.
// A shortcut instead of filling the .customSchedule field up.
// Default value is to backup every 6 hours.
// If both this field and the .customSchedule field
// are given, the schedule from the latter will be utilized.
Schedule string `json:"schedule"`

// Oneshot indicates whether the Backup should not be scheduled
// and rather created immediately and only once.
// If set to true, the .schedule field is ignored.
// If set to true and the .customSchedule field is given,
// the .spec.template from the latter will be utilized,
// the HMC-required options still might override or precede the options
// from the field.
Oneshot bool `json:"oneshot,omitempty"`
}

Expand All @@ -46,8 +32,12 @@ type BackupStatus struct {
// Reference to the underlying Velero object being managed.
// Might be either Velero Backup or Schedule.
Reference *corev1.ObjectReference `json:"reference,omitempty"`
// Status of the Velero Schedule if .spec.oneshot is set to false.
// Status of the Velero Schedule for the Management scheduled backups.
// Always absent for the Backups with the .spec.oneshot set to true.
Schedule *velerov1.ScheduleStatus `json:"schedule,omitempty"`
// NextAttempt indicates the time when the next scheduled backup will be performed.
// Always absent for the Backups with the .spec.oneshot set to true.
NextAttempt *metav1.Time `json:"nextAttempt,omitempty"`
// Last Velero Backup that has been created.
LastBackup *velerov1.BackupStatus `json:"lastBackup,omitempty"`
}
Expand Down
6 changes: 6 additions & 0 deletions api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ type Core struct {

// ManagementBackup enables a feature to backup HMC objects into a cloud.
type ManagementBackup struct {
// +kubebuilder:default="0 */6 * * *"

// Schedule is a Cron expression defining when to run the scheduled Backup.
// Default value is to backup every 6 hours.
Schedule string `json:"schedule,omitempty"`

// +kubebuilder:default=false

// Flag to indicate whether the backup feature is enabled.
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

15 changes: 8 additions & 7 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "MultiClusterService")
os.Exit(1)
}
if err = (&controller.BackupReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Backup")
os.Exit(1)
}
// TODO (zerospiel): disabled until the #605
// if err = (&controller.BackupReconciler{
// Client: mgr.GetClient(),
// Scheme: mgr.GetScheme(),
// }).SetupWithManager(mgr); err != nil {
// setupLog.Error(err, "unable to create controller", "controller", "Backup")
// os.Exit(1)
// }
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,7 @@ spec:
description: |-
Oneshot indicates whether the Backup should not be scheduled
and rather created immediately and only once.
If set to true, the .schedule field is ignored.
If set to true and the .customSchedule field is given,
the .spec.template from the latter will be utilized,
the HMC-required options still might override or precede the options
from the field.
type: boolean
schedule:
default: 0 */6 * * *
description: |-
Schedule is a Cron expression defining when to run the Backup.
A shortcut instead of filling the .customSchedule field up.
Default value is to backup every 6 hours.
If both this field and the .customSchedule field
are given, the schedule from the latter will be utilized.
type: string
required:
- schedule
type: object
status:
description: BackupStatus defines the observed state of Backup
Expand Down Expand Up @@ -210,6 +194,12 @@ spec:
file in object storage.
type: integer
type: object
nextAttempt:
description: |-
NextAttempt indicates the time when the next scheduled backup will be performed.
Always absent for the Backups with the .spec.oneshot set to true.
format: date-time
type: string
reference:
description: |-
Reference to the underlying Velero object being managed.
Expand Down Expand Up @@ -256,8 +246,9 @@ spec:
type: object
x-kubernetes-map-type: atomic
schedule:
description: Status of the Velero Schedule if .spec.oneshot is set
to false.
description: |-
Status of the Velero Schedule for the Management scheduled backups.
Always absent for the Backups with the .spec.oneshot set to true.
properties:
lastBackup:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ spec:

[Velero]: https://velero.io
type: boolean
schedule:
default: 0 */6 * * *
description: |-
Schedule is a Cron expression defining when to run the scheduled Backup.
Default value is to backup every 6 hours.
type: string
required:
- enabled
type: object
Expand Down
19 changes: 19 additions & 0 deletions templates/provider/hmc/templates/rbac/controller/roles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,25 @@ rules:
resources:
- secrets
verbs: {{ include "rbac.viewerVerbs" . | nindent 4 }}
- apiGroups:
- hmc.mirantis.com
resources:
- backups
verbs: {{ include "rbac.editorVerbs" . | nindent 4 }}
- apiGroups:
- hmc.mirantis.com
resources:
- backups/finalizers
verbs:
- update
- apiGroups:
- hmc.mirantis.com
resources:
- backups/status
verbs:
- get
- patch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
Loading