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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
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{
util.CreatedByRamenLabel: "true",
},
},
}

Expand Down Expand Up @@ -201,6 +204,9 @@ func (c *cgHandler) CreateOrUpdateReplicationGroupSource(
ObjectMeta: metav1.ObjectMeta{
Name: replicationGroupSourceName,
Namespace: replicationGroupSourceNamespace,
Labels: map[string]string{
util.CreatedByRamenLabel: "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, util.CreatedByRamenLabel, "true")
util.AddAnnotation(rd, volsync.OwnerNameAnnotation, m.ReplicationGroupDestination.Name)
util.AddAnnotation(rd, volsync.OwnerNamespaceAnnotation, m.ReplicationGroupDestination.Namespace)

Expand Down
4 changes: 4 additions & 0 deletions internal/controller/cephfscg/volumegroupsourcehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (h *volumeGroupSourceHandler) CreateOrUpdateVolumeGroupSnapshot(
return err
}

util.AddLabel(volumeGroupSnapshot, util.CreatedByRamenLabel, "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 +328,7 @@ func (h *volumeGroupSourceHandler) RestoreVolumesFromSnapshot(
return err
}

util.AddLabel(restoredPVC, util.CreatedByRamenLabel, "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 +415,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, util.CreatedByRamenLabel, "true")
util.AddLabel(replicationSource, util.RGSOwnerLabel, owner.GetName())
util.AddAnnotation(replicationSource, volsync.OwnerNameAnnotation, owner.GetName())
util.AddAnnotation(replicationSource, volsync.OwnerNamespaceAnnotation, owner.GetNamespace())
Expand Down
6 changes: 5 additions & 1 deletion internal/controller/drcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,13 +663,17 @@ func (u *drclusterInstance) generateDRClusterConfig() (*ramen.DRClusterConfig, e
return nil, err
}

labels := make(map[string]string)
labels[util.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,
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{
util.CreatedByRamenLabel: "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{
rmnutil.CreatedByRamenLabel: "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[rmnutil.CreatedByRamenLabel] = "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",
rmnutil.CreatedByRamenLabel: "true",
}

owner := metav1.NewControllerRef(placement, clrapiv1beta1.GroupVersion.WithKind("Placement"))
Expand Down
3 changes: 3 additions & 0 deletions internal/controller/kubeobjects/velero/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

"github.com/go-logr/logr"
"github.com/ramendr/ramen/internal/controller/kubeobjects"
"github.com/ramendr/ramen/internal/controller/util"
velero "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
corev1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -454,11 +455,13 @@ func backupRequestCreate(
labels map[string]string,
annotations map[string]string,
) (*velero.BackupStorageLocation, *velero.Backup, error) {
labels[util.CreatedByRamenLabel] = "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[CreatedByRamenLabel] = "true"
meta.Labels = labels

mcv := &viewv1beta1.ManagedClusterView{
ObjectMeta: meta,
Spec: viewv1beta1.ViewSpec{
Expand Down
6 changes: 6 additions & 0 deletions internal/controller/util/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (

// When this annotation is set to true, VolSync will protect RBD PVCs.
UseVolSyncAnnotation = "drplacementcontrol.ramendr.openshift.io/use-volsync-for-pvc-protection"

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

type ResourceUpdater struct {
Expand Down Expand Up @@ -221,6 +223,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) {
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[CreatedByRamenLabel] = "true"
mw := &ocmworkv1.ManifestWork{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/util/secrets_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ func newPlacementRuleBinding(
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
CreatedByRamenLabel: "true",
},
},
PlacementRef: gppv1.PlacementSubject{
APIGroup: plrv1.Resource("PlacementRule").Group,
Expand Down Expand Up @@ -217,6 +220,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{
Expand Down Expand Up @@ -360,6 +366,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,
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{
util.CreatedByRamenLabel: "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{
util.CreatedByRamenLabel: "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{
util.CreatedByRamenLabel: "true",
},
},
}

Expand Down
3 changes: 2 additions & 1 deletion internal/controller/volsync/secretgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func generateNewVolSyncReplicationSecret(secretName, secretNamespace string, log
Name: secretName,
Namespace: secretNamespace,
Labels: map[string]string{
rmnutil.OCMBackupLabelKey: rmnutil.OCMBackupLabelValue,
rmnutil.OCMBackupLabelKey: rmnutil.OCMBackupLabelValue,
rmnutil.CreatedByRamenLabel: "true",
},
},
StringData: map[string]string{
Expand Down
17 changes: 17 additions & 0 deletions internal/controller/volsync/vshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func (v *VSHandler) createOrUpdateRD(
ObjectMeta: metav1.ObjectMeta{
Name: getReplicationDestinationName(rdSpec.ProtectedPVC.Name),
Namespace: rdSpec.ProtectedPVC.Namespace,
Labels: map[string]string{
util.CreatedByRamenLabel: "true",
},
},
}

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

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

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

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

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

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

Expand Down Expand Up @@ -2318,6 +2332,9 @@ func (v *VSHandler) createPVCFromSnapshot(rd *volsyncv1alpha1.ReplicationDestina
ObjectMeta: metav1.ObjectMeta{
Name: snapshotRef.Name,
Namespace: rd.GetNamespace(),
Labels: map[string]string{
util.CreatedByRamenLabel: "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[rmnutil.CreatedByRamenLabel] = "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
Loading