Skip to content

Commit

Permalink
Backup implementation
Browse files Browse the repository at this point in the history
* install velero via flux rather than code
* TODO: code removal due to the chart installation
* adjusted roles for the velero chart
* removed unnecessary controller values
* fix bug in providertemplates ctrl
  when ownerreferences are being updated
  but requeue is not set
* TODO: actually remove the code
* TODO: rework controller to ticker
  but watch the mgmt events and manage schedule
  instead of velero schedule
  • Loading branch information
zerospiel committed Jan 13, 2025
1 parent 1abb691 commit 86eb134
Show file tree
Hide file tree
Showing 25 changed files with 210 additions and 510 deletions.
4 changes: 2 additions & 2 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ resources:
crdVersion: v1
namespaced: true
controller: true
domain: hmc.mirantis.com
group: hmc.mirantis.com
domain: k0rdent.mirantis.com
group: k0rdent.mirantis.com
kind: ManagementBackup
path: github.com/K0rdent/kcm/api/v1alpha1
version: v1alpha1
Expand Down
10 changes: 5 additions & 5 deletions api/v1alpha1/management_backup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
)

const (
// Name to label most of the HMC-related components.
// Name to label most of the KCM-related components.
// Mostly utilized by the backup feature.
GenericComponentLabelName = "hmc.mirantis.com/component"
// Component label value for the HMC-related components.
GenericComponentLabelValueHMC = "hmc"
GenericComponentLabelName = "k0rdent.mirantis.com/component"
// Component label value for the KCM-related components.
GenericComponentLabelValueKCM = "kcm"
)

