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

Added a cloud-based module, responsible for message notifications, license issuance and validation, information collection, and monitoring functions. #3409

Merged
merged 20 commits into from
Jul 4, 2023

Conversation

yxxchange
Copy link
Contributor

@yxxchange yxxchange commented Jun 27, 2023

🤖 Generated by Copilot at 4882579

Summary

🐳📜🛠️

This pull request adds the initial code and configuration for the controllers/cloud project, which is a Kubernetes controller that manages CloudClient and License custom resources. The pull request adds the API types, the CRD manifests, the controller logic, the webhook logic, the Dockerfile, the Makefile, the PROJECT file, and the README file for the project. The pull request also adds the .dockerignore and .gitignore files to exclude unnecessary or sensitive files from the docker and git contexts. The pull request uses kubebuilder, controller-gen, kustomize, and docker buildx tools to scaffold and build the project.

Cloud controllers
Scaffolded with kubebuilder
Autumn of codegen

Walkthrough

  • Add a .dockerignore file to exclude unnecessary or sensitive files from the docker build context (link)
  • Add a .gitignore file to exclude unwanted or temporary files from the git version control system (link)
  • Add a Dockerfile to define the steps to build a docker image for the manager binary, using a multi-stage build process and accepting arguments for cross-platform builds (link)
  • Add a Makefile to define various targets to automate common tasks such as generating code, building binaries, running tests, deploying controllers, and building docker images (link)
  • Add a PROJECT file to track the information used to scaffold the project and allow the plugins to work properly (link)
  • Add a README.md file to provide a brief overview of the project and its purpose, as well as instructions on how to get started, contribute, and license the project (link)
  • Define the API schema for the CloudClient and License custom resources, using structs to represent the spec and status of the resources, and registering the types with the SchemeBuilder (link, link)
  • Define the group and version information for the cloud API group, using variables and functions to specify the GroupVersion, SchemeBuilder, and AddToScheme (link)
  • Generate the deepcopy methods for the types defined in the cloud API group, using the controller-gen tool (link)
  • Add a main function for the manager binary, importing the client auth plugins, the API types, and the controller packages, and setting up the manager with the scheme, the metrics and probe endpoints, the leader election, and the health checks (link)
  • Generate the CustomResourceDefinition manifests for the CloudClient and License resources, using the controller-gen tool (link, link)
  • Add a kustomization.yaml file to apply kustomize transformations to the CRD manifests, listing the base resources, the patches, and the configurations (link)
  • Add a kustomizeconfig.yaml file to configure the kustomize transformations for the CRD manifests, specifying the nameReference, namespace, and varReference fields (link)
  • Add patches for adding cert-manager annotations to the CloudClient and License CRDs, which tell cert-manager to inject the CA certificate from a specified Certificate resource into the CRDs (link, link)
  • Add patches for enabling conversion webhooks for the CloudClient and License CRDs, which tell the API server how to invoke the webhooks for converting between different versions of the resources (link, link)
  • Add a kustomization.yaml file to apply kustomize transformations to the entire project configuration, specifying the namespace, namePrefix, labels, resources, patchesStrategicMerge, and replacements fields (link)

@pull-request-size
Copy link

Whoa! Easy there, Partner!

This PR is too big. Please break it up into smaller PRs.

@sealos-ci-robot
Copy link
Member

sealos-ci-robot commented Jun 27, 2023

🤖 Generated by lychee action

Summary

Status Count
🔍 Total 844
✅ Successful 322
⏳ Timeouts 0
🔀 Redirected 0
👻 Excluded 521
❓ Unknown 0
🚫 Errors 0

Full action output

Full Github Actions output

@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (cf8ba36) 72.97% compared to head (970bcc4) 72.97%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3409   +/-   ##
=======================================
  Coverage   72.97%   72.97%           
=======================================
  Files           8        8           
  Lines         618      618           
=======================================
  Hits          451      451           
  Misses        132      132           
  Partials       35       35           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

)

// CloudClientReconciler reconciles a CloudClient object
type CloudClientReconciler struct {
Copy link
Member

Choose a reason for hiding this comment

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

命名头疼。。。。

// - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.14.4/pkg/reconcile
func (r *CloudClientReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
r.logger.Info("Enter CloudClientReconcile", "namespace:", req.Namespace, "name", req.Name)

Copy link
Member

Choose a reason for hiding this comment

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

注意格式

}

r.logger.Info("Try to get the cloud secret resource...")
resource := util.NewImportanctResource(&clusterSecret, types.NamespacedName{Namespace: cloud.Namespace, Name: cloud.SecretName})
Copy link
Member

Choose a reason for hiding this comment

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

何为 Importenct Resource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some resources related to Licenses contain important information that needs to be stored persistently. If these resources are deleted, it could lead to unforeseen consequences. Therefore, related callback functions are triggered in GetImportanceResource to detect intrusion behavior, and appropriate actions will be taken when such behavior is discovered.

// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// CloudClientSpec defines the desired state of CloudClient
type CloudClientSpec struct {
Copy link
Member

Choose a reason for hiding this comment

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

CR is a resource not a Client

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of the CloudClient Custom Resource (CR) is to serve as the startup resource for the entire module controller. All reconcile functions need to listen to the CloudClient resource to initiate the interaction process with the cloud. The name CloudClient is indeed quite apt...

FALSE = "false"
)

func ReadConfigFile(filepath string, logger logr.Logger) (cloud.Config, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Read config form configmap or ENV is better than config file.

@yxxchange yxxchange force-pushed the main branch 8 times, most recently from 3198f3a to b4bae28 Compare June 30, 2023 10:16
@yxxchange yxxchange force-pushed the main branch 2 times, most recently from 4750d14 to 2ef7cab Compare July 1, 2023 15:45
Comment on lines +58 to +62
r.logger.Info("Enter LauncherReconcile", "namespace:", req.Namespace, "name", req.Name)
if r.Retries > 5 {
return ctrl.Result{}, nil
}
r.Retries++
Copy link
Member

Choose a reason for hiding this comment

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

return ctrl.Result{ Requeue: false}, err

config, err = util.ReadConfigFromConfigMap(string(cloud.ConfigName), &configMap)
if err != nil {
r.logger.Error(err, "failed to read config")
return ctrl.Result{}, err
Copy link
Member

Choose a reason for hiding this comment

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

duplicate code: config, err = util.ReadConfigFromConfigMap(string(cloud.ConfigName), &configMap)

}
}

func NotificationResponseToNotification(resp NotificationResponse) ntf.Notification {
Copy link
Member

Choose a reason for hiding this comment

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

return *ntf.Notification

return err
} else {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

 else {
			return err
		}
return err

@lingdie lingdie added this to the v5.0 milestone Jul 4, 2023
@lingdie lingdie merged commit 2f9eedd into labring:main Jul 4, 2023
62 checks passed
bxy4543 added a commit to bxy4543/sealos that referenced this pull request Oct 25, 2023
…cense issuance and validation, information collection, and monitoring functions. (labring#3409)

* add a notification controller

* fix notification controller bugs, add RWMutex

* Add cloudclient reconcile

* add license controller and cloudsync controller

* add cloudsync controller and fix bugs

* fix go mod

* fix gitignore bugs

* Enhanced the coding standards

* add cloud collector controller, fix some bugs

* add license monitor

* add license monitor

* init encrypt account

* fix bugs

* fix bugs

* fix bugs

* Simplified the code logic and unified the abstract logic under two different scenarios.

* fix bugs

* fix bugs

* fix bugs

* modify the name and fix bugs

---------

Co-authored-by: jiahui <bxy4543@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants