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

Create or update StorageClusterPeer #221

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vbnrh
Copy link
Member

@vbnrh vbnrh commented Jul 12, 2024

  • Updated MirrorPeerReconciler to handle StorageClientType by adding conditions in Reconcile method.
  • Introduced createStorageClusterPeer function for creating StorageClusterPeer objects.
  • Added utility functions fetchClientInfoConfigMap and getClientInfoFromConfigMap for handling client info.
  • Modified processManagedClusterAddon to utilize new config structure.
  • Enhanced DRPolicyReconciler to skip certain operations based on StorageClientType.

Copy link
Contributor

openshift-ci bot commented Jul 12, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vbnrh

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vbnrh
Copy link
Member Author

vbnrh commented Jul 12, 2024

Commits contain changes from #220 and can be ignored

@vbnrh
Copy link
Member Author

vbnrh commented Jul 12, 2024

/test integration-test

@vbnrh vbnrh changed the title Refactor MirrorPeerReconciler, API changes for StorageClient and deps updates API changes for StorageClient Jul 12, 2024
@vbnrh vbnrh force-pushed the mirror-api-changes branch 3 times, most recently from d5eb008 to 66aa1cd Compare July 17, 2024 04:22
@vbnrh vbnrh marked this pull request as draft July 17, 2024 04:23
@vbnrh vbnrh changed the title API changes for StorageClient Create or update StorageClusterPeer Jul 17, 2024
go.sum Outdated
@@ -711,8 +710,8 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/ramendr/ramen/api v0.0.0-20240409201920-10024cae3bfd h1:TsDaQqfb1BcR78JWXBmUyj6Qx4By5loUZ95CxmA/6zo=
github.com/ramendr/ramen/api v0.0.0-20240409201920-10024cae3bfd/go.mod h1:PCb0ODjdi4eYuxY/nSw+/rQqmzkmBVqGNoDr2JXdlKE=
github.com/red-hat-storage/ocs-operator/api/v4 v4.0.0-20240327160100-bbe9d9d49462 h1:84M7EBnmBISt2LcoyYPWsw+A3/7BGXp6Mh3sjUH5vIg=
github.com/red-hat-storage/ocs-operator/api/v4 v4.0.0-20240327160100-bbe9d9d49462/go.mod h1:uySjux/lY0DpC+VXof4ly2SlS7QUocTm2CH4sU8ICeg=
github.com/rewantsoni/ocs-operator/api/v4 v4.0.0-20240701052137-de69df292a5d h1:zXBbu5hpZmW4i3heppui4pqbvubZF/WsBiuP6ZekNKE=
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporarily till this merges red-hat-storage/ocs-operator#2466

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

red-hat-storage/ocs-operator#2677 is merged. We can update this.

