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

fix: Cannot set default values in greptimedb cluster #173

Closed

Conversation

daviderli614
Copy link
Member

@daviderli614 daviderli614 commented Aug 30, 2024

  • Bump kustomize version from v4.5.3 to v5.3.0.
  • Bump controller-gen version from v0.9.0 to v0.14.0.
  • Bump controller-runtime and some kubernetes dependencies mod package to hight version.
  • Fix to set default values in greptimedb cluster, we should SetDefaults() when every reconciler not only if len(cluster.Status.ClusterPhase) == 0:
E0830 15:33:31.869706   23888 controller.go:329]  "msg"="Reconciler error" "error"="Service \"basic-meta\" is invalid:  
 [spec.ports[0].port: Invalid value: 0: must be between 1 and 65535, inclusive, spec.ports[0].targetPort: Invalid value: 0:  
 must be between 1 and 65535, inclusive, spec.ports[1].port: Invalid value: 0: must be between 1 and 65535, inclusive,  
 spec.ports[1].targetPort: Invalid value: 0: must be between 1 and 65535, inclusive, spec.ports[1]: Duplicate value:  
 core.ServicePort{Name:\"\", Protocol:\"TCP\", AppProtocol:(*string)(nil), Port:0, TargetPort:intstr.IntOrString{Type:0,  
 IntVal:0, StrVal:\"\"}, NodePort:0}]" "GreptimeDBCluster"={"name":"basic","namespace":"default"}  
 "controller"="greptimedbcluster" "controllerGroup"="greptime.io" "controllerKind"="GreptimeDBCluster" "name"="basic"  
 "namespace"="default" "reconcileID"="132f23b1-06a6-425e-92b0-660a828d9b0a"  

Summary by CodeRabbit

  • New Features
    • Updated the Custom Resource Definition (CRD) for greptimedbstandalones, adding new properties such as resizePolicy, restartPolicy, and claims for improved resource management.
  • Improvements
    • Enhanced metrics configuration by restructuring how metrics are initialized in the controller manager.
    • Improved type safety by explicitly typing default port variables.
  • Bug Fixes
    • Refined the logic for setting default values in the cluster reconciliation process to prevent potential errors.
  • Dependency Updates
    • Upgraded various Go module dependencies to newer versions for improved performance and compatibility.

Copy link
Contributor

coderabbitai bot commented Aug 30, 2024

Walkthrough

The updates involve version upgrades for tools and dependencies, changes to type annotations for port variables, renaming fields in structs for clarity, and modifications to function signatures to enhance specificity. Additionally, enhancements to the Custom Resource Definition (CRD) structure and minor adjustments to build constraints are included. Overall, these changes aim to improve clarity, maintainability, and compatibility within the codebase.

Changes

File Path Change Summary
Makefile Updated KUSTOMIZE_VERSION to v5.3.0 and CONTROLLER_TOOLS_VERSION to v0.14.0.
apis/v1alpha1/defaulting.go Changed default port variables from untyped to int32. Replaced intstr.FromInt with intstr.FromInt32.
apis/v1alpha1/greptimedbstandalone_types.go Renamed HTTPServicePort to HTTPPort in GreptimeDBStandaloneSpec.
apis/v1alpha1/zz_generated.deepcopy.go Removed the build constraint // +build !ignore_autogenerated.
cmd/operator/app/command.go Replaced MetricsBindAddress with Metrics: metricsserver.Options{ BindAddress: o.MetricsAddr }.
config/crd/resources/greptime.io_greptimedbstandalones.yaml Updated CRD with new fields and annotations, changed controller-gen.kubebuilder.io/version to v0.14.0.
config/rbac/role.yaml Removed creationTimestamp from ClusterRole metadata.
controllers/greptimedbcluster/controller.go Refactored default value initialization in Reconcile function.
controllers/greptimedbcluster/deployers/common.go Changed UpdateStatus parameter type from client.UpdateOption to client.SubResourceUpdateOption.
controllers/greptimedbstandalone/controller.go Changed UpdateStatus parameter type from client.UpdateOption to client.SubResourceUpdateOption.
controllers/greptimedbstandalone/deployer.go Renamed HTTPServicePort to HTTPPort in several methods.
go.mod Updated various Go module dependencies to newer versions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Controller
    participant CRD

    User->>Controller: Create or update resource
    Controller->>CRD: Validate and set defaults
    alt New Resource
        Controller->>CRD: Initialize default values
    end
    Controller->>CRD: Update status
    CRD-->>Controller: Acknowledge update
    Controller-->>User: Confirm resource status
Loading

🐇 "Oh, what a hop, what a skip,
Versions upgraded, let’s take a trip!
Ports now typed, clear as can be,
Renamed fields sing, 'Look at me!'
In the code, we dance and play,
Happy changes brighten the day!" 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 951b022 and eaee9ac.

Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
Files selected for processing (12)
  • Makefile (1 hunks)
  • apis/v1alpha1/defaulting.go (9 hunks)
  • apis/v1alpha1/greptimedbstandalone_types.go (1 hunks)
  • apis/v1alpha1/zz_generated.deepcopy.go (1 hunks)
  • cmd/operator/app/command.go (2 hunks)
  • config/crd/resources/greptime.io_greptimedbstandalones.yaml (51 hunks)
  • config/rbac/role.yaml (1 hunks)
  • controllers/greptimedbcluster/controller.go (1 hunks)
  • controllers/greptimedbcluster/deployers/common.go (1 hunks)
  • controllers/greptimedbstandalone/controller.go (1 hunks)
  • controllers/greptimedbstandalone/deployer.go (3 hunks)
  • go.mod (1 hunks)
Files skipped from review due to trivial changes (4)
  • apis/v1alpha1/greptimedbstandalone_types.go
  • apis/v1alpha1/zz_generated.deepcopy.go
  • config/rbac/role.yaml
  • go.mod
Additional comments not posted (11)
cmd/operator/app/command.go (1)

73-75: Refactor to use structured metrics configuration.

The change from a simple string for MetricsBindAddress to using metricsserver.Options for Metrics enhances configuration flexibility and maintainability. This structured approach allows for future extensions in metrics configuration.

The code changes are approved.

controllers/greptimedbcluster/deployers/common.go (1)

109-109: Refinement in function parameter type for UpdateStatus.

Changing the parameter type from client.UpdateOption to client.SubResourceUpdateOption in the UpdateStatus function makes the update process more specific to sub-resources, which likely enhances the control over how updates are handled.

The code changes are approved.

Makefile (1)

190-191: Update to tool versions in the Makefile.

Updating KUSTOMIZE_VERSION to v5.3.0 and CONTROLLER_TOOLS_VERSION to v0.14.0 ensures that the project uses the latest versions of these tools, which can include important features, bug fixes, or performance improvements.

The version updates are approved.

apis/v1alpha1/defaulting.go (2)

33-37: Type Annotation Changes Approved

The explicit type annotations for port variables (int32) enhance type safety and clarity, aligning with best practices for specifying data types in Go. This change ensures that port-related values are consistently treated across the codebase, reducing the risk of type mismatches.


87-87: Correct Usage of Typed Ports in Function Calls

The replacement of intstr.FromInt with intstr.FromInt32 across various function calls is a necessary adjustment following the type annotation changes. This ensures that the correct type (int32) is passed to functions expecting integer values, which is crucial for maintaining type consistency and avoiding runtime errors.

Also applies to: 93-97, 134-134, 141-144, 178-179, 200-201, 213-213, 251-251, 265-265, 279-279

controllers/greptimedbstandalone/deployer.go (1)

360-360: Field Renaming Consistency Approved

Renaming the field from HTTPServicePort to HTTPPort enhances clarity and uniformity across the codebase. The changes are correctly reflected in the methods that define and utilize the HTTP port, ensuring that the functionality remains intact while improving the readability and maintainability of the code.

Also applies to: 385-385, 406-406

controllers/greptimedbstandalone/controller.go (1)

357-357: Function Signature Update Approved

Changing the parameter type in the UpdateStatus function from client.UpdateOption to client.SubResourceUpdateOption is a targeted refinement that likely enhances the specificity of the update process, focusing on sub-resource updates. This change is appropriate given the context of updating the status of resources, which often involves sub-resource modifications.

controllers/greptimedbcluster/controller.go (1)

141-144: Unconditional default setting enhances robustness.

The change to call SetDefaults() unconditionally is a positive improvement, ensuring that default values are always set regardless of the cluster's phase. This approach enhances the robustness of the reconciliation process and prevents issues related to uninitialized values.

The implementation and error handling are correctly done.

config/crd/resources/greptime.io_greptimedbstandalones.yaml (3)

6-6: Version bump in controller-gen should be verified for compatibility.

The update to controller-gen.kubebuilder.io/version: v0.14.0 is noted. While this is likely to bring enhancements, it's important to verify that this version is compatible with other tools and libraries used in the project.

Please ensure compatibility with the project's dependencies.


433-445: Addition of resizePolicy and restartPolicy enhances resource configurability.

The new fields resizePolicy and restartPolicy allow for detailed specifications of resource resizing and restart behaviors, enhancing the CRD's functionality. The use of x-kubernetes-list-type: atomic for these fields ensures that updates are treated as atomic operations, which is appropriate for these types of configurations.

The implementation of these fields is correctly done and follows Kubernetes best practices.


448-459: Structured handling of resource claims through the claims field.

The addition of the claims field under resources allows for a more structured and manageable approach to resource claims. The use of x-kubernetes-list-type: map with x-kubernetes-list-map-keys: name ensures that updates to the claims are handled correctly, with each claim uniquely identified by its name.

This addition is well-implemented and enhances the CRD's capabilities in managing resources.

@daviderli614 daviderli614 requested a review from zyy17 August 30, 2024 08:46
@zyy17
Copy link
Collaborator

zyy17 commented Sep 7, 2024

@daviderli614 It's not a best practice to fix a bug and upgrade the dependencies simultaneously, which is not about the bug itself.

Can you please make the PR into two standalone PRs:

  1. Describe what the bug is and how to reproduce it. Reverting the code logic is not a good solution. After reviewing the code, I strongly suspect this is not a bug.

  2. Submit another PR to bump the dependencies;

@@ -187,8 +187,8 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.3
CONTROLLER_TOOLS_VERSION ?= v0.9.0
KUSTOMIZE_VERSION ?= v5.3.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't bump the unrelated dependencies at the same time.

defaultMySQLPort = 4002
defaultPostgreSQLPort = 4003
defaultMetaRPCPort = 3002
defaultHTTPPort int32 = 4000
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we don't specify the type, the default type will be int.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's an unrelated modification of the bug.

@@ -32,7 +32,7 @@ type GreptimeDBStandaloneSpec struct {
TLS *TLSSpec `json:"tls,omitempty"`

// +optional
HTTPServicePort int32 `json:"httpPort,omitempty"`
HTTPPort int32 `json:"httpPort,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

The schema is already httpPort, but the variable name is still HTTPServicePort. It's not a bug that affects functionality.

HealthProbeBindAddress: o.HealthProbeAddr,
LeaderElection: o.EnableLeaderElection,
LeaderElectionID: leaderElectionID,
Metrics: metricsserver.Options{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's an unrelated modification of the bug.

// Means the cluster is just created.
if len(cluster.Status.ClusterPhase) == 0 {
klog.Infof("Start to create the cluster '%s/%s'", cluster.Namespace, cluster.Name)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you describe the bug and how to reproduce it in the PR? You can also create an issue. Reverting the original logic without any description is not a good practice.

@daviderli614
Copy link
Member Author

I will split this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants