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

Initial ramen label changes #1741

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions internal/controller/cephfscg/cghandler.go
Original file line number Diff line number Diff line change
@@ -115,6 +115,9 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupDestination(
ObjectMeta: metav1.ObjectMeta{
Name: replicationGroupDestinationName,
Namespace: replicationGroupDestinationNamespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -201,6 +204,9 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
ObjectMeta: metav1.ObjectMeta{
Name: replicationGroupSourceName,
Namespace: replicationGroupSourceNamespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

Original file line number Diff line number Diff line change
@@ -263,6 +263,7 @@ func (m *rgdMachine) CreateReplicationDestinations(
}

util.AddLabel(rd, util.RGDOwnerLabel, m.ReplicationGroupDestination.Name)
util.AddLabel(rd, createdByRamenLabel, "true")
util.AddAnnotation(rd, volsync.OwnerNameAnnotation, m.ReplicationGroupDestination.Name)
util.AddAnnotation(rd, volsync.OwnerNamespaceAnnotation, m.ReplicationGroupDestination.Namespace)

6 changes: 6 additions & 0 deletions internal/controller/cephfscg/volumegroupsourcehandler.go
Original file line number Diff line number Diff line change
@@ -30,6 +30,8 @@ var (
RestorePVCinCGNameFormat = "vs-cg-%s"
SnapshotGroup = "snapshot.storage.k8s.io"
SnapshotGroupKind = "VolumeSnapshot"

createdByRamenLabel = "ramendr.openshift.io/resource-created-by-ramen"
)

type VolumeGroupSourceHandler interface {
@@ -126,6 +128,7 @@ func (h *volumeGroupSourceHandler) CreateOrUpdateVolumeGroupSnapshot(
return err
}

util.AddLabel(volumeGroupSnapshot, createdByRamenLabel, "true")
util.AddLabel(volumeGroupSnapshot, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(volumeGroupSnapshot, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(volumeGroupSnapshot, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
@@ -354,6 +357,7 @@ func (h *volumeGroupSourceHandler) RestoreVolumesFromSnapshot(
return err
}

util.AddLabel(restoredPVC, createdByRamenLabel, "true")
util.AddLabel(restoredPVC, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(restoredPVC, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(restoredPVC, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
@@ -440,13 +444,15 @@ func (h *volumeGroupSourceHandler) CreateOrUpdateReplicationSourceForRestoredPVC
Namespace: replicationSourceNamepspace,
},
}

rdService := getRemoteServiceNameForRDFromPVCName(restoredPVC.SourcePVCName, replicationSourceNamepspace)

op, err := ctrlutil.CreateOrUpdate(ctx, h.Client, replicationSource, func() error {
if err := ctrl.SetControllerReference(owner, replicationSource, h.Client.Scheme()); err != nil {
return err
}

util.AddLabel(replicationSource, createdByRamenLabel, "true")
util.AddLabel(replicationSource, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(replicationSource, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(replicationSource, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
8 changes: 7 additions & 1 deletion internal/controller/drcluster_controller.go
Original file line number Diff line number Diff line change
@@ -75,6 +75,7 @@ const (

const (
DRClusterNameAnnotation = "drcluster.ramendr.openshift.io/drcluster-name"
createdByRamenLabel = "ramendr.openshift.io/resource-created-by-ramen"
)

// SetupWithManager sets up the controller with the Manager.
@@ -652,6 +653,7 @@ func (u *drclusterInstance) ensureDRClusterConfig() error {
return nil
}

//nolint:funlen
func (u *drclusterInstance) generateDRClusterConfig() (*ramen.DRClusterConfig, error) {
mc, err := util.NewManagedClusterInstance(u.ctx, u.client, u.object.GetName())
if err != nil {
@@ -663,13 +665,17 @@ func (u *drclusterInstance) generateDRClusterConfig() (*ramen.DRClusterConfig, e
return nil, err
}

labels := make(map[string]string)
labels[createdByRamenLabel] = "true"

drcConfig := ramen.DRClusterConfig{
TypeMeta: metav1.TypeMeta{
Kind: "DRClusterConfig",
APIVersion: "ramendr.openshift.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: u.object.GetName(),
Name: u.object.GetName(),
Labels: labels,
},
Spec: ramen.DRClusterConfigSpec{
ClusterID: clusterID,
3 changes: 3 additions & 0 deletions internal/controller/drclusterconfig_controller.go
Original file line number Diff line number Diff line change
@@ -304,6 +304,9 @@ func (r *DRClusterConfigReconciler) ensureClusterClaim(
cc := &clusterv1alpha1.ClusterClaim{
ObjectMeta: metav1.ObjectMeta{
Name: claimName(prefix, name),
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

3 changes: 3 additions & 0 deletions internal/controller/drplacementcontrol.go
Original file line number Diff line number Diff line change
@@ -1782,6 +1782,9 @@ func (d *DRPCInstance) newVRG(
ObjectMeta: metav1.ObjectMeta{
Name: d.instance.Name,
Namespace: d.vrgNamespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
Spec: rmn.VolumeReplicationGroupSpec{
PVCSelector: d.instance.Spec.PVCSelector,
5 changes: 5 additions & 0 deletions internal/controller/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
@@ -1097,6 +1097,10 @@ func (r *DRPlacementControlReconciler) clonePlacementRule(ctx context.Context,

clonedPlRule := &plrv1.PlacementRule{}

labels := make(map[string]string)
labels[createdByRamenLabel] = "true"
clonedPlRule.ObjectMeta.Labels = labels

userPlRule.DeepCopyInto(clonedPlRule)

clonedPlRule.Name = clonedPlRuleName
@@ -1701,6 +1705,7 @@ func (r *DRPlacementControlReconciler) createPlacementDecision(ctx context.Conte
plDecision.ObjectMeta.Labels = map[string]string{
clrapiv1beta1.PlacementLabel: placement.GetName(),
rmnutil.ExcludeFromVeleroBackup: "true",
createdByRamenLabel: "true",
}

owner := metav1.NewControllerRef(placement, clrapiv1beta1.GroupVersion.WithKind("Placement"))
4 changes: 4 additions & 0 deletions internal/controller/kubeobjects/velero/requests.go
Original file line number Diff line number Diff line change
@@ -28,6 +28,8 @@ const (
path = "velero/"
protectsPath = path + "backups/"
recoversPath = path + "restores/"

createdByRamenLabel = "ramendr.openshift.io/resource-created-by-ramen"
)

type (
@@ -454,11 +456,13 @@ func backupRequestCreate(
labels map[string]string,
annotations map[string]string,
) (*velero.BackupStorageLocation, *velero.Backup, error) {
labels[createdByRamenLabel] = "true"
backupLocation := backupLocation(requestsNamespaceName, requestName,
s3Url, s3BucketName, s3RegionName, s3KeyPrefix, secretKeyRef,
caCertificates,
labels,
)

if err := w.objectCreate(backupLocation); err != nil {
return backupLocation, nil, err
}
5 changes: 5 additions & 0 deletions internal/controller/util/mcv_util.go
Original file line number Diff line number Diff line change
@@ -386,6 +386,11 @@ func (m ManagedClusterViewGetterImpl) getOrCreateManagedClusterView(
meta metav1.ObjectMeta, viewscope viewv1beta1.ViewScope, logger logr.Logger,
) (*viewv1beta1.ManagedClusterView, error) {
key := types.NamespacedName{Name: meta.Name, Namespace: meta.Namespace}

labels := make(map[string]string)
labels[createdByRamenLabel] = "true"
meta.Labels = labels

mcv := &viewv1beta1.ManagedClusterView{
ObjectMeta: meta,
Spec: viewv1beta1.ViewSpec{
4 changes: 4 additions & 0 deletions internal/controller/util/misc.go
Original file line number Diff line number Diff line change
@@ -227,6 +227,10 @@ func CreateRamenOpsNamespace(ctx context.Context, k8sClient client.Client, ramen
func CreateNamespaceIfNotExists(ctx context.Context, k8sClient client.Client, namespace string) error {
ns := &corev1.Namespace{}

labels := make(map[string]string)
labels[createdByRamenLabel] = "true"
ns.ObjectMeta.Labels = labels

err := k8sClient.Get(ctx, types.NamespacedName{Name: namespace}, ns)
if err != nil {
if k8serrors.IsNotFound(err) {
1 change: 1 addition & 0 deletions internal/controller/util/mw_util.go
Original file line number Diff line number Diff line change
@@ -581,6 +581,7 @@ func (mwu *MWUtil) GenerateManifest(obj interface{}) (*ocmworkv1.Manifest, error
func (mwu *MWUtil) newManifestWork(name string, mcNamespace string,
labels map[string]string, manifests []ocmworkv1.Manifest, annotations map[string]string,
) *ocmworkv1.ManifestWork {
labels[createdByRamenLabel] = "true"
mw := &ocmworkv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: name,
20 changes: 20 additions & 0 deletions internal/controller/util/secrets_util.go
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ const (
SecretPolicyFinalizer string = "drpolicies.ramendr.openshift.io/policy-protection"

VeleroSecretKeyNameDefault = "ramengenerated"

createdByRamenLabel = "ramendr.openshift.io/resource-created-by-ramen"
)

// TargetSecretFormat defines the secret format to deliver to the cluster
@@ -189,6 +191,9 @@ func newPlacementRuleBinding(
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
PlacementRef: gppv1.PlacementSubject{
APIGroup: plrv1.Resource("PlacementRule").Group,
@@ -217,6 +222,9 @@ func newPlacementRule(name string, namespace string,
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
Spec: plrv1.PlacementRuleSpec{
GenericPlacementFields: plrv1.GenericPlacementFields{
@@ -282,6 +290,9 @@ func newS3ConfigurationSecret(s3SecretRef corev1.SecretReference, targetns strin
ObjectMeta: metav1.ObjectMeta{
Name: s3SecretRef.Name,
Namespace: targetns,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
Data: map[string]string{
"AWS_ACCESS_KEY_ID": "{{hub fromSecret " +
@@ -305,6 +316,9 @@ func newVeleroSecret(s3SecretRef corev1.SecretReference, fromNS, veleroNS, keyNa
ObjectMeta: metav1.ObjectMeta{
Name: GenerateVeleroSecretName(s3SecretRef.Name),
Namespace: veleroNS,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
/*
keyName contains, base 64 encoded data as follows:
@@ -334,6 +348,9 @@ func newConfigurationPolicy(name string, object *runtime.RawExtension) *cpcv1.Co
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
Spec: &cpcv1.ConfigurationPolicySpec{
RemediationAction: cpcv1.Enforce,
@@ -360,6 +377,9 @@ func newPolicy(name, namespace, triggerValue string, object runtime.RawExtension
Annotations: map[string]string{
PolicyTriggerAnnotation: triggerValue,
},
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
Spec: gppv1.PolicySpec{
RemediationAction: gppv1.Enforce,
9 changes: 9 additions & 0 deletions internal/controller/volsync/secret_propagator.go
Original file line number Diff line number Diff line change
@@ -164,6 +164,9 @@ func (sp *secretPropagator) reconcileSecretPropagationPolicy() error {
ObjectMeta: metav1.ObjectMeta{
Name: sp.PolicyName,
Namespace: sp.Owner.GetNamespace(),
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -256,6 +259,9 @@ func (sp *secretPropagator) reconcileSecretPropagationPlacementRule() error {
ObjectMeta: metav1.ObjectMeta{
Name: sp.PlacementRuleName,
Namespace: sp.Owner.GetNamespace(),
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -301,6 +307,9 @@ func (sp *secretPropagator) reconcileSecretPropagationPlacementBinding() error {
ObjectMeta: metav1.ObjectMeta{
Name: sp.PlacementBindingName,
Namespace: sp.Owner.GetNamespace(),
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

1 change: 1 addition & 0 deletions internal/controller/volsync/secretgen.go
Original file line number Diff line number Diff line change
@@ -78,6 +78,7 @@ func generateNewVolSyncReplicationSecret(secretName, secretNamespace string, log
Namespace: secretNamespace,
Labels: map[string]string{
rmnutil.OCMBackupLabelKey: rmnutil.OCMBackupLabelValue,
createdByRamenLabel: "true",
},
},
StringData: map[string]string{
20 changes: 20 additions & 0 deletions internal/controller/volsync/vshandler.go
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ const (
PVAnnotationRetentionValue = "retained"

PVCFinalizerProtected = "volumereplicationgroups.ramendr.openshift.io/pvc-volsync-protection"
createdByRamenLabel = "ramendr.openshift.io/resource-created-by-ramen"
)

type VSHandler struct {
@@ -200,6 +201,7 @@ func RDStatusReady(rd *volsyncv1alpha1.ReplicationDestination, log logr.Logger)
return true
}

//nolint:funlen
func (v *VSHandler) createOrUpdateRD(
rdSpec ramendrv1alpha1.VolSyncReplicationDestinationSpec, pskSecretName string,
dstPVC *string) (*volsyncv1alpha1.ReplicationDestination, error,
@@ -220,6 +222,9 @@ func (v *VSHandler) createOrUpdateRD(
ObjectMeta: metav1.ObjectMeta{
Name: getReplicationDestinationName(rdSpec.ProtectedPVC.Name),
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -444,6 +449,9 @@ func (v *VSHandler) createOrUpdateRS(rsSpec ramendrv1alpha1.VolSyncReplicationSo
ObjectMeta: metav1.ObjectMeta{
Name: getReplicationSourceName(rsSpec.ProtectedPVC.Name),
Namespace: rsSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -1405,6 +1413,9 @@ func (v *VSHandler) EnsurePVCforDirectCopy(ctx context.Context,
ObjectMeta: metav1.ObjectMeta{
Name: rdSpec.ProtectedPVC.Name,
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -1571,6 +1582,9 @@ func (v *VSHandler) ensurePVCFromSnapshot(rdSpec ramendrv1alpha1.VolSyncReplicat
ObjectMeta: metav1.ObjectMeta{
Name: rdSpec.ProtectedPVC.Name,
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

@@ -2135,6 +2149,7 @@ func (v *VSHandler) reconcileLocalRD(rdSpec ramendrv1alpha1.VolSyncReplicationDe
}
}

util.AddLabel(lrd, createdByRamenLabel, "true")
util.AddLabel(lrd, VRGOwnerNameLabel, v.owner.GetName())
util.AddLabel(lrd, VRGOwnerNamespaceLabel, v.owner.GetNamespace())
util.AddLabel(lrd, VolSyncDoNotDeleteLabel, VolSyncDoNotDeleteLabelVal)
@@ -2208,6 +2223,7 @@ func (v *VSHandler) reconcileLocalRS(rd *volsyncv1alpha1.ReplicationDestination,
}
}

util.AddLabel(lrs, createdByRamenLabel, "true")
util.AddLabel(lrs, VRGOwnerNameLabel, v.owner.GetName())
util.AddLabel(lrs, VRGOwnerNamespaceLabel, v.owner.GetNamespace())

@@ -2337,6 +2353,7 @@ func (v *VSHandler) setupLocalRS(rd *volsyncv1alpha1.ReplicationDestination,
return v.createPVCFromSnapshot(rd, rdSpec, snapshotRef, restoreSize)
}

//nolint:funlen
func (v *VSHandler) createPVCFromSnapshot(rd *volsyncv1alpha1.ReplicationDestination,
rdSpec *ramendrv1alpha1.VolSyncReplicationDestinationSpec,
snapshotRef *corev1.TypedLocalObjectReference,
@@ -2353,6 +2370,9 @@ func (v *VSHandler) createPVCFromSnapshot(rd *volsyncv1alpha1.ReplicationDestina
ObjectMeta: metav1.ObjectMeta{
Name: snapshotRef.Name,
Namespace: rd.GetNamespace(),
Labels: map[string]string{
createdByRamenLabel: "true",
},
},
}

Loading