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: adapt license for community edition #3644

Merged
merged 16 commits into from
Aug 14, 2023

Conversation

yxxchange
Copy link
Contributor

@yxxchange yxxchange commented Aug 8, 2023

🤖 Generated by Copilot at 53ef12f

Summary

📄🔄🚀

Refactor the licenseissuer controller to use runnable tasks and new APIs for license management, resource collection, data sync, and notification. Simplify and secure the RBAC, deployment, and configuration files. Add environment variables for MongoDB and other options.

Sing, O Muse, of the mighty licenseissuer controller,
That util package filled with many a skillful function,
To sync and collect data, to check and issue licenses,
To communicate with cloud and send forth notifications.

Walkthrough

  • Add environment variables for MongoDB, password salt, and monitor and network options to .env file and Makefile (link, link)
  • Add context and util packages to imports of main.go file (link, link)
  • Remove unused controllers and add runnable tasks for licenseissuer controller in main.go file (link, link)
  • Remove RBAC rules for unused resources from role.yaml file (link, link, link)
  • Comment out unused registry directory and add environment variables to Kubefile (link)
  • Add environment variables and remove unused Launcher resource from customconfig.yaml.tmpl file (link, link)
  • Add environment variables to deploy.yaml file (link)
  • Simplify setup.sh script by applying files together and removing unused CRD wait (link)
  • Update import paths, add fields, rewrite Reconcile method, update Predicate variable, and add methods to LicenseReconciler struct in license_controller.go file (link, link, link, link, link, link)
  • Add collect.go, const.go, datasync.go, external.go, init.go, license.go, and notice.go files to util package for different sub-tasks of licenseissuer controller (link, link, link, link, link, link, link)
  • Delete unused controller files collector_controller.go, launcher_controller.go, datasync_controller.go, and notification_controller.go (link, link, link, 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 Aug 8, 2023

🤖 Generated by lychee action

Summary

Status Count
🔍 Total 885
✅ Successful 348
⏳ Timeouts 0
🔀 Redirected 0
👻 Excluded 536
❓ Unknown 0
🚫 Errors 0

Full action output

Full Github Actions output

@codecov
Copy link

codecov bot commented Aug 8, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (a62daa6) 67.77% compared to head (4c3ad8d) 67.77%.
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3644   +/-   ##
=======================================
  Coverage   67.77%   67.77%           
=======================================
  Files           8        8           
  Lines         661      661           
=======================================
  Hits          448      448           
  Misses        171      171           
  Partials       42       42           

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

@@ -0,0 +1,3 @@
MONITOR= "true"
CAN_CONNECT_TO_EXTERNAL_NETWORK= "true"
MONGO_URI= "mongodb://root:[email protected]:27017/sealos-resources?authSource=admin&directConnection=true"
Copy link
Collaborator

Choose a reason for hiding this comment

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

set "" as default.

Comment on lines 106 to 107
func loadNotification(receivers []string, event Event, queue []v1.Notification) []v1.Notification {
for _, receiver := range receivers {
queue = append(queue, newNotification(receiver, event))
}
return queue
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

change to Notification

Comment on lines 78 to 79
pool := NewPool(maxBatchSize)
pool.Run(maxChannelSize)
Copy link
Collaborator

Choose a reason for hiding this comment

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

change pool into NotificationManager

Comment on lines 137 to 170
type Pool struct {
wg sync.WaitGroup
work chan func()
}

func NewPool(size int) *Pool {
p := &Pool{
work: make(chan func(), size),
}
return p
}

func (p *Pool) Add(f func()) {
p.work <- func() {
f()
}
}

func (p *Pool) Wait() {
close(p.work)
p.wg.Wait()
}

func (p *Pool) Run(size int) {
p.wg.Add(size)
for i := 0; i < size; i++ {
go func() {
for f := range p.work {
f()
}
p.wg.Done()
}()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

to pool.go

Comment on lines 103 to 123
func (rv *Receiver) Cache(obj client.ObjectList) error {
err := rv.Client.List(rv.Context, obj)
if err != nil {
logger.Error(err, "Failed to list namespaces")
return err
}
namespaces, ok := obj.(*corev1.NamespaceList)
if !ok {
logger.Error(err, "Failed to cast to NamespaceList")
return fmt.Errorf("failed to cast to NamespaceList: %w", err)
}
for _, ns := range namespaces.Items {
if filters[string(General)](&ns) {
rv.UserNamespaces = append(rv.UserNamespaces, ns.GetName())
}
if filters[string(Admin)](&ns) {
rv.AdminNamespaces = append(rv.AdminNamespaces, ns.GetName())
}
}
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

change to map to contain namespace.

Comment on lines 87 to 66
func (rv *Receiver) SetReceiver(receiver string, kind ...Kind) *Receiver {
if len(kind) == 0 {
rv.UserNamespaces = append(rv.UserNamespaces, receiver)
return rv
}
switch kind[0] {
case General:
rv.UserNamespaces = append(rv.UserNamespaces, receiver)
case Admin:
rv.AdminNamespaces = append(rv.AdminNamespaces, receiver)
}
return rv
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

change set default logic.

Comment on lines 246 to 277
// The Pool proviveds a pool of goroutines that can be used to perform work.
// type Pool struct {
// work chan func()
// wg sync.WaitGroup
// }

// func NewPool(size int) *Pool {
// return &Pool{
// work: make(chan func(), size),
// }
// }

// func (p *Pool) Run(workerCount int) {
// p.wg.Add(workerCount)
// for i := 0; i < workerCount; i++ {
// go func() {
// for work := range p.work {
// work()
// }
// p.wg.Done()
// }()
// }
// }

// func (p *Pool) Add(work func()) {
// p.work <- work
// }

// func (p *Pool) Wait() {
// close(p.work)
// p.wg.Wait()
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete.

return nil
}

func GetUIDURL(ctx context.Context, client client.Client) (string, map[string]string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

useless.

package util

const (
SealosNamespace = "sealos-system"
Copy link
Collaborator

Choose a reason for hiding this comment

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

use env to set SealosNamespace

const (
SealosNamespace = "sealos-system"
ClusterInfo = "cluster-info"
URLConfig = "url-config"
Copy link
Collaborator

Choose a reason for hiding this comment

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

set to env.

ClusterInfo = "cluster-info"
URLConfig = "url-config"
LicenseHistory = "license-history"
LicenseName = "license"
Copy link
Collaborator

Choose a reason for hiding this comment

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

delete license.

@lingdie lingdie changed the title Community edition feat: adapt license for community edition Aug 9, 2023
@bxy4543 bxy4543 added this to the v5.0 milestone Aug 14, 2023
@bxy4543 bxy4543 merged commit 4efb22a into labring:main Aug 14, 2023
63 checks passed
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