Skip to content

Commit

Permalink
Initial ramen label changes
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet Shakya <[email protected]>
  • Loading branch information
abhijeet219 committed Jan 8, 2025
1 parent aae07f6 commit 45da485
Show file tree
Hide file tree
Showing 16 changed files with 89 additions and 2 deletions.
6 changes: 6 additions & 0 deletions internal/controller/cephfscg/cghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupDestination(
ObjectMeta: metav1.ObjectMeta{
Name: replicationGroupDestinationName,
Namespace: replicationGroupDestinationNamespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

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

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

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

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

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

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

util.AddLabel(volumeGroupSnapshot, drCConfigCreatedByLabel, "true")
util.AddLabel(volumeGroupSnapshot, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(volumeGroupSnapshot, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(volumeGroupSnapshot, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
Expand Down Expand Up @@ -327,6 +330,7 @@ func (h *volumeGroupSourceHandler) RestoreVolumesFromSnapshot(
return err
}

util.AddLabel(restoredPVC, drCConfigCreatedByLabel, "true")
util.AddLabel(restoredPVC, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(restoredPVC, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(restoredPVC, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
Expand Down Expand Up @@ -413,13 +417,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, drCConfigCreatedByLabel, "true")
util.AddLabel(replicationSource, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(replicationSource, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(replicationSource, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
Expand Down
7 changes: 6 additions & 1 deletion internal/controller/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (

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

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -663,13 +664,17 @@ func (u *drclusterInstance) generateDRClusterConfig() (*ramen.DRClusterConfig, e
return nil, err
}

labels := make(map[string]string)
labels[drCConfigCreatedByLabel] = "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,
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/drclusterconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ func (r *DRClusterConfigReconciler) ensureClusterClaim(
cc := &clusterv1alpha1.ClusterClaim{
ObjectMeta: metav1.ObjectMeta{
Name: claimName(prefix, name),
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

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

clonedPlRule := &plrv1.PlacementRule{}

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

userPlRule.DeepCopyInto(clonedPlRule)

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

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

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

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

if err := w.objectCreate(backupLocation); err != nil {
return backupLocation, nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions internal/controller/util/mcv_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[drCConfigCreatedByLabel] = "true"
meta.Labels = labels

mcv := &viewv1beta1.ManagedClusterView{
ObjectMeta: meta,
Spec: viewv1beta1.ViewSpec{
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/util/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,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[drCConfigCreatedByLabel] = "true"
ns.ObjectMeta.Labels = labels

err := k8sClient.Get(ctx, types.NamespacedName{Name: namespace}, ns)
if err != nil {
if k8serrors.IsNotFound(err) {
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/util/mw_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,8 @@ 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 {
// if labels is empty map, then add the ramen label. If not empty, then append.
labels[drCConfigCreatedByLabel] = "true"
mw := &ocmworkv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down
11 changes: 11 additions & 0 deletions internal/controller/util/secrets_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
SecretPolicyFinalizer string = "drpolicies.ramendr.openshift.io/policy-protection"

VeleroSecretKeyNameDefault = "ramengenerated"

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

// TargetSecretFormat defines the secret format to deliver to the cluster
Expand Down Expand Up @@ -189,6 +191,9 @@ func newPlacementRuleBinding(
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
PlacementRef: gppv1.PlacementSubject{
APIGroup: plrv1.Resource("PlacementRule").Group,
Expand Down Expand Up @@ -217,6 +222,9 @@ func newPlacementRule(name string, namespace string,
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
Spec: plrv1.PlacementRuleSpec{
GenericPlacementFields: plrv1.GenericPlacementFields{
Expand Down Expand Up @@ -360,6 +368,9 @@ func newPolicy(name, namespace, triggerValue string, object runtime.RawExtension
Annotations: map[string]string{
PolicyTriggerAnnotation: triggerValue,
},
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
Spec: gppv1.PolicySpec{
RemediationAction: gppv1.Enforce,
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/volsync/secret_propagator.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ func (sp *secretPropagator) reconcileSecretPropagationPolicy() error {
ObjectMeta: metav1.ObjectMeta{
Name: sp.PolicyName,
Namespace: sp.Owner.GetNamespace(),
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

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

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

Expand Down
1 change: 1 addition & 0 deletions internal/controller/volsync/secretgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func generateNewVolSyncReplicationSecret(secretName, secretNamespace string, log
Namespace: secretNamespace,
Labels: map[string]string{
rmnutil.OCMBackupLabelKey: rmnutil.OCMBackupLabelValue,
drCConfigCreatedByLabel: "true",
},
},
StringData: map[string]string{
Expand Down
19 changes: 19 additions & 0 deletions internal/controller/volsync/vshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const (

// StorageClass label
StorageIDLabel = "ramendr.openshift.io/storageid"

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

type VSHandler struct {
Expand Down Expand Up @@ -207,6 +209,9 @@ func (v *VSHandler) createOrUpdateRD(
ObjectMeta: metav1.ObjectMeta{
Name: getReplicationDestinationName(rdSpec.ProtectedPVC.Name),
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

Expand Down Expand Up @@ -423,6 +428,9 @@ func (v *VSHandler) createOrUpdateRS(rsSpec ramendrv1alpha1.VolSyncReplicationSo
ObjectMeta: metav1.ObjectMeta{
Name: getReplicationSourceName(rsSpec.ProtectedPVC.Name),
Namespace: rsSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

Expand Down Expand Up @@ -992,6 +1000,9 @@ func (v *VSHandler) EnsurePVCforDirectCopy(ctx context.Context,
ObjectMeta: metav1.ObjectMeta{
Name: rdSpec.ProtectedPVC.Name,
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

Expand Down Expand Up @@ -1158,6 +1169,9 @@ func (v *VSHandler) ensurePVCFromSnapshot(rdSpec ramendrv1alpha1.VolSyncReplicat
ObjectMeta: metav1.ObjectMeta{
Name: rdSpec.ProtectedPVC.Name,
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

Expand Down Expand Up @@ -1722,6 +1736,7 @@ func (v *VSHandler) reconcileLocalRD(rdSpec ramendrv1alpha1.VolSyncReplicationDe
}
}

util.AddLabel(lrd, drCConfigCreatedByLabel, "true")
util.AddLabel(lrd, VRGOwnerNameLabel, v.owner.GetName())
util.AddLabel(lrd, VRGOwnerNamespaceLabel, v.owner.GetNamespace())
util.AddLabel(lrd, VolSyncDoNotDeleteLabel, VolSyncDoNotDeleteLabelVal)
Expand Down Expand Up @@ -1795,6 +1810,7 @@ func (v *VSHandler) reconcileLocalRS(rd *volsyncv1alpha1.ReplicationDestination,
}
}

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

Expand Down Expand Up @@ -1940,6 +1956,9 @@ func (v *VSHandler) createPVCFromSnapshot(rd *volsyncv1alpha1.ReplicationDestina
ObjectMeta: metav1.ObjectMeta{
Name: snapshotRef.Name,
Namespace: rd.GetNamespace(),
Labels: map[string]string{
drCConfigCreatedByLabel: "true",
},
},
}

Expand Down
5 changes: 4 additions & 1 deletion internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -1241,11 +1241,14 @@ func (v *VRGInstance) createVR(vrNamespacedName types.NamespacedName, state volr
v.instance.Name, err)
}

labels := rmnutil.OwnerLabels(v.instance)
labels[drCConfigCreatedByLabel] = "true"

volRep := &volrep.VolumeReplication{
ObjectMeta: metav1.ObjectMeta{
Name: vrNamespacedName.Name,
Namespace: vrNamespacedName.Namespace,
Labels: rmnutil.OwnerLabels(v.instance),
Labels: labels,
},
Spec: volrep.VolumeReplicationSpec{
DataSource: corev1.TypedLocalObjectReference{
Expand Down

0 comments on commit 45da485

Please sign in to comment.