-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
Whoa! Easy there, Partner!This PR is too big. Please break it up into smaller PRs. |
🤖 Generated by lychee actionSummary
Full action output |
Codecov ReportPatch and project coverage have no change.
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. |
controllers/licenseissuer/.env
Outdated
@@ -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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set "" as default.
func loadNotification(receivers []string, event Event, queue []v1.Notification) []v1.Notification { | ||
for _, receiver := range receivers { | ||
queue = append(queue, newNotification(receiver, event)) | ||
} | ||
return queue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to Notification
pool := NewPool(maxBatchSize) | ||
pool.Run(maxChannelSize) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change pool into NotificationManager
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() | ||
}() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to pool.go
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 | ||
} |
There was a problem hiding this comment.
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.
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change set default logic.
// 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() | ||
// } |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete license.
ad24b90
to
a897ef4
Compare
6004d40
to
4c3ad8d
Compare
🤖 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.
Walkthrough
.env
file andMakefile
(link, link)context
andutil
packages to imports ofmain.go
file (link, link)main.go
file (link, link)role.yaml
file (link, link, link)registry
directory and add environment variables toKubefile
(link)Launcher
resource fromcustomconfig.yaml.tmpl
file (link, link)deploy.yaml
file (link)setup.sh
script by applying files together and removing unused CRD wait (link)Reconcile
method, updatePredicate
variable, and add methods toLicenseReconciler
struct inlicense_controller.go
file (link, link, link, link, link, link)collect.go
,const.go
,datasync.go
,external.go
,init.go
,license.go
, andnotice.go
files toutil
package for different sub-tasks of licenseissuer controller (link, link, link, link, link, link, link)collector_controller.go
,launcher_controller.go
,datasync_controller.go
, andnotification_controller.go
(link, link, link, link)