// ManagementBackupSpec defines the desired state of ManagementBackup
Expand Down Expand Up @@ -64,7 +64,7 @@ func (in *ManagementBackupStatus) GetScheduleCopy() velerov1.ScheduleStatus {

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,shortName=hmcbackup;mgmtbackup
// +kubebuilder:resource:scope=Cluster,shortName=kcmbackup;mgmtbackup
// +kubebuilder:printcolumn:name="NextBackup",type=string,JSONPath=`.status.nextAttempt`,description="Next scheduled attempt to back up",priority=0
// +kubebuilder:printcolumn:name="Status",type=string,JSONPath=`.status.schedule.phase`,description="Schedule phase",priority=0
// +kubebuilder:printcolumn:name="SinceLastBackup",type=date,JSONPath=`.status.schedule.lastBackup`,description="Time elapsed since last backup run",priority=1
Expand Down
2 changes: 1 addition & 1 deletion api/v1alpha1/management_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type Core struct {
CAPI Component `json:"capi,omitempty"`
}

// Backup enables a feature to backup HMC objects into a cloud.
// Backup enables a feature to backup KCM objects into a cloud.
type Backup struct {
// +kubebuilder:example={customPlugins: {"alibabacloud": "registry.<region>.aliyuncs.com/acs/velero:1.4.2", "community.openstack.org/openstack": "lirt/velero-plugin-for-openstack:v0.6.0"}}

Expand Down
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func setupWebhooks(mgr ctrl.Manager, currentNamespace string) error {
setupLog.Error(err, "unable to create webhook", "webhook", "Release")
return err
}
if err := (&hmcwebhook.ManagementBackupValidator{}).SetupWebhookWithManager(mgr); err != nil {
if err := (&kcmwebhook.ManagementBackupValidator{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "ManagementBackup")
return err
}
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/backup/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
clusterapiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"

hmcv1alpha1 "github.com/K0rdent/kcm/api/v1alpha1"
kcmv1alpha1 "github.com/K0rdent/kcm/api/v1alpha1"
)

func (c *Config) getBackupTemplateSpec(ctx context.Context) (*velerov1api.BackupSpec, error) {
Expand All @@ -40,13 +40,13 @@ func (c *Config) getBackupTemplateSpec(ctx context.Context) (*velerov1api.Backup

orSelectors := []*metav1.LabelSelector{
// fixed ones
selector(hmcv1alpha1.GenericComponentLabelName, hmcv1alpha1.GenericComponentLabelValueHMC),
selector(kcmv1alpha1.GenericComponentLabelName, kcmv1alpha1.GenericComponentLabelValueKCM),
selector(certmanagerv1.PartOfCertManagerControllerLabelKey, "true"),
selector(hmcv1alpha1.FluxHelmChartNameKey, hmcv1alpha1.CoreHMCName),
selector(kcmv1alpha1.FluxHelmChartNameKey, kcmv1alpha1.CoreKCMName),
selector(clusterapiv1beta1.ProviderNameLabel, "cluster-api"),
}

clusterTemplates := new(hmcv1alpha1.ClusterTemplateList)
clusterTemplates := new(kcmv1alpha1.ClusterTemplateList)
if err := c.cl.List(ctx, clusterTemplates); err != nil {
return nil, fmt.Errorf("failed to list ClusterTemplates: %w", err)
}
Expand Down Expand Up @@ -112,10 +112,10 @@ func sortDedup(selectors []*metav1.LabelSelector) []*metav1.LabelSelector {
}

func getClusterDeploymentsSelectors(ctx context.Context, cl client.Client, clusterTemplateRef string) ([]*metav1.LabelSelector, error) {
cldeploys := new(hmcv1alpha1.ClusterDeploymentList)
cldeploys := new(kcmv1alpha1.ClusterDeploymentList)
opts := []client.ListOption{}
if clusterTemplateRef != "" {
opts = append(opts, client.MatchingFields{hmcv1alpha1.ClusterDeploymentTemplateIndexKey: clusterTemplateRef})
opts = append(opts, client.MatchingFields{kcmv1alpha1.ClusterDeploymentTemplateIndexKey: clusterTemplateRef})
}

if err := cl.List(ctx, cldeploys, opts...); err != nil {
Expand All @@ -124,7 +124,7 @@ func getClusterDeploymentsSelectors(ctx context.Context, cl client.Client, clust

selectors := make([]*metav1.LabelSelector, len(cldeploys.Items)*2)
for i, cldeploy := range cldeploys.Items {
selectors[i] = selector(hmcv1alpha1.FluxHelmChartNameKey, cldeploy.Name)
selectors[i] = selector(kcmv1alpha1.FluxHelmChartNameKey, cldeploy.Name)
selectors[i+1] = selector(clusterapiv1beta1.ClusterNameLabel, cldeploy.Name)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/controller/backup/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
velerov1api "github.com/zerospiel/velero/pkg/apis/velero/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

kcmv1 "github.com/K0rdent/kcm/api/v1alpha1"
kcmv1alpha1 "github.com/K0rdent/kcm/api/v1alpha1"
)

// Typ indicates type of a ManagementBackup object.
Expand All @@ -38,7 +38,7 @@ const (
)

// GetType returns type of the ManagementBackup, returns TypeNone if undefined.
func GetType(instance *hmcv1alpha1.ManagementBackup) Typ {
func GetType(instance *kcmv1alpha1.ManagementBackup) Typ {
if instance.Status.Reference == nil {
return TypeNone
}
Expand All @@ -58,8 +58,8 @@ func GetType(instance *hmcv1alpha1.ManagementBackup) Typ {
var ErrNoManagementExists = errors.New("no Management object exists")

// GetManagement fetches a Management object.
func (c *Config) GetManagement(ctx context.Context) (*hmcv1alpha1.Management, error) {
mgmts := new(hmcv1alpha1.ManagementList)
func (c *Config) GetManagement(ctx context.Context) (*kcmv1alpha1.Management, error) {
mgmts := new(kcmv1alpha1.ManagementList)
if err := c.cl.List(ctx, mgmts, client.Limit(1)); err != nil {
return nil, fmt.Errorf("failed to list Management: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/credential_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (r *CredentialReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return ctrl.Result{}, err
}

if err := utils.AddHMCComponentLabel(ctx, r.Client, clIdty); err != nil {
if err := utils.AddKCMComponentLabel(ctx, r.Client, clIdty); err != nil {
l.Error(err, "adding component label to the ClusterIdentity")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func (r *CredentialReconciler) updateAWSSecretFromClusterStaticIdentity(ctx cont
return fmt.Errorf("failed to get Secret %s referenced in %s %s: %w", key, clStaticIdentity.GetKind(), clStaticIdentity.GetName(), err)
}

if err := utils.AddHMCComponentLabel(ctx, r.Client, secret); err != nil {
if err := utils.AddKCMComponentLabel(ctx, r.Client, secret); err != nil {
return fmt.Errorf("failed to add component label: %w", err)
}

Expand Down
Loading

0 comments on commit 86eb134

Please sign in to comment.