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

operator: fix the issue that the default values of Karmada are not correctly applied #6158

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

zhzhuang-zju
Copy link
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
When the operator reconciles the Karmada CR, it will first validate the Karmada CR and then set the default values. This causes the validation to fail when users omit the configuration of certain fields.

It is necessary to set the default values first and then perform the validation.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
How to reproduce it:

  1. deploy karmada-operator
$ hack/deploy-karmada-operator.sh {path/to/kubeconfig} {context}
  1. deploy a karmada CR
$ kubectl apply -v=4 -f - <<EOF
apiVersion: operator.karmada.io/v1alpha1
kind: Karmada
metadata:
  name: karmada-demo
  namespace: test
spec:
  components:
    karmadaDescheduler: {}
    etcd: {}
EOF
  1. view operator log
E0224 11:56:27.802480       1 controller.go:96] Validation failed for karmada: validation errors: [spec.components.etcd: Invalid value: v1alpha1.Etcd{Local:(*v1alpha1.LocalEtcd)(nil), External:(*v1alpha1.ExternalEtcd)(nil)}: unexpected empty etcd configuration]

Does this PR introduce a user-facing change?:

`karmada-operator`: fix the error of validation failure when some fields of the Karmada CR are not configured. 

@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 24, 2025
@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Feb 24, 2025
operatorscheme.Scheme.Default(karmada)

if updated || !reflect.DeepEqual(karmada.Spec, older.Spec) {
if updated || isSpecUpdated {
Copy link
Member

Choose a reason for hiding this comment

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

Can the update operation also be placed before validateKarmada?

Copy link
Contributor Author

@zhzhuang-zju zhzhuang-zju Feb 24, 2025

Choose a reason for hiding this comment

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

The update operation should only be carried out when the validation is passed
The update operation, you mean controllerutil.AddFinalizer?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if it's appropriate. Can this update be placed before validate?

updated := controllerutil.AddFinalizer(karmada, ControllerFinalizerName)
if _, isExist := karmada.Labels[DisableCascadingDeletionLabel]; !isExist {
labelMap := labels.Merge(karmada.GetLabels(), labels.Set{DisableCascadingDeletionLabel: "false"})
karmada.SetLabels(labelMap)
updated = true
}

Copy link
Contributor Author

@zhzhuang-zju zhzhuang-zju Feb 25, 2025

Choose a reason for hiding this comment

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

I'm not sure if it's appropriate. Can this update be placed before validate?

@XiShanYongYe-Chang updated, does it meet your expectations?

Copy link
Member

Choose a reason for hiding this comment

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

Thanks~
/lgtm

@codecov-commenter
Copy link

codecov-commenter commented Feb 24, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 48.07%. Comparing base (cfebd4d) to head (df7f007).
Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
operator/pkg/controller/karmada/controller.go 0.00% 4 Missing ⚠️

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6158      +/-   ##
==========================================
- Coverage   48.10%   48.07%   -0.03%     
==========================================
  Files         668      668              
  Lines       55316    55327      +11     
==========================================
- Hits        26608    26598      -10     
- Misses      26973    26991      +18     
- Partials     1735     1738       +3     
Flag Coverage Δ
unittests 48.07% <0.00%> (-0.03%) ⬇️

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.

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 25, 2025
@karmada-bot karmada-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Feb 25, 2025
@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 25, 2025
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
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 Feb 26, 2025
@karmada-bot karmada-bot merged commit 00f936b into karmada-io:master Feb 26, 2025
21 checks passed
@RainbowMango RainbowMango added this to the v1.13 milestone Feb 26, 2025
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/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants