Skip to content

Commit

Permalink
Change fndv2 import name to viewv1beta1
Browse files Browse the repository at this point in the history
To retain consistent naming as we change the module to
point upstream.

Signed-off-by: Shyamsundar Ranganathan <srangana@redhat.com>
  • Loading branch information
ShyamsundarR authored and BenamarMk committed Aug 19, 2021
1 parent d9e709b commit 63764ce
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
28 changes: 14 additions & 14 deletions controllers/drplacementcontrol_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/ghodss/yaml"
"github.com/go-logr/logr"
ocmworkv1 "github.com/open-cluster-management/api/work/v1"
fndv2 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
viewv1beta1 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
plrv1 "github.com/open-cluster-management/multicloud-operators-placementrule/pkg/apis/apps/v1"
errorswrapper "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -188,13 +188,13 @@ func ManagedClusterViewPredicateFunc() predicate.Funcs {
log := ctrl.Log.WithName("MCV")
mcvPredicate := predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
oldMCV, ok := e.ObjectOld.DeepCopyObject().(*fndv2.ManagedClusterView)
oldMCV, ok := e.ObjectOld.DeepCopyObject().(*viewv1beta1.ManagedClusterView)
if !ok {
log.Info("Failed to deep copy older MCV")

return false
}
newMCV, ok := e.ObjectNew.DeepCopyObject().(*fndv2.ManagedClusterView)
newMCV, ok := e.ObjectNew.DeepCopyObject().(*viewv1beta1.ManagedClusterView)
if !ok {
log.Info("Failed to deep copy newer MCV")

Expand All @@ -215,7 +215,7 @@ func ManagedClusterViewPredicateFunc() predicate.Funcs {
return mcvPredicate
}

func filterMCV(mcv *fndv2.ManagedClusterView) []ctrl.Request {
func filterMCV(mcv *viewv1beta1.ManagedClusterView) []ctrl.Request {
return []ctrl.Request{
reconcile.Request{
NamespacedName: types.NamespacedName{
Expand Down Expand Up @@ -260,7 +260,7 @@ func (r *DRPlacementControlReconciler) SetupWithManager(mgr ctrl.Manager) error
mcvPred := ManagedClusterViewPredicateFunc()

mcvMapFun := handler.EnqueueRequestsFromMapFunc(handler.MapFunc(func(obj client.Object) []reconcile.Request {
mcv, ok := obj.(*fndv2.ManagedClusterView)
mcv, ok := obj.(*viewv1beta1.ManagedClusterView)
if !ok {
ctrl.Log.Info("ManagedClusterView map function received non-MCV resource")

Expand All @@ -275,7 +275,7 @@ func (r *DRPlacementControlReconciler) SetupWithManager(mgr ctrl.Manager) error
return ctrl.NewControllerManagedBy(mgr).
For(&rmn.DRPlacementControl{}).
Watches(&source.Kind{Type: &ocmworkv1.ManifestWork{}}, mwMapFun, builder.WithPredicates(mwPred)).
Watches(&source.Kind{Type: &fndv2.ManagedClusterView{}}, mcvMapFun, builder.WithPredicates(mcvPred)).
Watches(&source.Kind{Type: &viewv1beta1.ManagedClusterView{}}, mcvMapFun, builder.WithPredicates(mcvPred)).
Complete(r)
}

Expand Down Expand Up @@ -1244,7 +1244,7 @@ func (r *DRPlacementControlReconciler) getVRGFromManagedCluster(
},
}

mcvViewscope := fndv2.ViewScope{
mcvViewscope := viewv1beta1.ViewScope{
Resource: "VolumeReplicationGroup",
Name: resourceName,
Namespace: resourceNamespace,
Expand Down Expand Up @@ -1608,7 +1608,7 @@ func (d *DRPCInstance) deleteManagedClusterView(clusterName string) error {

d.log.Info("Delete ManagedClusterView from", "namespace", clusterName, "name", mcvName)

mcv := &fndv2.ManagedClusterView{}
mcv := &viewv1beta1.ManagedClusterView{}

err := d.reconciler.Client.Get(d.ctx, types.NamespacedName{Name: mcvName, Namespace: clusterName}, mcv)
if err != nil {
Expand Down Expand Up @@ -1771,7 +1771,7 @@ Requires:
Returns: error if encountered (nil if no error occurred). See results on interface object.
*/
func (r *DRPlacementControlReconciler) getManagedClusterResource(
meta metav1.ObjectMeta, viewscope fndv2.ViewScope, resource interface{}) error {
meta metav1.ObjectMeta, viewscope viewv1beta1.ViewScope, resource interface{}) error {
// create MCV first
mcv, err := r.getOrCreateManagedClusterView(meta, viewscope)
if err != nil {
Expand All @@ -1786,9 +1786,9 @@ func (r *DRPlacementControlReconciler) getManagedClusterResource(
err = fmt.Errorf("missing ManagedClusterView conditions")
case 1:
switch {
case mcv.Status.Conditions[0].Type != fndv2.ConditionViewProcessing:
case mcv.Status.Conditions[0].Type != viewv1beta1.ConditionViewProcessing:
err = fmt.Errorf("found invalid condition (%s) in ManagedClusterView", mcv.Status.Conditions[0].Type)
case mcv.Status.Conditions[0].Reason == fndv2.ReasonGetResourceFailed:
case mcv.Status.Conditions[0].Reason == viewv1beta1.ReasonGetResourceFailed:
err = errors.NewNotFound(schema.GroupResource{}, "requested resource not found in ManagedCluster")
case mcv.Status.Conditions[0].Status != metav1.ConditionTrue:
err = fmt.Errorf("ManagedClusterView is not ready (reason: %s)", mcv.Status.Conditions[0].Reason)
Expand Down Expand Up @@ -1819,10 +1819,10 @@ Requires:
Returns: ManagedClusterView, error
*/
func (r *DRPlacementControlReconciler) getOrCreateManagedClusterView(
meta metav1.ObjectMeta, viewscope fndv2.ViewScope) (*fndv2.ManagedClusterView, error) {
mcv := &fndv2.ManagedClusterView{
meta metav1.ObjectMeta, viewscope viewv1beta1.ViewScope) (*viewv1beta1.ManagedClusterView, error) {
mcv := &viewv1beta1.ManagedClusterView{
ObjectMeta: meta,
Spec: fndv2.ViewSpec{
Spec: viewv1beta1.ViewSpec{
Scope: viewscope,
},
}
Expand Down
27 changes: 15 additions & 12 deletions controllers/drplacementcontrol_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (

spokeClusterV1 "github.com/open-cluster-management/api/cluster/v1"
ocmworkv1 "github.com/open-cluster-management/api/work/v1"
fndv2 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
viewv1beta1 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
plrv1 "github.com/open-cluster-management/multicloud-operators-placementrule/pkg/apis/apps/v1"
dto "github.com/prometheus/client_model/go"
rmn "github.com/ramendr/ramen/api/v1alpha1"
Expand Down Expand Up @@ -143,7 +143,7 @@ func updateManagedClusterViewWithVRG(mcvNamespace string,
}

mcvName := controllers.BuildManagedClusterViewName(DRPCName, DRPCNamespaceName, "vrg")
mcv := &fndv2.ManagedClusterView{}
mcv := &viewv1beta1.ManagedClusterView{}
mcvLookupKey := types.NamespacedName{
Name: mcvName,
Namespace: mcvNamespace,
Expand All @@ -160,22 +160,25 @@ func updateManagedClusterViewWithVRG(mcvNamespace string,
}

// take an existing ManagedClusterView and apply the given resource to it as though it were "found"
func updateManagedClusterView(mcv *fndv2.ManagedClusterView, resource interface{}, status metav1.ConditionStatus) {
func updateManagedClusterView(
mcv *viewv1beta1.ManagedClusterView,
resource interface{},
status metav1.ConditionStatus) {
// get raw bytes
objJSON, err := json.Marshal(resource)

Expect(err).NotTo(HaveOccurred())

// update Status, Result fields
reason := fndv2.ReasonGetResource
reason := viewv1beta1.ReasonGetResource
if status != metav1.ConditionTrue {
reason = fndv2.ReasonGetResourceFailed
reason = viewv1beta1.ReasonGetResourceFailed
}

mcv.Status = fndv2.ViewStatus{
mcv.Status = viewv1beta1.ViewStatus{
Conditions: []metav1.Condition{
{
Type: fndv2.ConditionViewProcessing,
Type: viewv1beta1.ConditionViewProcessing,
LastTransitionTime: metav1.Time{Time: time.Now().Local()},
Status: status,
Reason: reason,
Expand Down Expand Up @@ -210,7 +213,7 @@ func updateManagedClusterView(mcv *fndv2.ManagedClusterView, resource interface{
func updateManagedClusterViewStatusAsNotFound(mcvNamespace string) {
// update Status, Result fields
mcvName := controllers.BuildManagedClusterViewName(DRPCName, DRPCNamespaceName, "vrg")
mcv := &fndv2.ManagedClusterView{}
mcv := &viewv1beta1.ManagedClusterView{}
mcvLookupKey := types.NamespacedName{
Name: mcvName,
Namespace: mcvNamespace,
Expand All @@ -223,13 +226,13 @@ func updateManagedClusterViewStatusAsNotFound(mcvNamespace string) {
}, timeout, interval).Should(BeTrue(),
fmt.Sprintf("failed to wait for mcv creation (%v)", mcv))

status := fndv2.ViewStatus{
status := viewv1beta1.ViewStatus{
Conditions: []metav1.Condition{
{
Type: fndv2.ConditionViewProcessing,
Type: viewv1beta1.ConditionViewProcessing,
LastTransitionTime: metav1.Time{Time: time.Now().Local()},
Status: metav1.ConditionFalse,
Reason: fndv2.ReasonGetResourceFailed,
Reason: viewv1beta1.ReasonGetResourceFailed,
},
},
}
Expand All @@ -246,7 +249,7 @@ func updateManagedClusterViewStatusAsNotFound(mcvNamespace string) {
}

result := err == nil && len(mcv.Status.Conditions) > 0 &&
mcv.Status.Conditions[0].Reason == fndv2.ReasonGetResourceFailed
mcv.Status.Conditions[0].Reason == viewv1beta1.ReasonGetResourceFailed

if !result {
mcv.Status = status
Expand Down
4 changes: 2 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
volrep "github.com/csi-addons/volume-replication-operator/api/v1alpha1"
ocmclv1 "github.com/open-cluster-management/api/cluster/v1"
ocmworkv1 "github.com/open-cluster-management/api/work/v1"
fndv2 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
viewv1beta1 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
subv1 "github.com/open-cluster-management/multicloud-operators-subscription/pkg/apis"
ramendrv1alpha1 "github.com/ramendr/ramen/api/v1alpha1"
ramencontrollers "github.com/ramendr/ramen/controllers"
Expand Down Expand Up @@ -86,7 +86,7 @@ var _ = BeforeSuite(func() {
err = ramendrv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

err = fndv2.AddToScheme(scheme.Scheme)
err = viewv1beta1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

err = volrep.AddToScheme(scheme.Scheme)
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
volrep "github.com/csi-addons/volume-replication-operator/api/v1alpha1"
spokeClusterV1 "github.com/open-cluster-management/api/cluster/v1"
ocmworkv1 "github.com/open-cluster-management/api/work/v1"
fndv2 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
viewv1beta1 "github.com/open-cluster-management/multicloud-operators-foundation/pkg/apis/view/v1beta1"
plrv1 "github.com/open-cluster-management/multicloud-operators-placementrule/pkg/apis/apps/v1"
uberzap "go.uber.org/zap"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -90,7 +90,7 @@ func newManager() (ctrl.Manager, error) {
utilruntime.Must(plrv1.AddToScheme(scheme))
utilruntime.Must(ocmworkv1.AddToScheme(scheme))
utilruntime.Must(spokeClusterV1.AddToScheme(scheme))
utilruntime.Must(fndv2.AddToScheme(scheme))
utilruntime.Must(viewv1beta1.AddToScheme(scheme))
} else {
utilruntime.Must(volrep.AddToScheme(scheme))
}
Expand Down

0 comments on commit 63764ce

Please sign in to comment.