go.mod Outdated
@@ -133,6 +133,7 @@ replace (
github.com/openshift/hive => github.com/openshift/hive v1.1.17-0.20220223000051-b1c8fa5853b1
github.com/openshift/hive/apis => github.com/openshift/hive/apis v0.0.0-20220221165319-b389a65758da
github.com/portworx/sched-ops => github.com/portworx/sched-ops v0.20.4-openstorage-rc3
github.com/red-hat-storage/ocs-operator/api/v4 => github.com/rewantsoni/ocs-operator/api/v4 v4.0.0-20240701052137-de69df292a5d
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed as soon as this merges red-hat-storage/ocs-operator#2466

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: red-hat-storage/ocs-operator#2677 is the PR, the older PR was before the design changes

Comment on lines 38 to 41
if peerRefs[0].StorageClusterRef.Namespace == "" && peerRefs[1].StorageClusterRef.Namespace == "" {
return true
}
return false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use Namespace empty as the condition to verify if it is a StorageClient or check for its existence?
We could simplify this to

return peerRefs[0].StorageClusterRef.Namespace == "" && peerRefs[1].StorageClusterRef.Namespace == "" 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a MirrorPeer check to see if its client pairing . Later more changes will made to API to make it more explicit.

Comment on lines 387 to 388
func getClientInfoFromConfigMap(clientInfoMap map[string]string, clientName string) (ClientInfo, error) {
clientInfoJSON, ok := clientInfoMap[clientName]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vbnrh vbnrh marked this pull request as ready for review August 12, 2024 05:24
@vbnrh
Copy link
Member Author

vbnrh commented Aug 13, 2024

/test integration-test

Name string `json:"name"`
Name string `json:"name"`

// +kubebuilder:validation:Optional
Namespace string `json:"namespace"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Namespace string `json:"namespace"`
Namespace string `json:"namespace,omitempty"`

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

r.Logger.Error("Failed to create ODR ObjectBucketClaim", "error", err, "MirrorPeer", mirrorPeer.Name, "namespace", scNamespace)
return err
}
logger := r.Logger.With("MirrorPeer", mirrorPeer.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already set by the main Reconcile() function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -113,6 +113,11 @@ func (r *DRPolicyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, err
}

if utils.IsStorageClientType(mirrorPeer.Spec.Items) {
logger.Info("MirrorPeer contains StorageClient reference. Skipping creation of VolumeReplicationClasses", "MirrorPeer", mirrorPeer.Name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.Info("MirrorPeer contains StorageClient reference. Skipping creation of VolumeReplicationClasses", "MirrorPeer", mirrorPeer.Name)
logger.Info("MirrorPeer contains StorageClient reference. Skipping creation of VolumeReplicationClasses")

Isn't MirrorPeer name already injected in the main reconcile function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is DRPolicy controller, only the req is injected with the logger. MirrorPeer is fetched separately

const (
mirrorPeerFinalizer = "hub.multicluster.odf.openshift.io"
spokeClusterRoleBindingName = "spoke-clusterrole-bindings"
ClientConfigMapKeyTemplate = "%s/%s"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a constant.

Comment on lines 260 to 268
func getKey(clusterName, clientName string) string {
return fmt.Sprintf(ClientConfigMapKeyTemplate, clusterName, clientName)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this? I think Sprintf is good enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer it this way as it is more verbally descriptive. I will remove the clientconfigmapkey and use a format string

// Provider B's onboarding token will be used for Provider A's StorageClusterPeer
onboardingToken, err := fetchOnboardingTicket(ctx, client, oppositeClient, mirrorPeer)
if err != nil {
return ctrl.Result{}, fmt.Errorf("failed to fetch onboarding token for provider %s. err %w", oppositeClient.ProviderInfo.ProviderManagedClusterName, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return ctrl.Result{}, fmt.Errorf("failed to fetch onboarding token for provider %s. err %w", oppositeClient.ProviderInfo.ProviderManagedClusterName, err)
return ctrl.Result{}, fmt.Errorf("failed to fetch onboarding token for provider %s. %w", oppositeClient.ProviderInfo.ProviderManagedClusterName, err)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -33,3 +33,7 @@ func GetPeerRefForSpokeCluster(mp *multiclusterv1alpha1.MirrorPeer, spokeCluster
}
return nil, fmt.Errorf("PeerRef for cluster %s under mirrorpeer %s not found", spokeClusterName, mp.Name)
}

func IsStorageClientType(peerRefs []multiclusterv1alpha1.PeerRef) bool {
return peerRefs[0].StorageClusterRef.Namespace == "" && peerRefs[1].StorageClusterRef.Namespace == ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the right way to check this. IMO we need to cross-reference with our configmap.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

…pe handling

- Updated `MirrorPeerReconciler` to handle `StorageClientType` by adding conditions in `Reconcile` method.
- Introduced `createStorageClusterPeer` function for creating `StorageClusterPeer` objects.
- Added utility functions `fetchClientInfoConfigMap` and `getClientInfoFromConfigMap` for handling client info.
- Modified `processManagedClusterAddon` to utilize new config structure.
- Enhanced `DRPolicyReconciler` to skip certain operations based on `StorageClientType`.

Signed-off-by: vbadrina <[email protected]>
- New utility functions for checking if MirrorPeer is having StorageClient ref
- Functions cross check with the configmap to see if client
- Functions will take a parameter for managedCluster and hub cluster separately to
  pick the configmap properly

Signed-off-by: vbadrina <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants