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

feat: List&watch mcs and service, reconcile the work in execution namespace #4323

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

Rains6
Copy link
Contributor

@Rains6 Rains6 commented Nov 25, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:
Referring to #4287

Which issue(s) this PR fixes:
Part of #4292

Special notes for your reviewer:
none

Does this PR introduce a user-facing change?:

`karmada-controller-manager`: Introduced `multiclusterservice` controller to sync MultiClusterService.

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Nov 25, 2023
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 25, 2023
@codecov-commenter
Copy link

codecov-commenter commented Nov 25, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (dd9f54c) 51.99% compared to head (2802916) 51.98%.
Report is 6 commits behind head on master.

Files Patch % Lines
pkg/util/helper/mcs.go 0.00% 6 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4323      +/-   ##
==========================================
- Coverage   51.99%   51.98%   -0.01%     
==========================================
  Files         242      242              
  Lines       23984    23990       +6     
==========================================
+ Hits        12471    12472       +1     
- Misses      10832    10837       +5     
  Partials      681      681              
Flag Coverage Δ
unittests 51.98% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Rains6 Rains6 force-pushed the dev-mcs-zhc branch 5 times, most recently from 0258393 to cd0c339 Compare November 27, 2023 06:43
limitations under the License.
*/

package mcs
Copy link
Member

Choose a reason for hiding this comment

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

To differentiate the current mcs controller, I believe it would be best to move it to a different directory.

Copy link
Member

Choose a reason for hiding this comment

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

cc @RainbowMango for better suggestions.

Options:

  1. mcsnative

Copy link
Member

Choose a reason for hiding this comment

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

It's ok to put the controller in this package. the user-facing controller name is defined at https://github.com/karmada-io/karmada/pull/4323/files#diff-a111978a679a9f03e49c67a43ecb913299d153e59ce48d2d30f5029f27ab601aR227.

Copy link
Member

Choose a reason for hiding this comment

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

I think we should also put it in another folder for easier code analysis and reading.

pkg/controllers/mcs/mcs_controller.go Outdated Show resolved Hide resolved
@jwcesign
Copy link
Member

Review continually

const ControllerName = "mcs-controller"

// MCSControllerFinalizer is added to Cluster to ensure work is deleted before itself is deleted.
const MCSControllerFinalizer = "karmada.io/mcs-controller"
Copy link
Member

Choose a reason for hiding this comment

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

Put this in pkg/util/constants.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

const MCSControllerFinalizer = "karmada.io/mcs-controller"

// CrossClusterEventReason is indicates the reason of CrossCluster event.
const CrossClusterEventReason string = "MCSCrossCluster"
Copy link
Member

Choose a reason for hiding this comment

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

Put this in pkg/events/events.go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

return controllerruntime.Result{}, nil
}

func (c *MCSController) syncSvcWorkToClusters(
Copy link
Member

Choose a reason for hiding this comment

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

How about using name syncSVCWorkToClusters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

limitations under the License.
*/

package mcs
Copy link
Member

Choose a reason for hiding this comment

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

cc @RainbowMango for better suggestions.

Options:

  1. mcsnative

pkg/controllers/mcs/mcs_controller.go Outdated Show resolved Hide resolved
const MCSServiceAppliedConditionType = "ServiceApplied"

// MCSWorkIDLabel is indicates the label of work created by mcs.
const MCSWorkIDLabel = "mcs.karmada.io/mcs-id"
Copy link
Member

Choose a reason for hiding this comment

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

Let's use MultiClusterServicePermanentIDLabel instead of MCSWorkIDLabel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

})
}

func (c *MCSController) getMultiClusterServiceID(mcs *networkingv1alpha1.MultiClusterService) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This ID will be added in mutating webhook: https://github.com/karmada-io/karmada/blob/02b9ff4e11f6bbf67655335fd3c4d1b45f223b25/pkg/webhook/multiclusterservice/mutating.go.

But I am not sure whether we should have this part, Just in case the user forgets to configure the webhook. cc @RainbowMango

}

// MCSContainCrossClusterType checks weather the MultiClusterService contains CrossCluster type.
func MCSContainCrossClusterType(mcs *networkingv1alpha1.MultiClusterService) bool {
Copy link
Member

Choose a reason for hiding this comment

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

Let's put this in file

func MultiClusterServiceCrossClusterEnabled(mcs *networkingv1alpha1.MultiClusterService) bool {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

}

// We only care about the update events below:
if equality.Semantic.DeepEqual(mcsOld.Annotations, mcsNew.Annotations) &&
Copy link
Member

Choose a reason for hiding this comment

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

Why is this judgment necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, there don't need to pay attention to other changes, such as label.

func (c *MCSController) deleteServiceWork(
ctx context.Context,
mcs *networkingv1alpha1.MultiClusterService,
retainClusters sets.Set[string],
Copy link
Member

Choose a reason for hiding this comment

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

retainClusters look useless?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's useful to exclude clusters where we don't want to delete service work.

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/assign

)

// ControllerName is the controller name that will be used when reporting events.
const ControllerName = "mcs-controller"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const ControllerName = "mcs-controller"
const ControllerName = "multiclusterservice-controller"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -89,6 +89,9 @@ const (
// ClusterResourceBindingControllerFinalizer is added to ClusterResourceBinding to ensure related Works are deleted
// before ClusterResourceBinding itself is deleted.
ClusterResourceBindingControllerFinalizer = "karmada.io/cluster-resource-binding-controller"

// MCSControllerFinalizer is added to Cluster to ensure service work is deleted before itself is deleted.
MCSControllerFinalizer = "karmada.io/mcs-controller"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
MCSControllerFinalizer = "karmada.io/mcs-controller"
MCSControllerFinalizer = "karmada.io/multiclusterservice-controller"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

Comment on lines +33 to +34
// MCSServiceAppliedConditionType is indicates the condition type of mcs service applied.
MCSServiceAppliedConditionType = "ServiceApplied"
Copy link
Member

Choose a reason for hiding this comment

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

Please move the events to pkg/events/events.go.

@jwcesign In my opinion, if we report a warning event and we need to report another normal event to cancel the event, right?

Copy link
Member

@jwcesign jwcesign Nov 29, 2023

Choose a reason for hiding this comment

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

I am not sure, but we should report the normal event.

@Rains6 Rains6 force-pushed the dev-mcs-zhc branch 2 times, most recently from 682dcfb to 2802916 Compare November 29, 2023 09:36
Copy link
Member

@jwcesign jwcesign left a comment

Choose a reason for hiding this comment

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

I am ok now, cc @RainbowMango for checking

Copy link
Member

@RainbowMango RainbowMango left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Nov 29, 2023
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 29, 2023
@karmada-bot karmada-bot merged commit 7032767 into karmada-io:master Nov 29, 2023
12 checks passed
@Rains6 Rains6 deleted the dev-mcs-zhc branch November 29, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants